Honor nav_expanded preference (DIMP)
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 16 Jul 2010 19:04:07 +0000 (13:04 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 16 Jul 2010 19:40:41 +0000 (13:40 -0600)
imp/docs/CHANGES
imp/js/dimpbase.js
imp/lib/Ajax/Application.php
imp/lib/Imap/Tree.php
imp/templates/dimp/javascript_defs_dimp.php

index 91ef26d..e8ed499 100644 (file)
@@ -2,6 +2,7 @@
 v5.0-git
 --------
 
+[mms] Honor nav_expanded preference (DIMP).
 [mms] Allow admin to define list of safe e-mail addresses that will not
       experience HTML image blocking (Request #9129).
 [mms] HTML compose editor uses Horde language for UI (Request #9084;
index 455afb3..8d9a26f 100644 (file)
@@ -9,8 +9,9 @@
 
 var DimpBase = {
     // Vars used and defaulting to null/false:
-    //   cfolderaction, folder, folderswitch, pollPE, pp, preview_replace,
-    //   resize, rownum, search, splitbar, template, uid, viewport
+    //   cfolderaction, expandfolder, folder, folderswitch, pollPE, pp,
+    //   preview_replace, resize, rownum, search, splitbar, template, uid,
+    //   viewport
     // msglist_template_horiz and msglist_template_vert set via
     //   js/mailbox-dimp.js
     cacheids: {},
@@ -2293,8 +2294,14 @@ var DimpBase = {
 
     _folderLoadCallback: function(r, callback)
     {
+        if (r.response.expand) {
+            this.expandfolder = true;
+        }
+
         this.mailboxCallback(r);
 
+        this.expandfolder = false;
+
         if (callback) {
             callback();
         }
@@ -2344,7 +2351,7 @@ var DimpBase = {
 
     _toggleSubFolder: function(base, mode, noeffect)
     {
-        var need = [], subs = [];
+        var collapse = [], need = [], subs = [];
 
         if (mode == 'expall' || mode == 'colall') {
             if (base.hasClassName('subfolders')) {
@@ -2395,6 +2402,11 @@ var DimpBase = {
                 ((mode == 'col' || mode == 'colall') && s.visible())) {
                 s.previous().down().toggleClassName('exp').toggleClassName('col');
 
+                if (mode == 'col' ||
+                    ((mode == 'tog') && s.visible())) {
+                    collapse.push(s.previous().retrieve('mbox'));
+                }
+
                 if (noeffect) {
                     s.toggle();
                 } else {
@@ -2408,6 +2420,14 @@ var DimpBase = {
                 }
             }
         });
+
+        if (DIMP.conf.mbox_expand) {
+            if (collapse.size()) {
+                DimpCore.doAction('collapseMailboxes', { mboxes: collapse.toJSON() });
+            } else if (mode == 'colall') {
+                DimpCore.doAction('collapseMailboxes', { all: 1 });
+            }
+        }
     },
 
     _listFolders: function(params)
@@ -2433,6 +2453,7 @@ var DimpBase = {
 
     // Folder actions.
     // For format of the ob object, see IMP_Dimp::_createFolderElt().
+    // If this.expandfolder is set, expand folder list on initial display.
     createFolder: function(ob)
     {
         var div, f_node, ftype, li, ll, parent_e, tmp,
@@ -2526,11 +2547,15 @@ var DimpBase = {
                 f_node.insert({ before: li });
             } else {
                 parent_e.insert(li);
+                if (this.expandfolder && !parent_e.hasClassName('folderlist')) {
+                    parent_e.up('LI').show().previous().down().removeClassName('exp').addClassName('col');
+                }
             }
 
             // Make sure the sub<mbox> ul is created if necessary.
             if (!ob.s && ob.ch) {
-                li.insert({ after: new Element('LI', { className: 'subfolders', id: submboxid }).insert(new Element('UL')).hide() });
+                li.insert({ after: Element('LI', { className: 'subfolders', id: submboxid }).insert(new Element('UL')).hide() });
+                li.insert({ after: tmp });
             }
         }
 
index 9bc0336..5a51f82 100644 (file)
@@ -270,6 +270,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
      * @return mixed  False on failure, or an object with the following
      *                entries:
      * <pre>
+     * 'expand' - (integer) Expand subfolders on load.
      * 'mailbox' - (object) Mailboxes that were altered. Contains the
      *             following properties:
      *   'a' - (array) Mailboxes that were added.
@@ -281,6 +282,8 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
     public function listMailboxes()
     {
         $imptree = $GLOBALS['injector']->getInstance('IMP_Imap_Tree');
+        $initreload = ($this->_vars->initial || $this->_vars->reload);
+        $result = new stdClass;
 
         $mask = IMP_Imap_Tree::FLIST_CONTAINER | IMP_Imap_Tree::FLIST_VFOLDER | IMP_Imap_Tree::FLIST_ELT;
         if ($this->_vars->unsub) {
@@ -288,9 +291,16 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
         }
 
         if (!$this->_vars->all) {
-            $mask |= IMP_Imap_Tree::FLIST_NOCHILDREN;
-            if ($this->_vars->initial || $this->_vars->reload) {
+            if ($initreload) {
                 $mask |= IMP_Imap_Tree::FLIST_ANCESTORS | IMP_Imap_Tree::FLIST_SAMELEVEL;
+                if ($GLOBALS['prefs']->getValue('nav_expanded')) {
+                    $result->expand = 1;
+                    $mask |= IMP_Imap_Tree::FLIST_EXPANDED;
+                } else {
+                    $mask |= IMP_Imap_Tree::FLIST_NOCHILDREN;
+                }
+            } else {
+                $mask |= IMP_Imap_Tree::FLIST_NOCHILDREN;
             }
         }
 
@@ -303,9 +313,13 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
         if (!empty($this->_vars->mboxes)) {
             foreach (Horde_Serialize::unserialize($this->_vars->mboxes, Horde_Serialize::JSON) as $val) {
                 $folder_list += $imptree->folderList($mask, $val);
+
+                if (!$initreload) {
+                    $imptree->expand($val);
+                }
             }
 
-            if (($this->_vars->initial || $this->_vars->reload) && empty($folder_list)) {
+            if ($initreload && empty($folder_list)) {
                 $folder_list = $imptree->folderList($mask, 'INBOX');
             }
         }
@@ -313,7 +327,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
         /* Add special folders explicitly to the initial folder list, since
          * they are ALWAYS displayed and may appear outside of the folder
          * slice requested. */
-        if ($this->_vars->initial || $this->_vars->reload) {
+        if ($initreload) {
             foreach ($imptree->getSpecialMailboxes() as $val) {
                 if (!is_array($val)) {
                     $val = array($val);
@@ -328,7 +342,6 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
             }
         }
 
-        $result = new stdClass;
         $result->mailbox = $this->_getMailboxResponse($imptree, array(
             'a' => array_values($folder_list),
             'c' => array(),
@@ -344,6 +357,33 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
     }
 
     /**
+     * AJAX action: Collapse mailboxes.
+     *
+     * Variables used:
+     * <pre>
+     * 'all' - (integer) 1 to show all mailboxes.
+     * 'mboxes' - (string) The list of mailboxes to process (JSON encoded
+     *            array) if 'all' is 0.
+     * </pre>
+     *
+     * @return boolean  True.
+     */
+    public function collapseMailboxes()
+    {
+        $imptree = $GLOBALS['injector']->getInstance('IMP_Imap_Tree');
+
+        if ($this->_vars->all) {
+            $imptree->collapseAll();
+        } elseif (!empty($this->_vars->mboxes)) {
+            foreach (Horde_Serialize::unserialize($this->_vars->mboxes, Horde_Serialize::JSON) as $val) {
+                $imptree->collapse($val);
+            }
+        }
+
+        return true;
+    }
+
+    /**
      * AJAX action: Poll mailboxes.
      *
      * See the list of variables needed for _changed() and _viewPortData().
index 91dc170..e9dfe78 100644 (file)
@@ -56,6 +56,7 @@ class IMP_Imap_Tree
     const FLIST_NOCHILDREN = 32;
     const FLIST_ANCESTORS = 64;
     const FLIST_SAMELEVEL = 128;
+    const FLIST_EXPANDED = 256;
 
     /* Add null to folder key since it allows us to sort by name but
      * never conflict with an IMAP mailbox. */
@@ -1675,6 +1676,8 @@ class IMP_Imap_Tree
      * IMP_Imap_Tree::FLIST_ANCESTORS - Include ancestors.
      * IMP_Imap_Tree::FLIST_SAMELEVEL - Also return mailboxes at the same
      *                                  level as $base.
+     * IMP_Imap_Tree::FLIST_EXPANDED - Only included expanded folders.
+     * </pre>
      * </pre>
      * @param string $base  Return all mailboxes below this element.
      *
@@ -1721,7 +1724,9 @@ class IMP_Imap_Tree
             }
         }
 
-        $nextmask = self::NEXT_SHOWCLOSED;
+        $nextmask = ($mask & self::FLIST_EXPANDED)
+            ? 0
+            : self::NEXT_SHOWCLOSED;
         if ($mask & self::FLIST_NOCHILDREN) {
             $nextmask |= self::NEXT_NOCHILDREN;
         }
index f3f6398..f041241 100644 (file)
@@ -64,6 +64,7 @@ $code['conf'] = array_filter(array(
     'fsearchid' => IMP_Search::MBOX_PREFIX . IMP_Search::DIMP_FILTERSEARCH,
     'ham_spammbox' => intval(!empty($GLOBALS['conf']['notspam']['spamfolder'])),
     'login_view' => $GLOBALS['prefs']->getValue('dimp_login_view'),
+    'mbox_expand' => intval($GLOBALS['prefs']->getValue('nav_expanded') == 2),
     'name' => $GLOBALS['registry']->get('name', 'imp'),
     'popup_height' => 610,
     'popup_width' => 820,
@@ -72,7 +73,7 @@ $code['conf'] = array_filter(array(
     'qsearchfield' => $GLOBALS['prefs']->getValue('dimp_qsearch_field'),
     'refresh_time' => intval($GLOBALS['prefs']->getValue('refresh_time')),
     'searchprefix' => IMP_Search::MBOX_PREFIX,
-    'sidebar_width' => max((int)$GLOBALS['prefs']->getValue('sidebar_width'), 150) . 'px',
+    'sidebar_width' => max(intval($GLOBALS['prefs']->getValue('sidebar_width')), 150) . 'px',
     'sort' => array(
         'sequence' => array(
             't' => '',