Ticket #26543: #26543.diff

File #26543.diff, 8.8 KB (added by Adonys Alea Boffill, 8 years ago)

Fixed changelist actions don't redirect after failed action

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

    diff --git a/django/contrib/admin/static/admin/js/actions.js b/django/contrib/admin/static/admin/js/actions.js
    index 7041701..2d10d06 100644
    a b  
    113113            list_editable_changed = true;
    114114        });
    115115        $('form#changelist-form button[name="index"]').click(function(event) {
     116            var actionSelected = $('select[name="action"]').val(),
     117                itemSelected = $('table#result_list td.action-checkbox input:checked').length > 0,
     118                messageList = $('ul.messagelist'),  // admin base.html's message list
     119                skipChangeListFormSubmit = function (msg, type, replace) {
     120                    event.preventDefault();  // skip submit
     121                    if (replace) {
     122                        // replace the message list with the new item error
     123                        messageList.html('<li class="' + type + '">' + msg + '</li>');
     124                    }
     125                    else {
     126                        // add new item error to the message list
     127                        $('<li class="' + type + '">' + msg + '</li>').appendTo(messageList);
     128                    }
     129                    return;
     130                };
     131            if (!actionSelected) skipChangeListFormSubmit(
     132                gettext("No action selected."),
     133                'warning',
     134                true
     135            );
     136            if (!itemSelected) skipChangeListFormSubmit(
     137                gettext("Items must be selected in order to perform actions on them. No items have been changed."),
     138                'warning',
     139                // if `actionSelected` is false, the new item error will be appended to the message list,
     140                // keeping the previous item error
     141                actionSelected
     142            );
    116143            if (list_editable_changed) {
    117144                return confirm(gettext("You have unsaved changes on individual editable fields. If you run an action, your unsaved changes will be lost."));
    118145            }
  • django/contrib/admin/static/admin/js/actions.min.js

    diff --git a/django/contrib/admin/static/admin/js/actions.min.js b/django/contrib/admin/static/admin/js/actions.min.js
    index c83b06a..eb61fdf 100644
    a b  
    1 (function(a){var f;a.fn.actions=function(e){var b=a.extend({},a.fn.actions.defaults,e),g=a(this),k=!1,l=function(){a(b.acrossClears).hide();a(b.acrossQuestions).show();a(b.allContainer).hide()},m=function(){a(b.acrossClears).show();a(b.acrossQuestions).hide();a(b.actionContainer).toggleClass(b.selectedClass);a(b.allContainer).show();a(b.counterContainer).hide()},n=function(){a(b.acrossClears).hide();a(b.acrossQuestions).hide();a(b.allContainer).hide();a(b.counterContainer).show()},p=function(){n();
    2 a(b.acrossInput).val(0);a(b.actionContainer).removeClass(b.selectedClass)},q=function(c){c?l():n();a(g).prop("checked",c).parent().parent().toggleClass(b.selectedClass,c)},h=function(){var c=a(g).filter(":checked").length,d=a(".action-counter").data("actionsIcnt");a(b.counterContainer).html(interpolate(ngettext("%(sel)s of %(cnt)s selected","%(sel)s of %(cnt)s selected",c),{sel:c,cnt:d},!0));a(b.allToggle).prop("checked",function(){var a;c===g.length?(a=!0,l()):(a=!1,p());return a})};a(b.counterContainer).show();
    3 a(this).filter(":checked").each(function(c){a(this).parent().parent().toggleClass(b.selectedClass);h();1===a(b.acrossInput).val()&&m()});a(b.allToggle).show().click(function(){q(a(this).prop("checked"));h()});a("a",b.acrossQuestions).click(function(c){c.preventDefault();a(b.acrossInput).val(1);m()});a("a",b.acrossClears).click(function(c){c.preventDefault();a(b.allToggle).prop("checked",!1);p();q(0);h()});f=null;a(g).click(function(c){c||(c=window.event);var d=c.target?c.target:c.srcElement;if(f&&
    4 a.data(f)!==a.data(d)&&!0===c.shiftKey){var e=!1;a(f).prop("checked",d.checked).parent().parent().toggleClass(b.selectedClass,d.checked);a(g).each(function(){if(a.data(this)===a.data(f)||a.data(this)===a.data(d))e=e?!1:!0;e&&a(this).prop("checked",d.checked).parent().parent().toggleClass(b.selectedClass,d.checked)})}a(d).parent().parent().toggleClass(b.selectedClass,d.checked);f=d;h()});a("form#changelist-form table#result_list tr").find("td:gt(0) :input").change(function(){k=!0});a('form#changelist-form button[name="index"]').click(function(a){if(k)return confirm(gettext("You have unsaved changes on individual editable fields. If you run an action, your unsaved changes will be lost."))});
     1(function(a){var e;a.fn.actions=function(g){var b=a.extend({},a.fn.actions.defaults,g),f=a(this),k=!1,m=function(){a(b.acrossClears).hide();a(b.acrossQuestions).show();a(b.allContainer).hide()},n=function(){a(b.acrossClears).show();a(b.acrossQuestions).hide();a(b.actionContainer).toggleClass(b.selectedClass);a(b.allContainer).show();a(b.counterContainer).hide()},p=function(){a(b.acrossClears).hide();a(b.acrossQuestions).hide();a(b.allContainer).hide();a(b.counterContainer).show()},q=function(){p();
     2a(b.acrossInput).val(0);a(b.actionContainer).removeClass(b.selectedClass)},r=function(c){c?m():p();a(f).prop("checked",c).parent().parent().toggleClass(b.selectedClass,c)},h=function(){var c=a(f).filter(":checked").length,d=a(".action-counter").data("actionsIcnt");a(b.counterContainer).html(interpolate(ngettext("%(sel)s of %(cnt)s selected","%(sel)s of %(cnt)s selected",c),{sel:c,cnt:d},!0));a(b.allToggle).prop("checked",function(){var a;c===f.length?(a=!0,m()):(a=!1,q());return a})};a(b.counterContainer).show();
     3a(this).filter(":checked").each(function(c){a(this).parent().parent().toggleClass(b.selectedClass);h();1===a(b.acrossInput).val()&&n()});a(b.allToggle).show().click(function(){r(a(this).prop("checked"));h()});a("a",b.acrossQuestions).click(function(c){c.preventDefault();a(b.acrossInput).val(1);n()});a("a",b.acrossClears).click(function(c){c.preventDefault();a(b.allToggle).prop("checked",!1);q();r(0);h()});e=null;a(f).click(function(c){c||(c=window.event);var d=c.target?c.target:c.srcElement;if(e&&
     4a.data(e)!==a.data(d)&&!0===c.shiftKey){var l=!1;a(e).prop("checked",d.checked).parent().parent().toggleClass(b.selectedClass,d.checked);a(f).each(function(){if(a.data(this)===a.data(e)||a.data(this)===a.data(d))l=l?!1:!0;l&&a(this).prop("checked",d.checked).parent().parent().toggleClass(b.selectedClass,d.checked)})}a(d).parent().parent().toggleClass(b.selectedClass,d.checked);e=d;h()});a("form#changelist-form table#result_list tr").find("td:gt(0) :input").change(function(){k=!0});a('form#changelist-form button[name="index"]').click(function(b){var d=
     5a('select[name="action"]').val(),e=0<a("table#result_list td.action-checkbox input:checked").length,f=a("ul.messagelist"),g=function(d,e,g){b.preventDefault();g?f.html('<li class="'+e+'">'+d+"</li>"):a('<li class="'+e+'">'+d+"</li>").appendTo(f)};d||g(gettext("No action selected."),"warning",!0);e||g(gettext("Items must be selected in order to perform actions on them. No items have been changed."),"warning",d);if(k)return confirm(gettext("You have unsaved changes on individual editable fields. If you run an action, your unsaved changes will be lost."))});
    56a('form#changelist-form input[name="_save"]').click(function(c){var d=!1;a("select option:selected",b.actionContainer).each(function(){a(this).val()&&(d=!0)});if(d)return k?confirm(gettext("You have selected an action, but you haven't saved your changes to individual fields yet. Please click OK to save. You'll need to re-run the action.")):confirm(gettext("You have selected an action, and you haven't made any changes on individual fields. You're probably looking for the Go button rather than the Save button."))})};
    67a.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"};a(document).ready(function(){var e=a("tr input.action-select");0<e.length&&e.actions()})})(django.jQuery);
  • django/contrib/admin/templates/admin/base.html

    diff --git a/django/contrib/admin/templates/admin/base.html b/django/contrib/admin/templates/admin/base.html
    index 70e137c..feff6a9 100644
    a b  
    6060    {% endif %}
    6161
    6262    {% block messages %}
     63        <ul class="messagelist">
    6364        {% if messages %}
    64         <ul class="messagelist">{% for message in messages %}
    65           <li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message|capfirst }}</li>
    66         {% endfor %}</ul>
     65            {% for message in messages %}
     66              <li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message|capfirst }}</li>
     67            {% endfor %}
    6768        {% endif %}
     69        </ul>
    6870    {% endblock messages %}
    6971
    7072    <!-- Content -->
Back to Top