Ticket #12705: 12705.1.diff

File 12705.1.diff, 5.7 KB (added by jezdez, 6 years ago)

Added a workaround for the DateTimeShortcuts widgets, still a solution for the FilterSelect missing

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

    diff --git a/django/contrib/admin/media/js/admin/DateTimeShortcuts.js b/django/contrib/admin/media/js/admin/DateTimeShortcuts.js
    index 016de90..fbaa599 100644
    a b var DateTimeShortcuts = { 
    1111    calendarLinkName: 'calendarlink',// name of the link that is used to toggle
    1212    clockDivName: 'clockbox',        // name of clock <div> that gets toggled
    1313    clockLinkName: 'clocklink',      // name of the link that is used to toggle
     14    shortCutsClass: 'datetimeshortcuts', // class of the clock and cal shortcuts
    1415    admin_media_prefix: '',
    1516    init: function() {
    1617        // Deduce admin_media_prefix by looking at the <script>s in the
    var DateTimeShortcuts = { 
    4243
    4344        // Shortcut links (clock icon and "Now" link)
    4445        var shortcuts_span = document.createElement('span');
     46        shortcuts_span.className = DateTimeShortcuts.shortCutsClass;
    4547        inp.parentNode.insertBefore(shortcuts_span, inp.nextSibling);
    4648        var now_link = document.createElement('a');
    4749        now_link.setAttribute('href', "javascript:DateTimeShortcuts.handleClockQuicklink(" + num + ", new Date().strftime('" + get_format('TIME_INPUT_FORMATS')[0] + "'));");
    var DateTimeShortcuts = { 
    128130
    129131        // Shortcut links (calendar icon and "Today" link)
    130132        var shortcuts_span = document.createElement('span');
     133        shortcuts_span.className = DateTimeShortcuts.shortCutsClass;
    131134        inp.parentNode.insertBefore(shortcuts_span, inp.nextSibling);
    132135        var today_link = document.createElement('a');
    133136        today_link.setAttribute('href', 'javascript:DateTimeShortcuts.handleCalendarQuickLink(' + num + ', 0);');
  • django/contrib/admin/media/js/inlines.js

    diff --git a/django/contrib/admin/media/js/inlines.js b/django/contrib/admin/media/js/inlines.js
    index 518ad9b..b66d6c9 100644
    a b  
    3434                var maxForms = $("#id_" + options.prefix + "-MAX_NUM_FORMS").attr("autocomplete", "off");
    3535                // only show the add button if we are allowed to add more items
    3636                var showAddButton = ((maxForms.val() == 0) || ((maxForms.val()-totalForms.val()) > 0));
    37                 var selectedItems = this;
    3837                $(this).each(function(i) {
    3938                        $(this).not("." + options.emptyCssClass).addClass(options.formCssClass);
    4039                });
  • django/contrib/admin/templates/admin/edit_inline/stacked.html

    diff --git a/django/contrib/admin/templates/admin/edit_inline/stacked.html b/django/contrib/admin/templates/admin/edit_inline/stacked.html
    index 6525fe1..c713d4a 100644
    a b  
    2222(function($) {
    2323    $(document).ready(function() {
    2424        var rows = "#{{ inline_admin_formset.formset.prefix }}-group .inline-related";
    25         updateInlineLabel = function(row) {
     25        var updateInlineLabel = function(row) {
    2626            $(rows).find(".inline_label").each(function(i) {
    2727                var count = i + 1;
    2828                $(this).html($(this).html().replace(/(#\d+)/g, "#" + count));
    2929            });
    3030        }
     31        var reinitDateTimeShortCuts = function() {
     32            // Reinitialize the calendar and clock widgets by force, yuck.
     33            if (typeof DateTimeShortcuts != "undefined") {
     34                $(".datetimeshortcuts").remove();
     35                DateTimeShortcuts.init();
     36            }
     37        }
    3138        $(rows).formset({
    3239            prefix: "{{ inline_admin_formset.formset.prefix }}",
    3340            addText: "{% blocktrans with inline_admin_formset.opts.verbose_name|title as verbose_name %}Add another {{ verbose_name }}{% endblocktrans %}",
     
    3643            deleteText: "{% trans "Remove" %}",
    3744            emptyCssClass: "empty-form",
    3845            removed: updateInlineLabel,
    39             added: updateInlineLabel
     46            added: (function(row) {
     47                reinitDateTimeShortCuts();
     48                updateInlineLabel(row);
     49            })
    4050        });
    4151    });
    4252})(jQuery.noConflict());
  • django/contrib/admin/templates/admin/edit_inline/tabular.html

    diff --git a/django/contrib/admin/templates/admin/edit_inline/tabular.html b/django/contrib/admin/templates/admin/edit_inline/tabular.html
    index 5c69bad..4b722fd 100644
    a b  
    6868(function($) {
    6969    $(document).ready(function($) {
    7070        var rows = "#{{ inline_admin_formset.formset.prefix }}-group .tabular.inline-related tbody tr";
    71         alternatingRows = function(row) {
     71        var alternatingRows = function(row) {
    7272            $(rows).not(".add-row").removeClass("row1 row2")
    7373                .filter(":even").addClass("row1").end()
    7474                .filter(rows + ":odd").addClass("row2");
    7575        }
     76        var reinitDateTimeShortCuts = function() {
     77            // Reinitialize the calendar and clock widgets by force
     78            if (typeof DateTimeShortcuts != "undefined") {
     79                $(".datetimeshortcuts").remove();
     80                DateTimeShortcuts.init();
     81            }
     82        }
    7683        $(rows).formset({
    7784            prefix: "{{ inline_admin_formset.formset.prefix }}",
    7885            addText: "{% blocktrans with inline_admin_formset.opts.verbose_name|title as verbose_name %}Add another {{ verbose_name }}{% endblocktrans %}",
     
    8188            deleteText: "{% trans "Remove" %}",
    8289            emptyCssClass: "empty-form",
    8390            removed: alternatingRows,
    84             added: alternatingRows
     91            added: (function(row) {
     92                reinitDateTimeShortCuts();
     93                alternatingRows(row);
     94            })
    8595        });
    8696    });
    8797})(jQuery.noConflict());
Back to Top