summaryrefslogtreecommitdiff
path: root/static/admin/js/collapse.js
diff options
context:
space:
mode:
Diffstat (limited to 'static/admin/js/collapse.js')
-rw-r--r--static/admin/js/collapse.js26
1 files changed, 26 insertions, 0 deletions
diff --git a/static/admin/js/collapse.js b/static/admin/js/collapse.js
new file mode 100644
index 0000000..7cb9362
--- /dev/null
+++ b/static/admin/js/collapse.js
@@ -0,0 +1,26 @@
+/*global gettext*/
+(function($) {
+ 'use strict';
+ $(document).ready(function() {
+ // Add anchor tag for Show/Hide link
+ $("fieldset.collapse").each(function(i, elem) {
+ // Don't hide if fields in this fieldset have errors
+ if ($(elem).find("div.errors").length === 0) {
+ $(elem).addClass("collapsed").find("h2").first().append(' (<a id="fieldsetcollapser' +
+ i + '" class="collapse-toggle" href="#">' + gettext("Show") +
+ '</a>)');
+ }
+ });
+ // Add toggle to anchor tag
+ $("fieldset.collapse a.collapse-toggle").click(function(ev) {
+ if ($(this).closest("fieldset").hasClass("collapsed")) {
+ // Show
+ $(this).text(gettext("Hide")).closest("fieldset").removeClass("collapsed").trigger("show.fieldset", [$(this).attr("id")]);
+ } else {
+ // Hide
+ $(this).text(gettext("Show")).closest("fieldset").addClass("collapsed").trigger("hide.fieldset", [$(this).attr("id")]);
+ }
+ return false;
+ });
+ });
+})(django.jQuery);