Ticket #13068: prepopulate-with-9983-and-9784-fix.diff
File prepopulate-with-9983-and-9784-fix.diff, 7.3 KB (added by , 15 years ago) |
---|
-
django/contrib/admin/media/js/admin/DateTimeShortcuts.js
120 120 }, 121 121 handleClockQuicklink: function(num, val) { 122 122 DateTimeShortcuts.clockInputs[num].value = val; 123 DateTimeShortcuts.clockInputs[num].focus(); 123 124 DateTimeShortcuts.dismissClock(num); 124 125 }, 125 126 // Add calendar widget to a given field. … … 247 248 format = format.replace('\n', '\\n'); 248 249 format = format.replace('\t', '\\t'); 249 250 format = format.replace("'", "\\'"); 250 return "function(y, m, d) { DateTimeShortcuts.calendarInputs["+num+"].value = new Date(y, m-1, d).strftime('"+format+"'); document.getElementById(DateTimeShortcuts.calendarDivName1+"+num+").style.display='none';}";251 return "function(y, m, d) { DateTimeShortcuts.calendarInputs["+num+"].value = new Date(y, m-1, d).strftime('"+format+"');DateTimeShortcuts.calendarInputs["+num+"].focus();document.getElementById(DateTimeShortcuts.calendarDivName1+"+num+").style.display='none';}"; 251 252 }, 252 253 handleCalendarQuickLink: function(num, offset) { 253 254 var d = new Date(); 254 255 d.setDate(d.getDate() + offset) 255 256 DateTimeShortcuts.calendarInputs[num].value = d.strftime(get_format('DATE_INPUT_FORMATS')[0]); 257 DateTimeShortcuts.calendarInputs[num].focus(); 256 258 DateTimeShortcuts.dismissCalendar(num); 257 259 }, 258 260 cancelEventPropagation: function(e) { -
django/contrib/admin/media/js/prepopulate.js
1 (function($) { 2 function getValuesFromFields(fields) { 3 var values = []; 4 dependencies.each(function() { 5 if ($(this).val().length > 0) { 6 values.push($(this).val()); 7 } 8 }); 9 field.val(URLify(values.join(' '), maxLength)); 10 return values; 11 } 12 13 $.fn.prepopulate = function(dependencies, maxLength) { 14 /* 15 Depends on urlify.js 16 Populates a selected field with the values of the dependent fields, 17 URLifies and shortens the string. 18 dependencies - selected jQuery object of dependent fields 19 maxLength - maximum length of the URLify'd string 20 */ 21 return this.each(function() { 22 var field = $(this); 23 24 field.data('_changed', false); 25 field.change(function() { 26 field.data('_changed', true); 27 }); 28 29 var populate = function () { 30 // Bail if the fields value has changed 31 if (field.data('_changed') == true) return; 32 33 var values = []; 34 dependencies.each(function() { 35 if ($(this).val().length > 0) { 36 values.push($(this).val()); 37 } 38 }); 39 field.val(URLify(values.join(' '), maxLength)); 40 }; 41 42 dependencies.keyup(populate).change(populate).focus(populate); 43 }); 44 }; 45 })(jQuery.noConflict()); -
django/contrib/admin/options.py
273 273 js.extend(['js/jquery.min.js', 'js/actions.min.js']) 274 274 if self.prepopulated_fields: 275 275 js.append('js/urlify.js') 276 js.append('js/prepopulate.js') 276 277 if self.opts.get_ordered_objects(): 277 278 js.extend(['js/getElementsBySelector.js', 'js/dom-drag.js' , 'js/admin/ordering.js']) 278 279 … … 1204 1205 js = ['js/jquery.min.js', 'js/inlines.min.js'] 1205 1206 if self.prepopulated_fields: 1206 1207 js.append('js/urlify.js') 1208 js.append('js/prepopulate.js') 1207 1209 if self.filter_vertical or self.filter_horizontal: 1208 1210 js.extend(['js/SelectBox.js' , 'js/SelectFilter2.js']) 1209 1211 return forms.Media(js=['%s%s' % (settings.ADMIN_MEDIA_PREFIX, url) for url in js]) -
django/contrib/admin/templates/admin/edit_inline/tabular.html
94 94 }) 95 95 } 96 96 } 97 var initPrepopulatedFields = function(row) { 98 $(row).find('td.prepopulated_field').each(function() { 99 var field = $(this); 100 var input = null; 101 var dependencies = null; 102 103 dependencies = row.find($.data(field.attr('id')).join(',')); 104 105 if (dependencies.length) { 106 input = field.find('input'); 107 input.prepopulate(dependencies, input.attr('maxlength')); 108 } 109 }); 110 } 97 111 $(rows).formset({ 98 112 prefix: "{{ inline_admin_formset.formset.prefix }}", 99 113 addText: "{% blocktrans with inline_admin_formset.opts.verbose_name|title as verbose_name %}Add another {{ verbose_name }}{% endblocktrans %}", … … 103 117 emptyCssClass: "empty-form", 104 118 removed: alternatingRows, 105 119 added: (function(row) { 120 initPrepopulatedFields(row); 106 121 reinitDateTimeShortCuts(); 107 122 updateSelectFilter(); 108 123 alternatingRows(row); -
django/contrib/admin/templates/admin/prepopulated_fields_js.html
1 1 <script type="text/javascript"> 2 (function($) { 3 var field = null; 4 2 5 {% for field in prepopulated_fields %} 3 document.getElementById("{{ field.field.auto_id }}").onchange = function() { this._changed = true; }; 6 $('.empty-form td.{{ field.field.name }}').addClass('prepopulated_field'); 7 8 field = { 9 id: '#{{ field.field.auto_id }}', 10 dependency_ids: [], 11 dependency_names: [], 12 maxLength: {{ field.field.field.max_length|default_if_none:"50" }} 13 }; 14 4 15 {% for dependency in field.dependencies %} 5 document.getElementById("{{ dependency.auto_id }}").onkeyup = function() { 6 var e = document.getElementById("{{ field.field.auto_id }}"); 7 if (!e._changed) { e.value = URLify({% for innerdep in field.dependencies %}document.getElementById("{{ innerdep.auto_id }}").value{% if not forloop.last %} + ' ' + {% endif %}{% endfor %}, {{ field.field.field.max_length|default_if_none:"50" }}); } 8 } 16 field['dependency_ids'].push('#{{ dependency.auto_id }}'); 17 field['dependency_names'].push('{{ dependency.name }}'); 9 18 {% endfor %} 19 20 $.data('{{ field.field.auto_id }}', field['dependency_names']); 21 $(field.id).prepopulate($(field['dependency_ids'].join(',')), field.maxLength); 10 22 {% endfor %} 23 })(jQuery.noConflict()); 11 24 </script>