diff -r 3e100985dbfa django/contrib/admin/media/js/SelectFilter2.js
a
|
b
|
|
16 | 16 | |
17 | 17 | var SelectFilter = { |
18 | 18 | 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 | } |
19 | 23 | var from_box = document.getElementById(field_id); |
20 | 24 | from_box.id += '_from'; // change its ID |
21 | 25 | from_box.className = 'filtered'; |
diff -r 3e100985dbfa django/contrib/admin/media/js/admin/DateTimeShortcuts.js
a
|
b
|
|
11 | 11 | calendarLinkName: 'calendarlink',// name of the link that is used to toggle |
12 | 12 | clockDivName: 'clockbox', // name of clock <div> that gets toggled |
13 | 13 | clockLinkName: 'clocklink', // name of the link that is used to toggle |
| 14 | shortCutsClass: 'datetimeshortcuts', // class of the clock and cal shortcuts |
14 | 15 | admin_media_prefix: '', |
15 | 16 | init: function() { |
16 | 17 | // Deduce admin_media_prefix by looking at the <script>s in the |
… |
… |
|
42 | 43 | |
43 | 44 | // Shortcut links (clock icon and "Now" link) |
44 | 45 | var shortcuts_span = document.createElement('span'); |
| 46 | shortcuts_span.className = DateTimeShortcuts.shortCutsClass; |
45 | 47 | inp.parentNode.insertBefore(shortcuts_span, inp.nextSibling); |
46 | 48 | var now_link = document.createElement('a'); |
47 | 49 | now_link.setAttribute('href', "javascript:DateTimeShortcuts.handleClockQuicklink(" + num + ", new Date().strftime('" + get_format('TIME_INPUT_FORMATS')[0] + "'));"); |
… |
… |
|
128 | 130 | |
129 | 131 | // Shortcut links (calendar icon and "Today" link) |
130 | 132 | var shortcuts_span = document.createElement('span'); |
| 133 | shortcuts_span.className = DateTimeShortcuts.shortCutsClass; |
131 | 134 | inp.parentNode.insertBefore(shortcuts_span, inp.nextSibling); |
132 | 135 | var today_link = document.createElement('a'); |
133 | 136 | today_link.setAttribute('href', 'javascript:DateTimeShortcuts.handleCalendarQuickLink(' + num + ', 0);'); |
diff -r 3e100985dbfa django/contrib/admin/media/js/inlines.js
a
|
b
|
|
34 | 34 | var maxForms = $("#id_" + options.prefix + "-MAX_NUM_FORMS").attr("autocomplete", "off"); |
35 | 35 | // only show the add button if we are allowed to add more items |
36 | 36 | var showAddButton = ((maxForms.val() == 0) || ((maxForms.val()-totalForms.val()) > 0)); |
37 | | var selectedItems = this; |
38 | 37 | $(this).each(function(i) { |
39 | 38 | $(this).not("." + options.emptyCssClass).addClass(options.formCssClass); |
40 | 39 | }); |
diff -r 3e100985dbfa django/contrib/admin/templates/admin/edit_inline/stacked.html
a
|
b
|
|
1 | | {% load i18n %} |
| 1 | {% load i18n adminmedia %} |
2 | 2 | <div class="inline-group" id="{{ inline_admin_formset.formset.prefix }}-group"> |
3 | 3 | <h2>{{ inline_admin_formset.opts.verbose_name_plural|title }}</h2> |
4 | 4 | {{ inline_admin_formset.formset.management_form }} |
… |
… |
|
22 | 22 | (function($) { |
23 | 23 | $(document).ready(function() { |
24 | 24 | var rows = "#{{ inline_admin_formset.formset.prefix }}-group .inline-related"; |
25 | | updateInlineLabel = function(row) { |
| 25 | var updateInlineLabel = function(row) { |
26 | 26 | $(rows).find(".inline_label").each(function(i) { |
27 | 27 | var count = i + 1; |
28 | 28 | $(this).html($(this).html().replace(/(#\d+)/g, "#" + count)); |
29 | 29 | }); |
30 | 30 | } |
| 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 | } |
31 | 51 | $(rows).formset({ |
32 | 52 | prefix: "{{ inline_admin_formset.formset.prefix }}", |
33 | 53 | addText: "{% blocktrans with inline_admin_formset.opts.verbose_name|title as verbose_name %}Add another {{ verbose_name }}{% endblocktrans %}", |
… |
… |
|
36 | 56 | deleteText: "{% trans "Remove" %}", |
37 | 57 | emptyCssClass: "empty-form", |
38 | 58 | removed: updateInlineLabel, |
39 | | added: updateInlineLabel |
| 59 | added: (function(row) { |
| 60 | reinitDateTimeShortCuts(); |
| 61 | updateSelectFilter(); |
| 62 | updateInlineLabel(row); |
| 63 | }) |
40 | 64 | }); |
41 | 65 | }); |
42 | 66 | })(jQuery.noConflict()); |
43 | | </script> |
44 | | No newline at end of file |
| 67 | </script> |
diff -r 3e100985dbfa django/contrib/admin/templates/admin/edit_inline/tabular.html
a
|
b
|
|
1 | | {% load i18n %} |
| 1 | {% load i18n adminmedia %} |
2 | 2 | <div class="inline-group" id="{{ inline_admin_formset.formset.prefix }}-group"> |
3 | 3 | <div class="tabular inline-related {% if forloop.last %}last-related{% endif %}"> |
4 | 4 | {{ inline_admin_formset.formset.management_form }} |
… |
… |
|
68 | 68 | (function($) { |
69 | 69 | $(document).ready(function($) { |
70 | 70 | var rows = "#{{ inline_admin_formset.formset.prefix }}-group .tabular.inline-related tbody tr"; |
71 | | alternatingRows = function(row) { |
| 71 | var alternatingRows = function(row) { |
72 | 72 | $(rows).not(".add-row").removeClass("row1 row2") |
73 | 73 | .filter(":even").addClass("row1").end() |
74 | 74 | .filter(rows + ":odd").addClass("row2"); |
75 | 75 | } |
| 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 | } |
76 | 97 | $(rows).formset({ |
77 | 98 | prefix: "{{ inline_admin_formset.formset.prefix }}", |
78 | 99 | addText: "{% blocktrans with inline_admin_formset.opts.verbose_name|title as verbose_name %}Add another {{ verbose_name }}{% endblocktrans %}", |
… |
… |
|
81 | 102 | deleteText: "{% trans "Remove" %}", |
82 | 103 | emptyCssClass: "empty-form", |
83 | 104 | removed: alternatingRows, |
84 | | added: alternatingRows |
| 105 | added: (function(row) { |
| 106 | reinitDateTimeShortCuts(); |
| 107 | updateSelectFilter(); |
| 108 | alternatingRows(row); |
| 109 | }) |
85 | 110 | }); |
86 | 111 | }); |
87 | 112 | })(jQuery.noConflict()); |
88 | | </script> |
89 | | No newline at end of file |
| 113 | </script> |
diff -r 3e100985dbfa django/contrib/admin/widgets.py
a
|
b
|
|
33 | 33 | super(FilteredSelectMultiple, self).__init__(attrs, choices) |
34 | 34 | |
35 | 35 | 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' |
36 | 39 | output = [super(FilteredSelectMultiple, self).render(name, value, attrs, choices)] |
37 | 40 | output.append(u'<script type="text/javascript">addEvent(window, "load", function(e) {') |
38 | 41 | # TODO: "id_" is hard-coded here. This should instead use the correct |