Ticket #12282: admin-selectacross.3.diff
File admin-selectacross.3.diff, 10.1 KB (added by , 15 years ago) |
---|
-
django/contrib/admin/helpers.py
diff --git a/django/contrib/admin/helpers.py b/django/contrib/admin/helpers.py index d047d89..29b777f 100644
a b ACTION_CHECKBOX_NAME = '_selected_action' 17 17 18 18 class ActionForm(forms.Form): 19 19 action = forms.ChoiceField(label=_('Action:')) 20 select_across = forms.BooleanField(label='', required=False, initial=0, 21 widget=forms.HiddenInput({'class': 'select-across'})) 20 22 21 23 checkbox = forms.CheckboxInput({'class': 'action-select'}, lambda value: False) 22 24 -
django/contrib/admin/media/css/changelists.css
diff --git a/django/contrib/admin/media/css/changelists.css b/django/contrib/admin/media/css/changelists.css index a9d7543..99ff8bc 100644
a b 228 228 border-right: 1px solid #ddd; 229 229 } 230 230 231 .action_counter{232 font-size: 11px;233 margin: 0 0.5em;234 display: none;235 }236 237 231 #changelist table input { 238 232 margin: 0; 239 233 } … … 250 244 background: white url(../img/admin/nav-bg-reverse.gif) 0 -10px repeat-x; 251 245 } 252 246 247 #changelist .actions.selected { 248 background: #fffccf; 249 border-top: 1px solid #fffee8; 250 border-bottom: 1px solid #edecd6; 251 } 252 253 #changelist .actions span.all, 254 #changelist .actions span.action-counter, 255 #changelist .actions span.clear, 256 #changelist .actions span.question { 257 font-size: 11px; 258 margin: 0 0.5em; 259 display: none; 260 } 261 253 262 #changelist .actions:last-child { 254 263 border-bottom: none; 255 264 } -
django/contrib/admin/media/js/actions.js
diff --git a/django/contrib/admin/media/js/actions.js b/django/contrib/admin/media/js/actions.js index 658f015..c50bdf5 100644
a b 1 1 var Actions = { 2 2 init: function() { 3 3 counterSpans = document.getElementsBySelector('span._acnt'); 4 counterContainer = document.getElementsBySelector('span.action_counter'); 4 counterContainer = document.getElementsBySelector('span.action-counter'); 5 allContainer = document.getElementsBySelector('div.actions span.all'); 6 actionContainer = document.getElementsBySelector('div.actions'); 5 7 actionCheckboxes = document.getElementsBySelector('tr input.action-select'); 8 acrossInputs = document.getElementsBySelector('div.actions input.select-across'); 9 acrossQuestions = document.getElementsBySelector('div.actions span.question'); 10 acrossClears = document.getElementsBySelector('div.actions span.clear'); 11 acrossQuestionLinks = document.getElementsBySelector('div.actions span.question a'); 12 acrossClearsLinks = document.getElementsBySelector('div.actions span.clear a'); 13 14 Actions.setDisplay(counterContainer, 'inline'); 6 15 selectAll = document.getElementById('action-toggle'); 7 lastChecked = null;8 for(var i = 0; i < counterContainer.length; i++) {9 counterContainer[i].style.display = 'inline';10 }11 16 if (selectAll) { 12 selectAll.style.display = 'inline';17 Actions.setDisplay([selectAll], 'inline'); 13 18 addEvent(selectAll, 'click', function() { 14 19 Actions.checker(selectAll.checked); 15 20 Actions.counter(); 16 21 }); 22 for(var i = 0; i < acrossQuestionLinks.length; i++) { 23 addEvent(acrossQuestionLinks[i], 'click', function() { 24 Actions.setAcrossInputs(1); 25 Actions.showClear() 26 return false; 27 }); 28 } 29 for(var i = 0; i < acrossClearsLinks.length; i++) { 30 addEvent(acrossClearsLinks[i], 'click', function() { 31 selectAll.checked = false; 32 Actions.clearAcross(); 33 Actions.checker(0); 34 Actions.counter(); 35 return false; 36 }); 37 } 17 38 } 39 lastChecked = null; 18 40 for(var i = 0; i < actionCheckboxes.length; i++) { 19 41 addEvent(actionCheckboxes[i], 'click', function(e) { 20 42 if (!e) { var e = window.event; } … … var Actions = { 57 79 tr.className = tr.className.replace(' selected', ''); 58 80 } 59 81 }, 60 checked: function() { 61 selectAll.checked = false; 82 setAcrossInputs: function(checked) { 83 for(var i = 0; i < acrossInputs.length; i++) { 84 acrossInputs[i].value = checked; 85 } 62 86 }, 63 87 checker: function(checked) { 88 if (checked) { 89 Actions.showQuestion() 90 } else { 91 Actions.reset(); 92 } 64 93 for(var i = 0; i < actionCheckboxes.length; i++) { 65 94 actionCheckboxes[i].checked = checked; 66 95 Actions.toggleRow(actionCheckboxes[i].parentNode.parentNode, checked); 67 96 } 68 97 }, 98 setDisplay: function(elements, value) { 99 for(var i = 0; i < elements.length; i++) { 100 elements[i].style.display = value; 101 } 102 }, 103 showQuestion: function() { 104 Actions.setDisplay(acrossQuestions, 'inline'); 105 Actions.setDisplay(acrossClears, 'none'); 106 Actions.setDisplay(allContainer, 'none'); 107 }, 108 showClear: function() { 109 Actions.setDisplay(acrossQuestions, 'none'); 110 Actions.setDisplay(acrossClears, 'inline'); 111 Actions.setDisplay(counterContainer, 'none'); 112 Actions.setDisplay(allContainer, 'inline'); 113 for(var i = 0; i < actionContainer.length; i++) { 114 Actions.toggleRow(actionContainer[i], true) 115 } 116 }, 117 reset: function() { 118 Actions.setDisplay(allContainer, 'none') 119 Actions.setDisplay(acrossQuestions, 'none'); 120 Actions.setDisplay(acrossClears, 'none'); 121 Actions.setDisplay(counterContainer, 'inline'); 122 }, 123 clearAcross: function() { 124 Actions.reset() 125 Actions.setAcrossInputs(0); 126 for(var i = 0; i < actionContainer.length; i++) { 127 Actions.toggleRow(actionContainer[i], false) 128 } 129 }, 69 130 counter: function() { 70 131 counter = 0; 71 132 for(var i = 0; i < actionCheckboxes.length; i++) { … … var Actions = { 76 137 for(var i = 0; i < counterSpans.length; i++) { 77 138 counterSpans[i].innerHTML = counter; 78 139 } 79 selectAll.checked = (counter == actionCheckboxes.length); 140 if (counter == actionCheckboxes.length) { 141 selectAll.checked = true; 142 Actions.showQuestion() 143 } else { 144 selectAll.checked = false; 145 Actions.clearAcross() 146 } 80 147 } 81 148 }; 82 149 -
django/contrib/admin/options.py
diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index 6dc707e..f3aa8b7 100644
a b class ModelAdmin(BaseModelAdmin): 719 719 # If the form's valid we can handle the action. 720 720 if action_form.is_valid(): 721 721 action = action_form.cleaned_data['action'] 722 select_across = action_form.cleaned_data['select_across'] 722 723 func, name, description = self.get_actions(request)[action] 723 724 724 725 # Get the list of selected PKs. If nothing's selected, we can't 725 # perform an action on it, so bail. 726 # perform an action on it, so bail. Except we want to perform 727 # the action explicitely on all objects. 726 728 selected = request.POST.getlist(helpers.ACTION_CHECKBOX_NAME) 727 if not selected :729 if not selected and not select_across: 728 730 # Reminder that something needs to be selected or nothing will happen 729 731 msg = _("Items must be selected in order to perform actions on them. No items have been changed.") 730 732 self.message_user(request, msg) 731 733 return None 732 734 733 response = func(self, request, queryset.filter(pk__in=selected)) 735 if not select_across: 736 # Perform the action only on the selected objects 737 queryset = queryset.filter(pk__in=selected) 738 739 response = func(self, request, queryset) 734 740 735 741 # Actions may return an HttpResponse, which will be used as the 736 742 # response from the POST. If not, we'll be a good little HTTP -
django/contrib/admin/templates/admin/actions.html
diff --git a/django/contrib/admin/templates/admin/actions.html b/django/contrib/admin/templates/admin/actions.html index 6d96616..11f5e71 100644
a b 1 1 {% load i18n %} 2 2 <div class="actions"> 3 {% for field in action_form %} <label>{{ field.label }} {{ field }}</label>{% endfor %}3 {% for field in action_form %}{% if field.label %}<label>{{ field.label }} {% endif %}{{ field }}{% if field.label %}</label>{% endif %}{% endfor %} 4 4 <button type="submit" class="button" title="{% trans "Run the selected action" %}" name="index" value="{{ action_index|default:0 }}">{% trans "Go" %}</button> 5 5 {% if actions_selection_counter %} 6 <span class="action_counter"> 7 {% blocktrans with cl.result_count as total_count %}<span class="_acnt">0</span> of {{ total_count }} {{ module_name }} selected{% endblocktrans %} 8 </span> 6 <span class="action-counter"> 7 {% blocktrans with cl.result_count as total_count %} 8 <span class="_acnt">0</span> of {{ total_count }} {{ module_name }} selected 9 {% endblocktrans %} 10 </span> 11 {% if cl.result_count != cl.result_list|length %} 12 <span class="all"> 13 {% blocktrans with cl.result_count as total_count %} 14 All {{ total_count }} {{ module_name }} selected 15 {% endblocktrans %} 16 </span> 17 <span class="question"> 18 <a href="javascript:;" title="{% trans "Click here to select all objects across all pages" %}"> 19 {% blocktrans with cl.result_count as total_count %} 20 Select all {{ total_count }} {{ module_name }} 21 {% endblocktrans %} 22 </a> 23 </span> 24 <span class="clear"><a href="javascript:;">{% trans "Clear selection" %}</a></span> 25 {% endif %} 9 26 {% endif %} 10 27 </div> 28