Ticket #5899: django_newforms-admin.collapsible_fieldset.diff
File django_newforms-admin.collapsible_fieldset.diff, 5.2 KB (added by , 17 years ago) |
---|
-
django/contrib/admin/media/js/admin/CollapsedFieldsets.js
11 11 } 12 12 13 13 var CollapsedFieldsets = { 14 collapse_re: /\bcollaps e\b/, // Class of fieldsets that should be dealt with.14 collapse_re: /\bcollaps(e|ible)\b/, // Class of fieldsets that should be dealt with. 15 15 collapsed_re: /\bcollapsed\b/, // Class that fieldsets get when they're hidden. 16 16 collapsed_class: 'collapsed', 17 collapsible_class: 'collapsible', // This will not be initially collapsed 17 18 init: function() { 18 19 var fieldsets = document.getElementsByTagName('fieldset'); 19 20 var collapsed_seen = false; 20 21 for (var i = 0, fs; fs = fieldsets[i]; i++) { 21 // Collapse this fieldset if it has the correct class, and if it22 // doesn't have any errors. (Collapsing shouldn't apply in the case22 // Collapse this fieldset or make it collapsible if it has the correct class, 23 // and if it doesn't have any errors. (Collapsing shouldn't apply in the case 23 24 // of error messages.) 24 if (fs.className.match(CollapsedFieldsets.collapse_re) && !CollapsedFieldsets.fieldset_has_errors(fs)) { 25 collapsed_seen = true; 26 // Give it an additional class, used by CSS to hide it. 27 fs.className += ' ' + CollapsedFieldsets.collapsed_class; 28 // (<a id="fieldsetcollapser3" class="collapse-toggle" href="#">Show</a>) 25 var collapse_match = fs.className.match(CollapsedFieldsets.collapse_re); 26 if (collapse_match && !CollapsedFieldsets.fieldset_has_errors(fs)) { 27 var start_collapsed = collapse_match[0] != CollapsedFieldsets.collapsible_class; 28 // If needed Give it an additional class, used by CSS to hide it. 29 if (start_collapsed) { 30 fs.className += ' ' + CollapsedFieldsets.collapsed_class; 31 } 32 // (<a id="fieldsetcollapser3" class="collapse-toggle" href="#">Show/Hide</a>) 29 33 var collapse_link = document.createElement('a'); 30 34 collapse_link.className = 'collapse-toggle'; 31 35 collapse_link.id = 'fieldsetcollapser' + i; 32 collapse_link.onclick = new Function('CollapsedFieldsets.show('+i+'); return false;');33 36 collapse_link.href = '#'; 34 collapse_link.innerHTML = gettext('Show'); 37 if (start_collapsed) { 38 collapse_link.onclick = new Function('CollapsedFieldsets.show('+i+'); return false;'); 39 collapse_link.innerHTML = gettext('Show'); 40 } else { 41 collapse_link.onclick = new Function('CollapsedFieldsets.hide('+i+'); return false;'); 42 collapse_link.innerHTML = gettext('Hide'); 43 } 35 44 var h2 = fs.getElementsByTagName('h2')[0]; 36 45 h2.appendChild(document.createTextNode(' (')); 37 46 h2.appendChild(collapse_link); -
django/contrib/admin/options.py
78 78 79 79 def _media(self): 80 80 from django.conf import settings 81 if 'collapse' in self.classes :81 if 'collapse' in self.classes or 'collapsible' in self.classes: 82 82 return forms.Media(js=['%sjs/admin/CollapsedFieldsets.js' % settings.ADMIN_MEDIA_PREFIX]) 83 83 return forms.Media() 84 84 media = property(_media) -
docs/tutorial02.txt
179 179 :alt: Form has fieldsets now 180 180 :target: http://media.djangoproject.com/img/doc/tutorial/admin08.png 181 181 182 You can assign arbitrary HTML classes to each fieldset. Django provides a 183 ``"collapse"`` class that displays a particular fieldset initially collapsed. 184 This is useful when you have a long form that contains a number of fields that 185 aren't commonly used:: 182 You can assign arbitrary HTML classes to each fieldset. Django provides the 183 ``"collapse"`` and ``"collapsible"`` classes that allow a particular fieldset 184 to be initially collapsed, respectively to be collapsible. This is useful when 185 you have a long form that contains a number of fields that aren't commonly 186 used:: 186 187 187 188 class Admin: 188 189 fields = ( -
docs/model-api.txt
1324 1324 ``collapse`` and ``wide``. Fieldsets with the ``collapse`` style will be 1325 1325 initially collapsed in the admin and replaced with a small "click to expand" 1326 1326 link. Fieldsets with the ``wide`` style will be given extra horizontal space. 1327 Alternatively you can use ``collapsible`` which has the same effect as 1328 ``collapse``, but fieldsets will be initially expanded. 1327 1329 1328 1330 ``description`` 1329 1331 ~~~~~~~~~~~~~~~