Ticket #5899: 5899.collapsible-fieldsets.diff
File 5899.collapsible-fieldsets.diff, 8.6 KB (added by , 13 years ago) |
---|
-
django/contrib/admin/helpers.py
diff --git a/django/contrib/admin/helpers.py b/django/contrib/admin/helpers.py index 04a3492..fb5e5a6 100644
a b class Fieldset(object): 74 74 self.readonly_fields = readonly_fields 75 75 76 76 def _media(self): 77 if 'collapse' in self.classes :77 if 'collapse' in self.classes or 'collapsible' in self.classes: 78 78 js = ['jquery.min.js', 'jquery.init.js', 'collapse.min.js'] 79 79 return forms.Media(js=[static('admin/js/%s' % url) for url in js]) 80 80 return forms.Media() -
django/contrib/admin/static/admin/js/collapse.js
diff --git a/django/contrib/admin/static/admin/js/collapse.js b/django/contrib/admin/static/admin/js/collapse.js index 0a1e2d8..93b58ac 100644
a b 1 1 (function($) { 2 2 $(document).ready(function() { 3 // Add anchor tag for Show/Hide link 4 $("fieldset.collapse").each(function(i, elem) { 5 // Don't hide if fields in this fieldset have errors 6 if ( $(elem).find("div.errors").length == 0 ) { 7 $(elem).addClass("collapsed"); 8 $(elem).find("h2").first().append(' (<a id="fieldsetcollapser' + 9 i +'" class="collapse-toggle" href="#">' + gettext("Show") + 10 '</a>)'); 11 } 12 }); 13 // Add toggle to anchor tag 14 $("fieldset.collapse a.collapse-toggle").toggle( 15 function() { // Show 16 $(this).text(gettext("Hide")); 17 $(this).closest("fieldset").removeClass("collapsed"); 3 /** 4 * Structure for handling collapsible fieldsets. 5 * There are two opportunities: 6 * 1. using "collapse" as class name of the fieldset the fieldset will 7 * be initially hidden and can be shown by click 8 * 2. using "collapsible" as class name of the fieldset the fielset 9 * will be initially shown but can be hidden by click. 10 * This structure adds the click elements and their behaviour to the 11 * existing html of the fieldsets. 12 */ 13 var CollapsedFieldsets = { 14 /** 15 * Initializes the structure. 16 */ 17 init: function() { 18 this.appendShowHideLink(); 19 this.initToggling(); 20 }, 21 22 /** 23 * Appends the clickable elements, either for showing or hiding 24 * depending on the current state of the fieldset. 25 */ 26 appendShowHideLink: function() { 27 $('fieldset.collapse, fieldset.collapsible').each(function(i, elem) { 28 // Don't hide if fields in this fieldset have errors 29 if ( $(elem).find('div.errors').length == 0 ) { 30 // do not collapse initially shown "collapsibles" 31 if (!$(elem).hasClass('collapsible')) { 32 $(elem).addClass('collapsed'); 33 } 34 $(elem).find('h2').first().append(' (<a id="fieldsetcollapser' + 35 i +'" class="collapse-toggle" href="#">' + 36 (!$(elem).hasClass('collapsible') ? gettext('Show') : gettext('Hide')) + 37 '</a>)'); 38 } 39 }); 40 }, 41 42 /** 43 * Initializes the toggling for the clickable elements to show/hide 44 * the fieldset. 45 */ 46 initToggling: function() { 47 $('fieldset.collapse a.collapse-toggle, fieldset.collapsible a.collapse-toggle').toggle( 48 function(e) { this.toggleOn(e.target); }.bind(this), 49 function(e) { this.toggleOff(e.target); }.bind(this) 50 ); 51 }, 52 53 /** 54 * The first toggle method moving the clickable element from its 55 * initial state to the next one. Collapses the fieldset if it's 56 * uncollapsed and vice versa. 57 * @param target the clickable link 58 */ 59 toggleOn: function(target) { 60 if ($(target).closest('fieldset').hasClass('collapsible')) { 61 this.collapseElement($(target)); 62 } else { 63 this.uncollapseElement($(target)); 64 } 18 65 return false; 19 66 }, 20 function() { // Hide 21 $(this).text(gettext("Show")); 22 $(this).closest("fieldset").addClass("collapsed"); 67 68 /** 69 * The seconds toggle method moving the clickable element from its 70 * second state back to the initial one. Collapses the fieldset 71 * if it's uncollapsed and vice versa. 72 * @param target the clickable link 73 */ 74 toggleOff: function(target) { 75 if ($(target).closest('fieldset').hasClass('collapsible')) { 76 this.uncollapseElement($(target)); 77 } else { 78 this.collapseElement($(target)); 79 } 23 80 return false; 81 }, 82 83 /** 84 * Collapses the given element by applying the new "Show" label 85 * and adding the collapsed class. 86 * @param element the clickable element 87 */ 88 collapseElement: function(element) { 89 element.text(gettext('Show')); 90 element.closest('fieldset').addClass('collapsed'); 91 }, 92 93 /** 94 * Uncollapses the given element by applying the new "Hide" label 95 * and removing the collapsed class. 96 * @param element the clickable element 97 */ 98 uncollapseElement: function(element) { 99 element.text(gettext('Hide')); 100 element.closest('fieldset').removeClass('collapsed'); 24 101 } 25 ); 102 }; 103 104 // Engage! 105 CollapsedFieldsets.init(); 26 106 }); 27 107 })(django.jQuery); -
django/contrib/admin/static/admin/js/collapse.min.js
diff --git a/django/contrib/admin/static/admin/js/collapse.min.js b/django/contrib/admin/static/admin/js/collapse.min.js index 428984e..300302a 100644
a b 1 (function( a){a(document).ready(function(){a("fieldset.collapse").each(function(c,b){if(a(b).find("div.errors").length==0){a(b).addClass("collapsed");a(b).find("h2").first().append(' (<a id="fieldsetcollapser'+c+'" class="collapse-toggle" href="#">'+gettext("Show")+"</a>)")}});a("fieldset.collapse a.collapse-toggle").toggle(function(){a(this).text(gettext("Hide"));a(this).closest("fieldset").removeClass("collapsed");return false},function(){a(this).text(gettext("Show"));a(this).closest("fieldset").addClass("collapsed");2 return false})})})(django.jQuery);1 (function(b){b(document).ready(function(){({init:function(){this.appendShowHideLink();this.initToggling()},appendShowHideLink:function(){b("fieldset.collapse, fieldset.collapsible").each(function(a,c){if(b(c).find("div.errors").length==0){b(c).hasClass("collapsible")||b(c).addClass("collapsed");b(c).find("h2").first().append(' (<a id="fieldsetcollapser'+a+'" class="collapse-toggle" href="#">'+(!b(c).hasClass("collapsible")?gettext("Show"):gettext("Hide"))+"</a>)")}})},initToggling:function(){b("fieldset.collapse a.collapse-toggle, fieldset.collapsible a.collapse-toggle").toggle(function(a){this.toggleOn(a.target)}.bind(this), 2 function(a){this.toggleOff(a.target)}.bind(this))},toggleOn:function(a){b(a).closest("fieldset").hasClass("collapsible")?this.collapseElement(b(a)):this.uncollapseElement(b(a));return false},toggleOff:function(a){b(a).closest("fieldset").hasClass("collapsible")?this.uncollapseElement(b(a)):this.collapseElement(b(a));return false},collapseElement:function(a){a.text(gettext("Show"));a.closest("fieldset").addClass("collapsed")},uncollapseElement:function(a){a.text(gettext("Hide"));a.closest("fieldset").removeClass("collapsed")}}).init()})})(django.jQuery); -
docs/intro/tutorial02.txt
diff --git a/docs/intro/tutorial02.txt b/docs/intro/tutorial02.txt index 7d2ce4f..3bd887c 100644
a b Here's what our form looks like now: 212 212 :alt: Form has fieldsets now 213 213 214 214 You can assign arbitrary HTML classes to each fieldset. Django provides a 215 ``"collapse"`` class that displays a particular fieldset initially collapsed. 216 This is useful when you have a long form that contains a number of fields that 217 aren't commonly used:: 215 ``"collapse"`` and ``"collapsible"` classes that allow a particular fieldset to 216 be initially collapsed, respectively to be collapsible. This is useful when 217 you have a long form that contains a number of fields that aren't commonly 218 used:: 218 219 219 220 class PollAdmin(admin.ModelAdmin): 220 221 fieldsets = [ -
docs/ref/contrib/admin/index.txt
diff --git a/docs/ref/contrib/admin/index.txt b/docs/ref/contrib/admin/index.txt index 8ba41aa..5c7a406 100644
a b subclass:: 274 274 Two useful classes defined by the default admin site stylesheet are 275 275 ``collapse`` and ``wide``. Fieldsets with the ``collapse`` style 276 276 will be initially collapsed in the admin and replaced with a small 277 "click to expand" link. Fieldsets with the ``wide`` style will be 277 "click to expand" link. Alternatively you can use ``collapsible`` 278 which has the same effect as ``collapse``, but fieldsets will be 279 initially expanded. Fieldsets with the ``wide`` style will be 278 280 given extra horizontal space. 279 281 280 282 * ``description``