Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Fixed #12282 - When paginated allow selecting all items in the admin …
…changlist. Thanks to Martin Mahner, Rob Hudson and Zain Memon for providing inital patches and guidance. git-svn-id: http://code.djangoproject.com/svn/django/trunk@12298 bcc190cf-cafb-0310-a4f2-bffc1f526a37
- Loading branch information
Showing
7 changed files
with
163 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,83 +1,111 @@ | |||
var Actions = { | (function($) { | ||
init: function() { | $.fn.actions = function(opts) { | ||
counterSpans = document.getElementsBySelector('span._acnt'); | var options = $.extend({}, $.fn.actions.defaults, opts); | ||
counterContainer = document.getElementsBySelector('span.action_counter'); | var actionCheckboxes = $(this); | ||
actionCheckboxes = document.getElementsBySelector('tr input.action-select'); | checker = function(checked) { | ||
selectAll = document.getElementById('action-toggle'); | if (checked) { | ||
lastChecked = null; | showQuestion(); | ||
for(var i = 0; i < counterContainer.length; i++) { | } else { | ||
counterContainer[i].style.display = 'inline'; | reset(); | ||
} | } | ||
if (selectAll) { | $(actionCheckboxes).attr("checked", checked) | ||
selectAll.style.display = 'inline'; | .parent().parent().toggleClass(options.selectedClass, checked); | ||
addEvent(selectAll, 'click', function() { | } | ||
Actions.checker(selectAll.checked); | updateCounter = function() { | ||
Actions.counter(); | var count = $(actionCheckboxes).filter(":checked").length; | ||
}); | $("span._acnt").html(count); | ||
} | $(options.allToggle).attr("checked", function() { | ||
for(var i = 0; i < actionCheckboxes.length; i++) { | if (count == actionCheckboxes.length) { | ||
addEvent(actionCheckboxes[i], 'click', function(e) { | value = true; | ||
if (!e) { var e = window.event; } | showQuestion(); | ||
var target = e.target ? e.target : e.srcElement; | } else { | ||
if (lastChecked && lastChecked != target && e.shiftKey == true) { | value = false; | ||
var inrange = false; | clearAcross(); | ||
lastChecked.checked = target.checked; | } | ||
Actions.toggleRow(lastChecked.parentNode.parentNode, target.checked); | return value | ||
for (var i = 0; i < actionCheckboxes.length; i++) { | }); | ||
if (actionCheckboxes[i] == lastChecked || actionCheckboxes[i] == target) { | } | ||
inrange = (inrange) ? false : true; | showQuestion = function() { | ||
} | $(options.acrossClears).hide(); | ||
if (inrange) { | $(options.acrossQuestions).show(); | ||
actionCheckboxes[i].checked = target.checked; | $(options.allContainer).hide(); | ||
Actions.toggleRow(actionCheckboxes[i].parentNode.parentNode, target.checked); | } | ||
} | showClear = function() { | ||
} | $(options.acrossClears).show(); | ||
} | $(options.acrossQuestions).hide(); | ||
lastChecked = target; | $(options.actionContainer).toggleClass(options.selectedClass); | ||
Actions.counter(); | $(options.allContainer).show(); | ||
}); | $(options.counterContainer).hide(); | ||
} | } | ||
var changelistTable = document.getElementsBySelector('#changelist table')[0]; | reset = function() { | ||
if (changelistTable) { | $(options.acrossClears).hide(); | ||
addEvent(changelistTable, 'click', function(e) { | $(options.acrossQuestions).hide(); | ||
if (!e) { var e = window.event; } | $(options.allContainer).hide(); | ||
var target = e.target ? e.target : e.srcElement; | $(options.counterContainer).show(); | ||
if (target.nodeType == 3) { target = target.parentNode; } | } | ||
if (target.className == 'action-select') { | clearAcross = function() { | ||
var tr = target.parentNode.parentNode; | reset(); | ||
Actions.toggleRow(tr, target.checked); | $(options.acrossInput).val(0); | ||
} | $(options.actionContainer).removeClass(options.selectedClass); | ||
}); | } | ||
} | // Show counter by default | ||
}, | $(options.counterContainer).show(); | ||
toggleRow: function(tr, checked) { | // Check state of checkboxes and reinit state if needed | ||
if (checked && tr.className.indexOf('selected') == -1) { | $(this).filter(":checked").each(function(i) { | ||
tr.className += ' selected'; | $(this).parent().parent().toggleClass(options.selectedClass); | ||
} else if (!checked) { | updateCounter(); | ||
tr.className = tr.className.replace(' selected', ''); | if ($(options.acrossInput).val() == 1) { | ||
} | showClear(); | ||
}, | } | ||
checked: function() { | }); | ||
selectAll.checked = false; | $(options.allToggle).show().click(function() { | ||
}, | checker($(this).attr("checked")); | ||
checker: function(checked) { | updateCounter(); | ||
for(var i = 0; i < actionCheckboxes.length; i++) { | }); | ||
actionCheckboxes[i].checked = checked; | $("div.actions span.question a").click(function(event) { | ||
Actions.toggleRow(actionCheckboxes[i].parentNode.parentNode, checked); | event.preventDefault(); | ||
} | $(options.acrossInput).val(1); | ||
}, | showClear(); | ||
counter: function() { | }); | ||
counter = 0; | $("div.actions span.clear a").click(function(event) { | ||
for(var i = 0; i < actionCheckboxes.length; i++) { | event.preventDefault(); | ||
if(actionCheckboxes[i].checked){ | $(options.allToggle).attr("checked", false); | ||
counter++; | clearAcross(); | ||
} | checker(0); | ||
} | updateCounter(); | ||
for(var i = 0; i < counterSpans.length; i++) { | }); | ||
counterSpans[i].innerHTML = counter; | lastChecked = null; | ||
} | $(actionCheckboxes).click(function(event) { | ||
selectAll.checked = (counter == actionCheckboxes.length); | if (!event) { var event = window.event; } | ||
} | var target = event.target ? event.target : event.srcElement; | ||
}; | if (lastChecked && $.data(lastChecked) != $.data(target) && event.shiftKey == true) { | ||
|
var inrange = false; | ||
addEvent(window, 'load', Actions.init); | $(lastChecked).attr("checked", target.checked) | ||
.parent().parent().toggleClass(options.selectedClass, target.checked); | |||
$(actionCheckboxes).each(function() { | |||
if ($.data(this) == $.data(lastChecked) || $.data(this) == $.data(target)) { | |||
inrange = (inrange) ? false : true; | |||
} | |||
if (inrange) { | |||
$(this).attr("checked", target.checked) | |||
.parent().parent().toggleClass(options.selectedClass, target.checked); | |||
} | |||
}); | |||
} | |||
$(target).parent().parent().toggleClass(options.selectedClass, target.checked); | |||
lastChecked = target; | |||
updateCounter(); | |||
}); | |||
} | |||
/* Setup plugin defaults */ | |||
$.fn.actions.defaults = { | |||
actionContainer: "div.actions", | |||
counterContainer: "span.action-counter", | |||
allContainer: "div.actions span.all", | |||
acrossInput: "div.actions input.select-across", | |||
acrossQuestions: "div.actions span.question", | |||
acrossClears: "div.actions span.clear", | |||
allToggle: "#action-toggle", | |||
selectedClass: "selected" | |||
} | |||
})(jQuery); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,10 +1,20 @@ | |||
{% load i18n %} | {% load i18n %} | ||
<div class="actions"> | <div class="actions"> | ||
{% for field in action_form %}<label>{{ field.label }} {{ field }}</label>{% endfor %} | {% for field in action_form %}{% if field.label %}<label>{{ field.label }} {% endif %}{{ field }}{% if field.label %}</label>{% endif %}{% endfor %} | ||
<button type="submit" class="button" title="{% trans "Run the selected action" %}" name="index" value="{{ action_index|default:0 }}">{% trans "Go" %}</button> | <button type="submit" class="button" title="{% trans "Run the selected action" %}" name="index" value="{{ action_index|default:0 }}">{% trans "Go" %}</button> | ||
{% if actions_selection_counter %} | {% if actions_selection_counter %} | ||
<span class="action_counter"> | <span class="action-counter"> | ||
{% blocktrans with cl.result_count as total_count %}<span class="_acnt">0</span> of {{ total_count }} {{ module_name }} selected{% endblocktrans %} | {% blocktrans with cl.result_count as total_count %}<span class="_acnt">0</span> of {{ total_count }} {{ module_name }} selected{% endblocktrans %} | ||
</span> | </span> | ||
{% if cl.result_count != cl.result_list|length %} | |||
<span class="all"> | |||
{% blocktrans with cl.result_count as total_count %}All {{ total_count }} {{ module_name }} selected{% endblocktrans %} | |||
</span> | |||
<span class="question"> | |||
<a href="javascript:;" title="{% trans "Click here to select all objects across all pages" %}">{% blocktrans with cl.result_count as total_count %}Select all {{ total_count }} {{ module_name }}{% endblocktrans %}</a> | |||
</span> | |||
<span class="clear"><a href="javascript:;">{% trans "Clear selection" %}</a></span> | |||
{% endif %} | |||
{% endif %} | {% endif %} | ||
</div> | </div> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters