web/static/admin/js/collapse.js
author wakimd
Tue, 16 Nov 2010 14:15:07 +0100
changeset 9 22ab430e9b64
permissions -rw-r--r--
Corrections on models and general structure
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
     1
(function($) {
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
     2
	$(document).ready(function() {
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
     3
		// Add anchor tag for Show/Hide link
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
     4
		$("fieldset.collapse").each(function(i, elem) {
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
     5
			// Don't hide if fields in this fieldset have errors
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
     6
			if ( $(elem).find("div.errors").length == 0 ) {
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
     7
				$(elem).addClass("collapsed");
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
     8
				$(elem).find("h2").first().append(' (<a id="fieldsetcollapser' +
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
     9
					i +'" class="collapse-toggle" href="#">' + gettext("Show") +
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    10
					'</a>)');
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    11
			}
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    12
		});
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    13
		// Add toggle to anchor tag
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    14
		$("fieldset.collapse a.collapse-toggle").toggle(
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    15
			function() { // Show
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    16
				$(this).text(gettext("Hide"));
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    17
				$(this).closest("fieldset").removeClass("collapsed");
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    18
				return false;
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    19
			},
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    20
			function() { // Hide
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    21
				$(this).text(gettext("Show"));
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    22
				$(this).closest("fieldset").addClass("collapsed");
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    23
				return false;
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    24
			}
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    25
		);
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    26
	});
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    27
})(django.jQuery);