Ticket #11697: shift-check-multi-3.diff

File shift-check-multi-3.diff, 2.4 KB (added by Sean Brant, 14 years ago)

this patch will automatically select/deselect the check all if you select all with shift-click

  • django/contrib/admin/media/js/actions.js

     
    44        counterContainer = document.getElementsBySelector('span.action_counter');
    55        actionCheckboxes = document.getElementsBySelector('tr input.action-select');
    66        selectAll = document.getElementById('action-toggle');
     7        lastChecked = null;
    78        for(var i = 0; i < counterContainer.length; i++) {
    89            counterContainer[i].style.display = 'inline';
    910        }
     
    1516            });
    1617        }
    1718        for(var i = 0; i < actionCheckboxes.length; i++) {
    18             addEvent(actionCheckboxes[i], 'click', function() {
     19            addEvent(actionCheckboxes[i], 'click', function(e) {
     20                if (!e) { var e = window.event; }
     21                var target = e.target ? e.target : e.srcElement;
     22                if (lastChecked && lastChecked != target && e.shiftKey == true) {
     23                    var inrange = false;
     24                    lastChecked.checked = target.checked;
     25                    Actions.toggleRow(lastChecked.parentNode.parentNode, target.checked);
     26                    for (var i = 0; i < actionCheckboxes.length; i++) {
     27                        if (actionCheckboxes[i] == lastChecked || actionCheckboxes[i] == target) {
     28                            inrange = (inrange) ? false : true;
     29                        }
     30                        if (inrange) {
     31                            actionCheckboxes[i].checked = target.checked;
     32                            Actions.toggleRow(actionCheckboxes[i].parentNode.parentNode, target.checked);
     33                        }
     34                    }
     35                }
     36                lastChecked = target;
    1937                Actions.counter();
    2038            });
    2139        }
     
    2846                if (target.className == 'action-select') {
    2947                    var tr = target.parentNode.parentNode;
    3048                    Actions.toggleRow(tr, target.checked);
    31                     Actions.checked();
    3249                }
    3350            });
    3451        }
     
    5976        for(var i = 0; i < counterSpans.length; i++) {
    6077            counterSpans[i].innerHTML = counter;
    6178        }
     79        selectAll.checked = (counter == actionCheckboxes.length);
    6280    }
    6381};
    6482
Back to Top