Re-add saving expand/collapse state in IMP folders page
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 24 Aug 2010 07:27:25 +0000 (01:27 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 24 Aug 2010 07:27:25 +0000 (01:27 -0600)
imp/folders.php
imp/js/folders.js
imp/lib/Ajax/Application.php

index a20044f..6465774 100644 (file)
@@ -430,8 +430,10 @@ if (!empty($imaptree->recent)) {
 }
 
 Horde::addInlineScript(array(
+    'ImpFolders.ajax = ' . Horde_Serialize::serialize(Horde::getServiceLink('ajax', 'imp')->url, Horde_Serialize::JSON, $charset),
     'ImpFolders.displayNames = ' . Horde_Serialize::serialize($displayNames, Horde_Serialize::JSON, $charset),
-    'ImpFolders.fullNames = ' . Horde_Serialize::serialize($fullNames, Horde_Serialize::JSON, $charset)
+    'ImpFolders.fullNames = ' . Horde_Serialize::serialize($fullNames, Horde_Serialize::JSON, $charset),
+    'ImpFolders.mbox_expand' => intval($prefs->getValue('nav_expanded') == 2)
 ));
 
 $title = _("Folder Navigator");
index 81d6594..038ed1d 100644 (file)
@@ -162,6 +162,11 @@ var ImpFolders = {
         });
     },
 
+    toggleSubfolder: function(e, type)
+    {
+        new Ajax.Request(this.ajax + type + 'Mailboxes', { parameters: { encoded: 1, mboxes: Object.toJSON([ e.memo ]) } });
+    },
+
     changeHandler: function(e)
     {
         switch (e.element().readAttribute('id')) {
@@ -198,9 +203,18 @@ var ImpFolders = {
 
             elt = elt.up();
         }
+    },
+
+    onDomLoad: function()
+    {
+        if (this.mbox_expand) {
+            $('fmanager').observe('Horde_Tree:collapse', this.toggleSubfolder.bindAsEventListener(this, 'collapse'));
+            $('fmanager').observe('Horde_Tree:expand', this.toggleSubfolder.bindAsEventListener(this, 'expand'));
+        }
     }
 
 };
 
 document.observe('change', ImpFolders.changeHandler.bind(ImpFolders));
 document.observe('click', ImpFolders.clickHandler.bind(ImpFolders));
+document.observe('dom:loaded', ImpFolders.onDomLoad.bind(ImpFolders));
index 4e0c9c4..714e44d 100644 (file)
@@ -358,11 +358,40 @@ class IMP_Ajax_Application extends Horde_Core_Ajax_Application
     }
 
     /**
+     * AJAX action: Expand mailboxes (saves expanded state in prefs).
+     *
+     * Variables used:
+     * <pre>
+     * 'encoded' - (integer) 1 if mboxes is URL encoded.
+     * 'mboxes' - (string) The list of mailboxes to process (JSON encoded
+     *            array) if 'all' is 0.
+     * </pre>
+     *
+     * @return boolean  True.
+     */
+    public function expandMailboxes()
+    {
+        $imptree = $GLOBALS['injector']->getInstance('IMP_Imap_Tree');
+
+        if (!empty($this->_vars->mboxes)) {
+            foreach (Horde_Serialize::unserialize($this->_vars->mboxes, Horde_Serialize::JSON) as $val) {
+                if ($this->_vars->encoded) {
+                    $val = rawurldecode($val);
+                }
+                $imptree->expand($val);
+            }
+        }
+
+        return true;
+    }
+
+    /**
      * AJAX action: Collapse mailboxes.
      *
      * Variables used:
      * <pre>
      * 'all' - (integer) 1 to show all mailboxes.
+     * 'encoded' - (integer) 1 if mboxes is URL encoded.
      * 'mboxes' - (string) The list of mailboxes to process (JSON encoded
      *            array) if 'all' is 0.
      * </pre>
@@ -377,6 +406,9 @@ class IMP_Ajax_Application extends Horde_Core_Ajax_Application
             $imptree->collapseAll();
         } elseif (!empty($this->_vars->mboxes)) {
             foreach (Horde_Serialize::unserialize($this->_vars->mboxes, Horde_Serialize::JSON) as $val) {
+                if ($this->_vars->encoded) {
+                    $val = rawurldecode($val);
+                }
                 $imptree->collapse($val);
             }
         }