From 37db1ae919326399b18d6d2eacfdec37e5c632d9 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Fri, 16 Jul 2010 13:04:07 -0600 Subject: [PATCH] Honor nav_expanded preference (DIMP) --- imp/docs/CHANGES | 1 + imp/js/dimpbase.js | 33 ++++++++++++++++--- imp/lib/Ajax/Application.php | 50 ++++++++++++++++++++++++++--- imp/lib/Imap/Tree.php | 7 +++- imp/templates/dimp/javascript_defs_dimp.php | 3 +- 5 files changed, 83 insertions(+), 11 deletions(-) diff --git a/imp/docs/CHANGES b/imp/docs/CHANGES index 91ef26dfe..e8ed4996a 100644 --- a/imp/docs/CHANGES +++ b/imp/docs/CHANGES @@ -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; diff --git a/imp/js/dimpbase.js b/imp/js/dimpbase.js index 455afb37e..8d9a26f76 100644 --- a/imp/js/dimpbase.js +++ b/imp/js/dimpbase.js @@ -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 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 }); } } diff --git a/imp/lib/Ajax/Application.php b/imp/lib/Ajax/Application.php index 9bc0336ce..5a51f8226 100644 --- a/imp/lib/Ajax/Application.php +++ b/imp/lib/Ajax/Application.php @@ -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: *
+     * '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:
+     * 
+     * 'all' - (integer) 1 to show all mailboxes.
+     * 'mboxes' - (string) The list of mailboxes to process (JSON encoded
+     *            array) if 'all' is 0.
+     * 
+ * + * @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(). diff --git a/imp/lib/Imap/Tree.php b/imp/lib/Imap/Tree.php index 91dc170b4..e9dfe7812 100644 --- a/imp/lib/Imap/Tree.php +++ b/imp/lib/Imap/Tree.php @@ -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. + *
* * @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; } diff --git a/imp/templates/dimp/javascript_defs_dimp.php b/imp/templates/dimp/javascript_defs_dimp.php index f3f6398fb..f0412413d 100644 --- a/imp/templates/dimp/javascript_defs_dimp.php +++ b/imp/templates/dimp/javascript_defs_dimp.php @@ -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' => '', -- 2.11.0