Ticket #12705: 12705.2.diff

File 12705.2.diff, 9.0 KB (added by jbronn, 15 years ago)

Now works with SelectFIlter

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

    diff -r 3e100985dbfa django/contrib/admin/media/js/SelectFilter2.js
    a b  
    1616
    1717var SelectFilter = {
    1818    init: function(field_id, field_name, is_stacked, admin_media_prefix) {
     19        if (field_id.match(/__prefix__/)){
     20            // Don't intialize on empty forms.
     21            return;
     22        }
    1923        var from_box = document.getElementById(field_id);
    2024        from_box.id += '_from'; // change its ID
    2125        from_box.className = 'filtered';
  • django/contrib/admin/media/js/admin/DateTimeShortcuts.js

    diff -r 3e100985dbfa django/contrib/admin/media/js/admin/DateTimeShortcuts.js
    a b  
    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
     
    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] + "'));");
     
    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 -r 3e100985dbfa django/contrib/admin/media/js/inlines.js
    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 -r 3e100985dbfa django/contrib/admin/templates/admin/edit_inline/stacked.html
    a b  
    1 {% load i18n %}
     1{% load i18n adminmedia %}
    22<div class="inline-group" id="{{ inline_admin_formset.formset.prefix }}-group">
    33  <h2>{{ inline_admin_formset.opts.verbose_name_plural|title }}</h2>
    44{{ inline_admin_formset.formset.management_form }}
     
    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        }
     38        var updateSelectFilter = function() {
     39            // If any SelectFilter widgets were added, instantiate a new instance.
     40            if (typeof SelectFilter != "undefined"){
     41                $(".selectfilter").each(function(index, value){
     42                  var namearr = value.name.split('-');
     43                  SelectFilter.init(value.id, namearr[namearr.length-1], false, "{% admin_media_prefix %}");
     44                })
     45                $(".selectfilterstacked").each(function(index, value){
     46                  var namearr = value.name.split('-');
     47                  SelectFilter.init(value.id, namearr[namearr.length-1], true, "{% admin_media_prefix %}");
     48                })
     49            }
     50        }
    3151        $(rows).formset({
    3252            prefix: "{{ inline_admin_formset.formset.prefix }}",
    3353            addText: "{% blocktrans with inline_admin_formset.opts.verbose_name|title as verbose_name %}Add another {{ verbose_name }}{% endblocktrans %}",
     
    3656            deleteText: "{% trans "Remove" %}",
    3757            emptyCssClass: "empty-form",
    3858            removed: updateInlineLabel,
    39             added: updateInlineLabel
     59            added: (function(row) {
     60                reinitDateTimeShortCuts();
     61                updateSelectFilter();
     62                updateInlineLabel(row);
     63            })
    4064        });
    4165    });
    4266})(jQuery.noConflict());
    43 </script>
    44  No newline at end of file
     67</script>
  • django/contrib/admin/templates/admin/edit_inline/tabular.html

    diff -r 3e100985dbfa django/contrib/admin/templates/admin/edit_inline/tabular.html
    a b  
    1 {% load i18n %}
     1{% load i18n adminmedia %}
    22<div class="inline-group" id="{{ inline_admin_formset.formset.prefix }}-group">
    33  <div class="tabular inline-related {% if forloop.last %}last-related{% endif %}">
    44{{ inline_admin_formset.formset.management_form }}
     
    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        }
     83        var updateSelectFilter = function() {
     84            // If any SelectFilter widgets are a part of the new form,
     85            // instantiate a new SelectFilter instance for it.
     86            if (typeof SelectFilter != "undefined"){
     87                $(".selectfilter").each(function(index, value){
     88                  var namearr = value.name.split('-');
     89                  SelectFilter.init(value.id, namearr[namearr.length-1], false, "{% admin_media_prefix %}");
     90                })
     91                $(".selectfilterstacked").each(function(index, value){
     92                  var namearr = value.name.split('-');
     93                  SelectFilter.init(value.id, namearr[namearr.length-1], true, "{% admin_media_prefix %}");
     94                })
     95            }
     96        }
    7697        $(rows).formset({
    7798            prefix: "{{ inline_admin_formset.formset.prefix }}",
    7899            addText: "{% blocktrans with inline_admin_formset.opts.verbose_name|title as verbose_name %}Add another {{ verbose_name }}{% endblocktrans %}",
     
    81102            deleteText: "{% trans "Remove" %}",
    82103            emptyCssClass: "empty-form",
    83104            removed: alternatingRows,
    84             added: alternatingRows
     105            added: (function(row) {
     106                reinitDateTimeShortCuts();
     107                updateSelectFilter();
     108                alternatingRows(row);
     109            })
    85110        });
    86111    });
    87112})(jQuery.noConflict());
    88 </script>
    89  No newline at end of file
     113</script>
  • django/contrib/admin/widgets.py

    diff -r 3e100985dbfa django/contrib/admin/widgets.py
    a b  
    3333        super(FilteredSelectMultiple, self).__init__(attrs, choices)
    3434
    3535    def render(self, name, value, attrs=None, choices=()):
     36        if attrs is None: attrs = {}
     37        attrs['class'] = 'selectfilter'
     38        if self.is_stacked: attrs['class'] += 'stacked'
    3639        output = [super(FilteredSelectMultiple, self).render(name, value, attrs, choices)]
    3740        output.append(u'<script type="text/javascript">addEvent(window, "load", function(e) {')
    3841        # TODO: "id_" is hard-coded here. This should instead use the correct
Back to Top