]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1149899 - Remember expanded/collapsed sections
authorByron Jones <glob@mozilla.com>
Mon, 12 Oct 2015 04:56:46 +0000 (12:56 +0800)
committerByron Jones <glob@mozilla.com>
Mon, 12 Oct 2015 04:56:46 +0000 (12:56 +0800)
extensions/BugModal/Extension.pm
extensions/BugModal/template/en/default/bug_modal/edit.html.tmpl
extensions/BugModal/template/en/default/bug_modal/header.html.tmpl
extensions/BugModal/template/en/default/hook/global/setting-descs-settings.none.tmpl
extensions/BugModal/web/bug_modal.js

index 54ef8f4cac9012d453a30a552cc7b46d4b404d5e..2c60ef35ad767541610f650d7626b00a065a55b0 100644 (file)
@@ -293,6 +293,7 @@ sub webservice {
 sub install_before_final_checks {
     my ($self, $args) = @_;
     add_setting('ui_experiments', ['on', 'off'], 'off');
+    add_setting('ui_remember_collapsed', ['on', 'off'], 'off');
 
     # ensure the correct skin is being used
     my $dbh = Bugzilla->dbh;
index ddf37a26c3c728beb543cca29806ebc2b472eb4b..2663d5562b3f87f6bb56d770caabe98fe4f5185c 100644 (file)
   [% END %]
 [% END %]
 
+[%# === initialise module visibility === %]
+
+<script>
+  init_module_visibility();
+</script>
+
 [%# === top (between modules and comments) actions === %]
 
 [% IF user.id %]
index 7fdb2ed498d1582411e4a378f26934ee59c6d181..361b9ec9d2458058fc3d9bf87c5c6706347d2d17 100644 (file)
@@ -99,7 +99,8 @@
     can_tag: [% user.can_tag_comments ? "true" : "false" %],
     settings: {
       quote_replies: '[% user.settings.quote_replies.value FILTER js %]',
-      zoom_textareas: [% user.settings.zoom_textareas.value == "on" ? "true" : "false" %]
+      zoom_textareas: [% user.settings.zoom_textareas.value == "on" ? "true" : "false" %],
+      remember_collapsed: [% user.settings.ui_remember_collapsed.value == "on" ? "true" : "false" %]
     }
   };
   [% IF user.id %]
index 7214977bb59b74987b7fee843eb4c2cfab520d85..4ca9c30037376ff85184eaf3b9bfd8a05c7d6d05 100644 (file)
@@ -8,4 +8,5 @@
 
 [%
   setting_descs.ui_experiments = "Use experimental user interface"
+  setting_descs.ui_remember_collapsed = "Remember visibility of header sections when viewing a bug"
 %]
index 74ee83312d88f5b197e411c26c38232b958c5da2..ac467aa0fae5dcafbc29a7cc2b6850a8e8c1d4f0 100644 (file)
@@ -5,6 +5,47 @@
  * This Source Code Form is "Incompatible With Secondary Licenses", as
  * defined by the Mozilla Public License, v. 2.0. */
 
+// expand/collapse module
+function slide_module(module, action, fast) {
+    if (!module.attr('id'))
+        return;
+    var latch = module.find('.module-latch');
+    var spinner = $(latch.children('.module-spinner')[0]);
+    var content = $(module.children('.module-content')[0]);
+    var duration = fast ? 0 : 200;
+
+    function slide_done() {
+        var is_visible = content.is(':visible');
+        spinner.html(is_visible ? '&#9662;' : '&#9656;');
+        if (BUGZILLA.user.settings.remember_collapsed)
+            localStorage.setItem(module.attr('id') + '.visibility', is_visible ? 'show' : 'hide');
+    }
+
+    if (action == 'show') {
+        content.slideDown(duration, 'swing', slide_done);
+    }
+    else if (action == 'hide') {
+        content.slideUp(duration, 'swing', slide_done);
+    }
+    else {
+        content.slideToggle(duration, 'swing', slide_done);
+    }
+}
+
+function init_module_visibility() {
+    if (!BUGZILLA.user.settings.remember_collapsed)
+        return;
+    $('.module').each(function() {
+        var that = $(this);
+        var id = that.attr('id');
+        if (!id) return;
+        var stored = localStorage.getItem(id + '.visibility');
+        if (stored) {
+            slide_module(that, stored, true);
+        }
+    });
+}
+
 $(function() {
     'use strict';
 
@@ -25,29 +66,6 @@ $(function() {
     // products with descriptions (also lazy-loaded)
     var products = [];
 
-    // expand/collapse module
-    function slide_module(module, action, fast) {
-        if (!module.attr('id'))
-            return;
-        var latch = module.find('.module-latch');
-        var spinner = $(latch.children('.module-spinner')[0]);
-        var content = $(module.children('.module-content')[0]);
-        var duration = fast ? 0 : 200;
-
-        function slide_done() {
-            spinner.html(content.is(':visible') ? '&#9662;' : '&#9656;');
-        }
-        if (action == 'show') {
-            content.slideDown(duration, 'swing', slide_done);
-        }
-        else if (action == 'hide') {
-            content.slideUp(duration, 'swing', slide_done);
-        }
-        else {
-            content.slideToggle(duration, 'swing', slide_done);
-        }
-    }
-
     // restore edit mode after navigating back
     function restoreEditMode() {
         if (!$('#editing').val())