Ticket #5899: django_newforms-admin.collapsible_fieldset.diff

File django_newforms-admin.collapsible_fieldset.diff, 5.2 KB (added by Ionut Ciocirlan <ionut.ciocirlan@…>, 7 years ago)
  • django/contrib/admin/media/js/admin/CollapsedFieldsets.js

     
    1111}
    1212
    1313var CollapsedFieldsets = {
    14     collapse_re: /\bcollapse\b/,   // Class of fieldsets that should be dealt with.
     14    collapse_re: /\bcollaps(e|ible)\b/,   // Class of fieldsets that should be dealt with.
    1515    collapsed_re: /\bcollapsed\b/, // Class that fieldsets get when they're hidden.
    1616    collapsed_class: 'collapsed',
     17    collapsible_class: 'collapsible', // This will not be initially collapsed
    1718    init: function() {
    1819        var fieldsets = document.getElementsByTagName('fieldset');
    1920        var collapsed_seen = false;
    2021        for (var i = 0, fs; fs = fieldsets[i]; i++) {
    21             // Collapse this fieldset if it has the correct class, and if it
    22             // doesn't have any errors. (Collapsing shouldn't apply in the case
     22            // 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
    2324            // 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>)
    2933                var collapse_link = document.createElement('a');
    3034                collapse_link.className = 'collapse-toggle';
    3135                collapse_link.id = 'fieldsetcollapser' + i;
    32                 collapse_link.onclick = new Function('CollapsedFieldsets.show('+i+'); return false;');
    3336                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                }
    3544                var h2 = fs.getElementsByTagName('h2')[0];
    3645                h2.appendChild(document.createTextNode(' ('));
    3746                h2.appendChild(collapse_link);
  • django/contrib/admin/options.py

     
    7878
    7979    def _media(self):
    8080        from django.conf import settings
    81         if 'collapse' in self.classes:
     81        if 'collapse' in self.classes or 'collapsible' in self.classes:
    8282            return forms.Media(js=['%sjs/admin/CollapsedFieldsets.js' % settings.ADMIN_MEDIA_PREFIX])
    8383        return forms.Media()
    8484    media = property(_media)
  • docs/tutorial02.txt

     
    179179   :alt: Form has fieldsets now
    180180   :target: http://media.djangoproject.com/img/doc/tutorial/admin08.png
    181181
    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::
     182You can assign arbitrary HTML classes to each fieldset. Django provides the
     183``"collapse"`` and ``"collapsible"`` classes that allow a particular fieldset
     184to be initially collapsed, respectively to be collapsible. This is useful when
     185you have a long form that contains a number of fields that aren't commonly
     186used::
    186187
    187188        class Admin:
    188189            fields = (
  • docs/model-api.txt

     
    13241324``collapse`` and ``wide``. Fieldsets with the ``collapse`` style will be
    13251325initially collapsed in the admin and replaced with a small "click to expand"
    13261326link. Fieldsets with the ``wide`` style will be given extra horizontal space.
     1327Alternatively you can use ``collapsible`` which has the same effect as
     1328``collapse``, but fieldsets will be initially expanded.
    13271329
    13281330``description``
    13291331~~~~~~~~~~~~~~~
Back to Top