summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorCarlton Gibson <carlton.gibson@noumenal.es>2021-04-15 17:15:28 +0200
committerCarlton Gibson <carlton.gibson@noumenal.es>2021-04-21 08:31:06 +0200
commit5c73fbb6a93ee214678f02ba4027f18dff49337b (patch)
tree9eba97cddf7490fde7068f4245fcbc33eac49265 /django
parent54e94640ace261b14cf8cdb1fae3dc6f068a5f87 (diff)
Fixed #32647 -- Restored multi-row select with shift-modifier in admin changelist.
Regression in 30e59705fc3e3e9e8370b965af794ad6173bf92b.
Diffstat (limited to 'django')
-rw-r--r--django/contrib/admin/static/admin/js/actions.js28
1 files changed, 27 insertions, 1 deletions
diff --git a/django/contrib/admin/static/admin/js/actions.js b/django/contrib/admin/static/admin/js/actions.js
index 239aa5dc39..5aee34ea5e 100644
--- a/django/contrib/admin/static/admin/js/actions.js
+++ b/django/contrib/admin/static/admin/js/actions.js
@@ -88,6 +88,16 @@
window.Actions = function(actionCheckboxes, options) {
options = Object.assign({}, defaults, options);
let list_editable_changed = false;
+ let lastChecked = null;
+ let shiftPressed = false;
+
+ document.addEventListener('keydown', (event) => {
+ shiftPressed = event.shiftKey;
+ });
+
+ document.addEventListener('keyup', (event) => {
+ shiftPressed = event.shiftKey;
+ });
document.getElementById(options.allToggleId).addEventListener('click', function(event) {
checker(actionCheckboxes, options, this.checked);
@@ -113,12 +123,28 @@
});
});
+ function affectedCheckboxes(target, withModifier) {
+ const multiSelect = (lastChecked && withModifier && lastChecked !== target);
+ if (!multiSelect) {
+ return [target];
+ }
+ const checkboxes = Array.from(actionCheckboxes);
+ const targetIndex = checkboxes.findIndex(el => el === target);
+ const lastCheckedIndex = checkboxes.findIndex(el => el === lastChecked);
+ const startIndex = Math.min(targetIndex, lastCheckedIndex);
+ const endIndex = Math.max(targetIndex, lastCheckedIndex);
+ const filtered = checkboxes.filter((el, index) => (startIndex <= index) && (index <= endIndex));
+ return filtered;
+ };
+
Array.from(document.getElementById('result_list').tBodies).forEach(function(el) {
el.addEventListener('change', function(event) {
const target = event.target;
if (target.classList.contains('action-select')) {
- target.closest('tr').classList.toggle(options.selectedClass, target.checked);
+ const checkboxes = affectedCheckboxes(target, shiftPressed);
+ checker(checkboxes, options, target.checked);
updateCounter(actionCheckboxes, options);
+ lastChecked = target;
} else {
list_editable_changed = true;
}