Use Horde_Tree to render folder tree in MIMP
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 25 Aug 2010 05:47:43 +0000 (23:47 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 25 Aug 2010 05:59:13 +0000 (23:59 -0600)
imp/folders-mimp.php
imp/lib/Imap/Tree.php
imp/templates/mimp/folders/folders.html

index fa9812b..c8dc0d4 100644 (file)
@@ -33,6 +33,7 @@ $showAll = (!$subscribe || $_SESSION['imp']['showunsub']);
 
 /* Initialize the IMP_Imap_Tree object. */
 $imptree = $injector->getInstance('IMP_Imap_Tree');
+$mask = IMP_Imap_Tree::FLIST_CONTAINER;
 
 /* Toggle subscribed view, if necessary. */
 if ($subscribe && Horde_Util::getFormData('ts')) {
@@ -40,27 +41,15 @@ if ($subscribe && Horde_Util::getFormData('ts')) {
     $_SESSION['imp']['showunsub'] = $showAll;
     $imptree->showUnsubscribed($showAll);
     if ($showAll) {
-        $imptree->setIteratorFilter(IMP_Imap_Tree::FLIST_UNSUB);
+        $mask |= IMP_Imap_Tree::FLIST_UNSUB;
     }
 }
 
-/* Initialize Horde_Template. */
-$t = $injector->createInstance('Horde_Template');
-
-/* Start iterating through the list of mailboxes, displaying them. */
-$rows = array();
-foreach ($imptree as $val) {
-    $poll_info = $val->polled
-        ? $val->poll_info
-        : null;
-    $rows[] = array(
-        'level' => str_repeat('&nbsp;', $val->level * 2),
-        'label' => htmlspecialchars(Horde_String::abbreviate($val->label, 30 - ($val->level * 2))),
-        'link' => ($val->container ? null : IMP::generateIMPUrl('mailbox-mimp.php', $val->value)),
-        'msgs' => ($poll_info ? ($poll_info->unseen . '/' . $poll_info->msgs) : null)
-    );
-}
-$t->set('rows', $rows);
+$imptree->setIteratorFilter($mask);
+$tree = $imptree->createTree('mimp_folders', array(
+    'poll_info' => true,
+    'render_type' => 'Simplehtml'
+));
 
 $selfurl = Horde::applicationUrl('folders-mimp.php');
 $menu = array(array(_("Refresh"), $selfurl));
@@ -71,10 +60,12 @@ if ($subscribe) {
     );
 }
 
-$t->set('menu', $injector->getInstance('IMP_Ui_Mimp')->getMenu('folders', $menu));
-
 $title = _("Folders");
+
+$t = $injector->createInstance('Horde_Template');
+$t->set('menu', $injector->getInstance('IMP_Ui_Mimp')->getMenu('folders', $menu));
 $t->set('title', $title);
+$t->set('tree', $tree->getTree(true));
 
 require_once IMP_TEMPLATES . '/common-header.inc';
 IMP::status();
index b8d166c..79d8245 100644 (file)
@@ -1473,12 +1473,18 @@ class IMP_Imap_Tree implements ArrayAccess, Iterator
      *            DEFAULT: null (add to base level)
      * 'poll_info' - (boolean) Include poll information?
      *               DEFAULT: false
+     * 'render_type' - (string) The renderer name.
+     *                 DEFAULT: Javascript
      * </pre>
      *
      * @return Horde_Tree  The tree object.
      */
     public function createTree($name, array $opts = array())
     {
+        $opts = array_merge(array(
+            'render_type' => 'Javascript'
+        ), $opts);
+
         $this->recent = array();
         $this->unseen = 0;
 
@@ -1487,7 +1493,7 @@ class IMP_Imap_Tree implements ArrayAccess, Iterator
             $indent = $opts['indent'];
             $parent = $opts['parent'];
         } else {
-            $tree = $GLOBALS['injector']->getInstance('Horde_Tree')->getTree($name, 'Javascript', array(
+            $tree = $GLOBALS['injector']->getInstance('Horde_Tree')->getTree($name, $opts['render_type'], array(
                 'alternate' => true,
                 'lines' => true,
                 'lines_base' => true
@@ -1495,13 +1501,23 @@ class IMP_Imap_Tree implements ArrayAccess, Iterator
             $indent = 0;
             $parent = null;
         }
-        $mailbox_url = Horde::applicationUrl('mailbox.php');
+
+        $mailbox_url = (IMP::getViewMode() == 'mimp')
+            ? Horde::applicationUrl('mailbox-mimp.php')
+            : Horde::applicationUrl('mailbox.php');
 
         foreach ($this as $val) {
             $after = $class = '';
-            $label = $val->name;
             $url = null;
 
+            if ($opts['render_type'] == 'Simplehtml') {
+                $label =  htmlspecialchars(Horde_String::abbreviate($val->label, 30 - ($val->level * 2)));
+                $icon = null;
+            } else {
+                $label = $val->name;
+                $icon = $val->icon;
+            }
+
             if (!empty($opts['poll_info']) && $val->polled) {
                 $poll_info = $val->poll_info;
 
@@ -1541,7 +1557,6 @@ class IMP_Imap_Tree implements ArrayAccess, Iterator
                 }
             }
 
-            $icon = $val->icon;
             $tree->addNode(
                 strval($parent) . $val->value,
                 ($val->level) ? strval($parent) . $val->parent : $parent,
@@ -1550,8 +1565,8 @@ class IMP_Imap_Tree implements ArrayAccess, Iterator
                 $val->is_open,
                 array(
                     'class' => $class,
-                    'icon' => $icon->icon,
-                    'iconopen' => $icon->iconopen,
+                    'icon' => $icon ? $icon->icon : null,
+                    'iconopen' => $icon ? $icon->iconopen : null,
                     'url' => $url
                 ),
                 $after,
index 4a99017..0c3c96b 100644 (file)
@@ -1,8 +1,6 @@
   <div><tag:title /></div>
   <hr />
-<loop:rows>
-  <div><tag:rows.level /><if:rows.link><a href="<tag:rows.link />"><tag:rows.label /></a><else:rows.link><tag:rows.label /></else:rows.link></if:rows.link><if:rows.msgs> (<tag:rows.msgs />)</if:rows.msgs></div>
-</loop:rows>
+  <tag:tree />
   <hr />
   <div><gettext>Menu</gettext></div>
   <tag:menu />