DJANGO Phase 1
This commit is contained in:
@@ -1,29 +1,20 @@
|
||||
'use strict';
|
||||
{
|
||||
// Call function fn when the DOM is loaded and ready. If it is already
|
||||
// loaded, call the function now.
|
||||
// http://youmightnotneedjquery.com/#ready
|
||||
function ready(fn) {
|
||||
if (document.readyState !== 'loading') {
|
||||
fn();
|
||||
} else {
|
||||
document.addEventListener('DOMContentLoaded', fn);
|
||||
}
|
||||
}
|
||||
/** global: django */
|
||||
|
||||
ready(function() {
|
||||
function handleClick(event) {
|
||||
event.preventDefault();
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
if (params.has('_popup')) {
|
||||
window.close(); // Close the popup.
|
||||
} else {
|
||||
window.history.back(); // Otherwise, go back.
|
||||
}
|
||||
}
|
||||
|
||||
document.querySelectorAll('.cancel-link').forEach(function(el) {
|
||||
el.addEventListener('click', handleClick);
|
||||
if (typeof(django) !== 'undefined' && typeof(django.jQuery) !== 'undefined') {
|
||||
(function($) {
|
||||
'use strict';
|
||||
$(document).ready(function() {
|
||||
$('.cancel-link').click(function(e) {
|
||||
e.preventDefault();
|
||||
var parentWindow = window.parent;
|
||||
if (parentWindow && typeof(parentWindow.dismissRelatedObjectModal) === 'function' && parentWindow !== window) {
|
||||
parentWindow.dismissRelatedObjectModal();
|
||||
} else {
|
||||
// fallback to default behavior
|
||||
window.history.back();
|
||||
}
|
||||
return false;
|
||||
});
|
||||
});
|
||||
});
|
||||
})(django.jQuery);
|
||||
}
|
||||
|
||||
49
backend/staticfiles/admin/js/collapse.js
Normal file
49
backend/staticfiles/admin/js/collapse.js
Normal file
@@ -0,0 +1,49 @@
|
||||
/*global gettext*/
|
||||
/* copied from django 4.0.7 */
|
||||
'use strict';
|
||||
{
|
||||
window.addEventListener('load', function() {
|
||||
// Add anchor tag for Show/Hide link
|
||||
const fieldsets = document.querySelectorAll('fieldset.collapse');
|
||||
for (const [i, elem] of fieldsets.entries()) {
|
||||
// Don't hide if fields in this fieldset have errors
|
||||
if (elem.querySelectorAll('div.errors, ul.errorlist').length === 0) {
|
||||
const h2 = elem.querySelector('h2');
|
||||
const link = document.createElement('a');
|
||||
link.id = 'fieldsetcollapser' + i;
|
||||
link.className = 'collapse-toggle';
|
||||
link.href = '#';
|
||||
// changed: can opt into starting visible
|
||||
if (elem.classList.contains('expanded')) {
|
||||
link.textContent = gettext('Hide');
|
||||
} else {
|
||||
link.textContent = gettext('Show');
|
||||
elem.classList.add('collapsed');
|
||||
}
|
||||
h2.appendChild(document.createTextNode(' ('));
|
||||
h2.appendChild(link);
|
||||
h2.appendChild(document.createTextNode(')'));
|
||||
}
|
||||
}
|
||||
// Add toggle to hide/show anchor tag
|
||||
const toggleFunc = function(ev) {
|
||||
if (ev.target.matches('.collapse-toggle')) {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
const fieldset = ev.target.closest('fieldset');
|
||||
if (fieldset.classList.contains('collapsed')) {
|
||||
// Show
|
||||
ev.target.textContent = gettext('Hide');
|
||||
fieldset.classList.remove('collapsed');
|
||||
} else {
|
||||
// Hide
|
||||
ev.target.textContent = gettext('Show');
|
||||
fieldset.classList.add('collapsed');
|
||||
}
|
||||
}
|
||||
};
|
||||
document.querySelectorAll('fieldset.module').forEach(function(el) {
|
||||
el.addEventListener('click', toggleFunc);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -1,15 +1,48 @@
|
||||
'use strict';
|
||||
{
|
||||
const initData = JSON.parse(document.getElementById('django-admin-popup-response-constants').dataset.popupResponse);
|
||||
switch(initData.action) {
|
||||
case 'change':
|
||||
opener.dismissChangeRelatedObjectPopup(window, initData.value, initData.obj, initData.new_value);
|
||||
break;
|
||||
case 'delete':
|
||||
opener.dismissDeleteRelatedObjectPopup(window, initData.value);
|
||||
break;
|
||||
default:
|
||||
opener.dismissAddRelatedObjectPopup(window, initData.value, initData.obj);
|
||||
break;
|
||||
(function() {
|
||||
|
||||
'use strict';
|
||||
|
||||
var windowRef = window;
|
||||
var windowRefProxy;
|
||||
var windowName, widgetName;
|
||||
var openerRef = windowRef.opener;
|
||||
if (!openerRef) {
|
||||
// related modal is active
|
||||
openerRef = windowRef.parent;
|
||||
windowName = windowRef.name;
|
||||
widgetName = windowName.replace(/^(change|add|delete|lookup)_/, '');
|
||||
if (typeof(openerRef.id_to_windowname) === 'function') {
|
||||
// django < 3.1 compatibility
|
||||
widgetName = openerRef.id_to_windowname(widgetName);
|
||||
}
|
||||
windowRefProxy = {
|
||||
name: widgetName,
|
||||
location: windowRef.location,
|
||||
close: function() {
|
||||
openerRef.dismissRelatedObjectModal();
|
||||
}
|
||||
};
|
||||
windowRef = windowRefProxy;
|
||||
}
|
||||
}
|
||||
|
||||
// default django popup_response.js
|
||||
var initData = JSON.parse(document.getElementById('django-admin-popup-response-constants').dataset.popupResponse);
|
||||
switch (initData.action) {
|
||||
case 'change':
|
||||
if (typeof(openerRef.dismissChangeRelatedObjectPopup) === 'function') {
|
||||
openerRef.dismissChangeRelatedObjectPopup(windowRef, initData.value, initData.obj, initData.new_value);
|
||||
}
|
||||
break;
|
||||
case 'delete':
|
||||
if (typeof(openerRef.dismissDeleteRelatedObjectPopup) === 'function') {
|
||||
openerRef.dismissDeleteRelatedObjectPopup(windowRef, initData.value);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (typeof(openerRef.dismissAddRelatedObjectPopup) === 'function') {
|
||||
openerRef.dismissAddRelatedObjectPopup(windowRef, initData.value, initData.obj);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user