diff --git a/django/contrib/admin/media/css/changelists.css b/django/contrib/admin/media/css/changelists.css index 43033780ac..a9d7543829 100644 --- a/django/contrib/admin/media/css/changelists.css +++ b/django/contrib/admin/media/css/changelists.css @@ -228,6 +228,12 @@ border-right: 1px solid #ddd; } +.action_counter{ + font-size: 11px; + margin: 0 0.5em; + display: none; +} + #changelist table input { margin: 0; } diff --git a/django/contrib/admin/media/js/actions.js b/django/contrib/admin/media/js/actions.js index d34488ab9d..87b2e1b84e 100644 --- a/django/contrib/admin/media/js/actions.js +++ b/django/contrib/admin/media/js/actions.js @@ -1,10 +1,22 @@ var Actions = { init: function() { - var selectAll = document.getElementById('action-toggle'); + counterSpans = document.getElementsBySelector('span._acnt'); + counterContainer = document.getElementsBySelector('span.action_counter'); + actionCheckboxes = document.getElementsBySelector('tr input.action-select'); + selectAll = document.getElementById('action-toggle'); + for(var i = 0; i < counterContainer.length; i++) { + counterContainer[i].style.display = 'inline'; + } if (selectAll) { selectAll.style.display = 'inline'; addEvent(selectAll, 'click', function() { Actions.checker(selectAll.checked); + Actions.counter(); + }); + } + for(var i = 0; i < actionCheckboxes.length; i++) { + addEvent(actionCheckboxes[i], 'click', function() { + Actions.counter(); }); } var changelistTable = document.getElementsBySelector('#changelist table')[0]; @@ -16,6 +28,7 @@ var Actions = { if (target.className == 'action-select') { var tr = target.parentNode.parentNode; Actions.toggleRow(tr, target.checked); + Actions.checked(); } }); } @@ -27,13 +40,26 @@ var Actions = { tr.className = tr.className.replace(' selected', ''); } }, + checked: function() { + selectAll.checked = false; + }, checker: function(checked) { - var actionCheckboxes = document.getElementsBySelector('tr input.action-select'); for(var i = 0; i < actionCheckboxes.length; i++) { actionCheckboxes[i].checked = checked; Actions.toggleRow(actionCheckboxes[i].parentNode.parentNode, checked); } + }, + counter: function() { + counter = 0; + for(var i = 0; i < actionCheckboxes.length; i++) { + if(actionCheckboxes[i].checked){ + counter++; + } + } + for(var i = 0; i < counterSpans.length; i++) { + counterSpans[i].innerHTML = counter; + } } }; -addEvent(window, 'load', Actions.init); +addEvent(window, 'load', Actions.init); \ No newline at end of file diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index c18af6260a..6dc707eefb 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -210,6 +210,7 @@ class ModelAdmin(BaseModelAdmin): action_form = helpers.ActionForm actions_on_top = True actions_on_bottom = False + actions_selection_counter = True def __init__(self, model, admin_site): self.model = model @@ -1024,7 +1025,13 @@ class ModelAdmin(BaseModelAdmin): else: action_form = None + if cl.result_count == 1: + module_name = force_unicode(opts.verbose_name) + else: + module_name = force_unicode(opts.verbose_name_plural) + context = { + 'module_name': module_name, 'title': cl.title, 'is_popup': cl.is_popup, 'cl': cl, @@ -1035,6 +1042,7 @@ class ModelAdmin(BaseModelAdmin): 'action_form': action_form, 'actions_on_top': self.actions_on_top, 'actions_on_bottom': self.actions_on_bottom, + 'actions_selection_counter': self.actions_selection_counter, } context.update(extra_context or {}) context_instance = template.RequestContext(request, current_app=self.admin_site.name) diff --git a/django/contrib/admin/templates/admin/actions.html b/django/contrib/admin/templates/admin/actions.html index bf4b975dfb..6d96616678 100644 --- a/django/contrib/admin/templates/admin/actions.html +++ b/django/contrib/admin/templates/admin/actions.html @@ -2,4 +2,9 @@