Horde_Tree cleanups.
authorMichael M Slusarz <slusarz@curecanti.org>
Mon, 23 Aug 2010 22:19:01 +0000 (16:19 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 24 Aug 2010 06:00:58 +0000 (00:00 -0600)
Don't hardcode float or other styles.
Use spans for internal elements.

agora/lib/Api.php
agora/lib/Comments.php
agora/lib/Messages.php
agora/themes/screen.css
framework/Core/lib/Horde/Core/Perms/Ui.php
framework/Tree/lib/Horde/Tree/Html.php
horde/admin/activesync.php
horde/admin/groups.php
horde/js/hordetree.js
horde/themes/screen.css

index a5406c3..fdf2e54 100644 (file)
@@ -293,12 +293,14 @@ class Agora_Api extends Horde_Registry_Api
             return '';
         }
 
-        $col_headers = array('message_thread' => _("Subject"),
-                            'message_thread_class_plain' => '',
-                            'message_author' => _("Posted by"),
-                            'message_author_class_plain' => '',
-                            'message_timestamp' => _("Date"),
-                            'message_timestamp_class_plain' => '');
+        $col_headers = array(
+            'message_thread' => _("Subject"),
+            'message_thread_class_plain' => 'msgThreadPlain',
+            'message_author' => _("Posted by"),
+            'message_author_class_plain' => 'msgAuthorPlain',
+            'message_timestamp' => _("Date"),
+            'message_timestamp_class_plain' => 'msgTimestampPlain'
+        );
 
         $forums = &Agora_Messages::singleton($scope);
         $forum_id = $forums->getForumId($forum_name);
index 6569478..9cd4918 100644 (file)
@@ -78,12 +78,14 @@ class Agora_ViewComments {
         }
         $html .= '</div>';
 
-        $col_headers = array('message_thread' => _("Subject"),
-                             'message_thread_class_plain' => '',
-                             'message_author' => _("Posted by"),
-                             'message_author_class_plain' => '',
-                             'message_timestamp' => _("Date"),
-                             'message_timestamp_class_plain' => '');
+        $col_headers = array(
+            'message_thread' => _("Subject"),
+            'message_thread_class_plain' => 'msgThreadPlain',
+            'message_author' => _("Posted by"),
+            'message_author_class_plain' => 'msgAuthorPlain',
+            'message_timestamp' => _("Date"),
+            'message_timestamp_class_plain' => 'msgTimestampPlain'
+        );
 
         if ($view_bodies == 1) {
             $threads = $messages->getThreads(0, true, 'message_thread', 0, true, '', $base_url);
index 534687f..3616e6e 100644 (file)
@@ -1395,19 +1395,25 @@ class Agora_Messages {
         /* Render threaded lists with Horde_Tree. */
         $current = key($threads);
         if (!$template_file && isset($threads[$current]['indent'])) {
-            $tree = $GLOBALS['injector']->getInstance('Horde_Tree')->getTree('threads', 'Html');
-            $tree->setOption(array('multiline' => $bodies,
-                                   'lines' => !$bodies));
+            $tree = $GLOBALS['injector']->getInstance('Horde_Tree')->getTree('threads', 'Html', array(
+                'multiline' => $bodies,
+                'lines' => !$bodies
+            ));
+
             $tree->setHeader(array(
-                array('html' => '<strong>' . $col_headers['message_thread'] . '</strong>',
-                      'width' => '50%',
-                      'class' => $col_headers['message_thread_class_plain']),
-                array('html' => '<strong>' . $col_headers['message_author'] . '</strong>',
-                      'width' => '25%',
-                      'class' => $col_headers['message_author_class_plain']),
-                array('html' => '<strong>' . $col_headers['message_timestamp'] . '</strong>',
-                      'width' => '24%',
-                      'class' => $col_headers['message_timestamp_class_plain'])));
+                array(
+                    'class' => $col_headers['message_thread_class_plain'],
+                    'html' => '<strong>' . $col_headers['message_thread'] . '</strong>'
+                ),
+                array(
+                    'class' => $col_headers['message_author_class_plain'],
+                    'html' => '<strong>' . $col_headers['message_author'] . '</strong>'
+                ),
+                array(
+                    'class' => $col_headers['message_timestamp_class_plain'],
+                    'html' => '<strong>' . $col_headers['message_timestamp'] . '</strong>'
+                )
+            ));
 
             foreach ($threads as &$thread) {
                 if ($bodies) {
@@ -1427,15 +1433,20 @@ class Agora_Messages {
                     }
                 }
 
-                $tree->addNode($thread['message_id'],
-                               $thread['parent'],
-                               $text,
-                               $thread['indent'],
-                               true,
-                               array('icon' => '',
-                                     'class' => 'linedRow'),
-                               array($thread['message_author'],
-                                     $thread['message_date']));
+                $tree->addNode(
+                    $thread['message_id'],
+                    $thread['parent'],
+                    $text,
+                    $thread['indent'],
+                    true,
+                    array(
+                        'class' => 'linedRow',
+                    ),
+                    array(
+                        $thread['message_author'],
+                        $thread['message_date']
+                    )
+                );
             }
 
             return $tree->getTree(true);
index 0817131..d887dec 100644 (file)
 .messageBody p {
     padding: 1em;
 }
+
+.msgThreadPlain {
+    width: 50%;
+}
+.msgAuthorPlain {
+    width: 25%;
+}
+.msgTimestampPlain {
+    width: 24%;
+}
index 772cf13..e96c66c 100644 (file)
@@ -79,7 +79,11 @@ class Horde_Core_Perms_Ui
             'alternate' => true,
             'hideHeaders' => true
         ));
-        $tree->setHeader(array(array('width' => '50%')));
+        $tree->setHeader(array(
+            array(
+                'class' => 'treeHdrSpacer'
+            )
+        ));
 
         foreach ($nodes as $perm_id => $node) {
             $node_class = ($current == $perm_id)
index 3b46c64..432a8b5 100644 (file)
@@ -90,6 +90,8 @@ class Horde_Tree_Html extends Horde_Tree
      * <pre>
      * alternate - (boolean) Alternate shading in the table?
      * class - (string) The class to use for the table.
+     * hideHeaders - (boolean) Don't render any HTML for the header row, just
+     *               use the widths.
      * lines - (boolean) Show tree lines?
      * multiline - (boolean) Do the node labels contain linebreaks?
      * </pre>
@@ -147,10 +149,8 @@ class Horde_Tree_Html extends Horde_Tree
      * @param array $header  An array containing hashes with header
      *                       information. The following keys are allowed:
      * <pre>
-     * align - The alignment inside the header cell
      * class - The CSS class of the header cell
      * html - The HTML content of the header cell
-     * width - The width of the header cell
      * </pre>
      */
     public function setHeader($header)
@@ -165,39 +165,31 @@ class Horde_Tree_Html extends Horde_Tree
      */
     protected function _buildHeader()
     {
-        if (!count($this->_header)) {
+        if (!count($this->_header) ||
+            $this->getOption('hideHeaders')) {
             return '';
         }
 
-        $html = '<div';
+        $className = 'treeRowHeader';
+
         /* If using alternating row shading, work out correct
          * shade. */
         if ($this->getOption('alternate')) {
-            $html .= ' class="item' . $this->_alt_count . '"';
+            $className .= ' item' . $this->_alt_count;
             $this->_alt_count = 1 - $this->_alt_count;
         }
-        $html .= '>';
+
+        $html = '<div class="' . $className . '">';
 
         foreach ($this->_header as $header) {
-            $html .= '<div class="leftFloat';
+            $html .= '<span';
             if (!empty($header['class'])) {
-                $html .= ' ' . $header['class'];
+                $html .= ' class="' . $header['class'] . '"';
             }
-            $html .= '"';
 
-            $style = '';
-            if (!empty($header['width'])) {
-                $style .= 'width:' . $header['width'] . ';';
-            }
-            if (!empty($header['align'])) {
-                $style .= 'text-align:' . $header['align'] . ';';
-            }
-            if (!empty($style)) {
-                $html .= ' style="' . $style . '"';
-            }
-            $html .= '>';
-            $html .= empty($header['html']) ? '&nbsp;' : $header['html'];
-            $html .= '</div>';
+            $html .= '>' .
+                (empty($header['html']) ? '&nbsp;' : $header['html'])
+                . '</span>';
         }
 
         return $html . '</div>';
@@ -258,31 +250,13 @@ class Horde_Tree_Html extends Horde_Tree
         if (isset($this->_nodes[$node_id]['extra'][self::EXTRA_LEFT])) {
             $extra = $this->_nodes[$node_id]['extra'][self::EXTRA_LEFT];
             $cMax = count($extra);
-            for ($c = 0; $c < $cMax; ++$c) {
-                $style = '';
-                if (isset($this->_header[$column]['width'])) {
-                    $style .= 'width:' . $this->_header[$column]['width'] . ';';
-                }
-
-                $line .= '<div class="leftFloat"';
-                if (!empty($style)) {
-                    $line .= ' style="' . $style . '"';
-                }
-                $line .= '>' . $extra[$c] . '</div>';
-
+            while ($column < $cMax) {
+                $line .= $this->_addColumn($column) . $extra[$column] . '</span>';
                 $column++;
             }
         }
 
-        $style = '';
-        if (isset($this->_header[$column]['width'])) {
-            $style .= 'width:' . $this->_header[$column]['width'] . ';';
-        }
-        $line .= '<div class="leftFloat"';
-        if (!empty($style)) {
-            $line .= ' style="' . $style . '"';
-        }
-        $line .= '>';
+        $line .= $this->_addColumn($column++);
 
         if ($this->getOption('multiline')) {
             $line .= '<table cellspacing="0"><tr><td>';
@@ -301,24 +275,13 @@ class Horde_Tree_Html extends Horde_Tree
             $line .= '</td></tr></table>';
         }
 
-        $line .= '</div>';
-        ++$column;
+        $line .= '</span>';
 
         if (isset($this->_nodes[$node_id]['extra'][self::EXTRA_RIGHT])) {
             $extra = $this->_nodes[$node_id]['extra'][self::EXTRA_RIGHT];
             $cMax = count($extra);
-            for ($c = 0; $c < $cMax; ++$c) {
-                $style = '';
-                if (isset($this->_header[$column]['width'])) {
-                    $style .= 'width:' . $this->_header[$column]['width'] . ';';
-                }
-
-                $line .= '<div class="leftFloat"';
-                if (!empty($style)) {
-                    $line .= ' style="' . $style . '"';
-                }
-                $line .= '>' . $extra[$c] . '</div>';
-
+            for ($c = 0, $cMax = count($extra); $c < $cMax; ++$c) {
+                $line .= $this->_addColumn($column) . $extra[$c] . '</span>';
                 $column++;
             }
         }
@@ -327,6 +290,17 @@ class Horde_Tree_Html extends Horde_Tree
     }
 
     /**
+     */
+    protected function _addColumn($column)
+    {
+        $line = '<span';
+        if (isset($this->_header[$column]['class'])) {
+            $line .= ' class="' . $this->_header[$column]['class'] . '"';
+        }
+        return $line . '>';
+    }
+
+    /**
      * Sets the label on the tree line.
      *
      * @param string $node_id  The Node ID.
index 87850db..be61651 100644 (file)
@@ -85,36 +85,72 @@ $device_node = array('icon' => strval(Horde_Themes::img('mobile.png')));
 $user_node = array('icon' => strval(Horde_Themes::img('user.png')));
 $users = array();
 
-$tree = $injector->getInstance('Horde_Tree')->getTree('admin_devices', 'Javascript');
-$tree->setOption(array('alternate' => true));
+$tree = $injector->getInstance('Horde_Tree')->getTree('admin_devices', 'Javascript', array(
+    'alternate' => true
+));
+
 $tree->setHeader(array(
-                   array('width' => '30%'),
-                   array('width' => '22%', 'html' => _("Last Sync Time")),
-                   array('html' => $spacer),
-                   array('width' => '6%', 'html' => _("Policy Key")),
-                   array('html' => $spacer),
-                   array('width' => '10%', 'html' => _("Status")),
-                   array('html' => $spacer),
-                   array('width' => '12%' , 'html' => _("Device ID")),
-                   array('html' => $spacer),
-                   array('width' => '10%', 'html' => _("Actions"))
- ));
+    array(
+        'class' => 'activesyncHdr1'
+    ),
+    array(
+        'class' => 'activesyncHdr2',
+        'html' => _("Last Sync Time")
+    ),
+    array(
+        'html' => $spacer
+    ),
+    array(
+        'class' => 'activesyncHdr3',
+        'html' => _("Policy Key")
+    ),
+    array(
+        'html' => $spacer
+    ),
+    array(
+        'class' => 'activesyncHdr4',
+        'html' => _("Status")
+    ),
+    array(
+        'html' => $spacer
+    ),
+    array(
+        'class' => 'activesyncHdr5',
+        'html' => _("Device ID")
+    ),
+    array(
+        'html' => $spacer
+    ),
+    array(
+        'class' => 'activesyncHdr6',
+        'html' => _("Actions")
+    )
+));
 
 /* Root tree node, and reprovision button */
-$tree->addNode('root',
-               null,
-               _("Registered User Devices"),
-               0,
-               true,
-               $base_node_params,
-               array('--', $spacer, '--', $spacer, '--', $spacer, '--', $spacer, '<input class="button" type="button" value="' . _("Reprovision All Devices") . '" id="reset" />' ));
+$tree->addNode(
+    'root',
+    null,
+    _("Registered User Devices"),
+    0,
+    true,
+    $base_node_params,
+    array('--', $spacer, '--', $spacer, '--', $spacer, '--', $spacer, '<input class="button" type="button" value="' . _("Reprovision All Devices") . '" id="reset" />' )
+);
 
 /* Build the device entry */
 foreach ($devices as $key => $device) {
     $node_params = array();
     if (array_search($device['device_user'], $users) === false) {
         $users[] = $device['device_user'];
-        $tree->addNode($device['device_user'], 'root', $device['device_user'], 0, false, $user_node);
+        $tree->addNode(
+            $device['device_user'],
+            'root',
+            $device['device_user'],
+            0,
+            false,
+            $user_node
+        );
     }
 
     /* Load this device */
@@ -149,13 +185,15 @@ foreach ($devices as $key => $device) {
     $actions .= '&nbsp;<input class="button removeDevice" type="button" value="' . _("Remove") . '" id="remove_' . $key . '" />';
 
     /* Add it */
-    $tree->addNode($device['device_id'],
-                   $device['device_user'],
-                   $device['device_type']. ' | ' . $device['device_agent'],
-                   0,
-                   true,
-                   $device_node + $node_params,
-                   array($ts->format('r'), $spacer, $device['device_policykey'], $spacer, $status, $spacer, $device['device_id'], $spacer, $actions));
+    $tree->addNode(
+        $device['device_id'],
+        $device['device_user'],
+        $device['device_type']. ' | ' . $device['device_agent'],
+        0,
+        true,
+        $device_node + $node_params,
+        array($ts->format('r'), $spacer, $device['device_policykey'], $spacer, $status, $spacer, $device['device_id'], $spacer, $actions)
+    );
 }
 
 echo '<h1 class="header">' . Horde::img('group.png') . ' ' . _("ActiveSync Devices") . '</h1>';
index dba7124..c8205b1 100644 (file)
@@ -214,9 +214,15 @@ $edit_img = Horde::img('edit.png', _("Edit Group"));
 $delete_img = Horde::img('delete.png', _("Delete Group"));
 
 /* Set up the tree. */
-$tree = $injector->getInstance('Horde_Tree')->getTree('admin_groups', 'Javascript');
-$tree->setOption(array('alternate' => true, 'hideHeaders' => true));
-$tree->setHeader(array(array('width' => '50%')));
+$tree = $injector->getInstance('Horde_Tree')->getTree('admin_groups', 'Javascript', array(
+    'alternate' => true,
+    'hideHeaders' => true
+));
+$tree->setHeader(array(
+    array(
+        'class' => 'treeHdrSpacer'
+    )
+));
 
 /* Explicitly check for > 0 since we can be called with current = -1
  * for the root node. */
@@ -226,20 +232,35 @@ if ($cid > 0) {
 
 foreach ($nodes as $id => $node) {
     $node_params = ($cid == $id) ? array('class' => 'selected') : array();
+
     if ($id == Horde_Group::ROOT) {
         $add_link = Horde::link(Horde_Util::addParameter($add, 'cid', $id), _("Add a new group")) . $add_img . '</a>';
 
         $base_node_params = array('icon' => strval(Horde_Themes::img('administration.png')));
-        $tree->addNode($id, null, _("All Groups"), 0, true, $base_node_params + $node_params, array($spacer, $add_link));
+        $tree->addNode(
+            $id,
+            null,
+            _("All Groups"),
+            0,
+            true,
+            $base_node_params + $node_params,
+            array($spacer, $add_link)
+        );
     } else {
         $name = $groups->getGroupShortName($node);
         $node_params['url'] = Horde_Util::addParameter($edit, 'cid', $id);
         $add_link = Horde::link(Horde_Util::addParameter($add, 'cid', $id), sprintf(_("Add a child group to \"%s\""), $name)) . $add_img . '</a>';
         $delete_link = Horde::link(Horde_Util::addParameter($delete, 'cid', $id), sprintf(_("Delete \"%s\""), $name)) . $delete_img . '</a>';
 
-        $parent_id = $groups->getGroupParent($id);
-        $group_extra = array($spacer, $add_link, $delete_link);
-        $tree->addNode($id, $parent_id, $groups->getGroupShortName($node), $groups->getLevel($id) + 1, (isset($cid_parents[$id])), $group_node + $node_params, $group_extra);
+        $tree->addNode(
+            $id,
+            $groups->getGroupParent($id),
+            $groups->getGroupShortName($node),
+            $groups->getLevel($id) + 1,
+            (isset($cid_parents[$id])),
+            $group_node + $node_params,
+            array($spacer, $add_link, $delete_link)
+        );
     }
 }
 
index 320c1c9..bc47916 100644 (file)
@@ -67,20 +67,12 @@ var Horde_Tree = Class.create({
         var div = new Element('DIV');
 
         this.opts.header.each(function(h) {
-            var tmp = new Element('DIV').insert(h.html ? h.html : '&nbsp;');
+            var tmp = new Element('SPAN').insert(h.html ? h.html : '&nbsp;');
 
             if (h['class']) {
                 tmp.addClassName(h['class']);
             }
 
-            if (h.width) {
-                tmp.setStyle({ width: h.width });
-            }
-
-            if (h.align) {
-                tmp.setStyle({ textAlign: h.align });
-            }
-
             div.appendChild(tmp);
         }, this);
 
@@ -125,15 +117,15 @@ var Horde_Tree = Class.create({
         // any given cell of content.
         if (node.extra && node.extra[0]) {
             node.extra[0].each(function(n) {
-                div.insert(this._divWidth(new Element('DIV').update(n), column++));
+                div.insert(this._divClass(new Element('SPAN').update(n), column++));
             }, this);
         }
 
         for (; column < this.opts.extraColsLeft; ++column) {
-            div.insert(this._divWidth(new Element('DIV').update('&nbsp;'), column));
+            div.insert(this._divClass(new Element('SPAN').update('&nbsp;'), column));
         }
 
-        div.insert(this._divWidth(new Element('DIV'), column));
+        div.insert(this._divClass(new Element('SPAN'), column));
 
         tmp = document.createDocumentFragment();
         for (i = Number(this.renderStatic); i < node.indent; ++i) {
@@ -199,22 +191,24 @@ var Horde_Tree = Class.create({
 
         if (node.extra && node.extra[1]) {
             node.extra[1].each(function(n) {
-                div.insert(this._divWidth(new Element('DIV').update(n), column++));
+                div.insert(this._divClass(new Element('SPAN').update(n), column++));
             }, this);
         }
 
         for (; column < this.opts.extraColsRight; ++column) {
-            div.insert(this._divWidth(new Element('DIV').update('&nbsp;'), column));
+            div.insert(this._divClass(new Element('SPAN').update('&nbsp;'), column));
         }
 
         p.appendChild(div);
     },
 
-    _divWidth: function(div, c)
+    _divClass: function(div, c)
     {
-        if (this.opts.header[c] && this.opts.header[c]['width']) {
-            c.setStyle({ width: this.opts.header[c].width });
+        if (this.opts.header[c] && this.opts.header[c]['class']) {
+            c.addClassName(this.opts.header[c]['class']);
         }
+
+        return div;
     },
 
     _setNodeToggle: function(nodeId)
index 335f5e8..5090517 100644 (file)
@@ -395,6 +395,10 @@ div.nicetitle {
     cursor: pointer;
 }
 
+.treeHdrSpacer {
+    width: 50%;
+}
+
 span.treeImg {
     height: 20px;
     width: 20px;
@@ -977,6 +981,27 @@ ul.sound-list {
     float: right;
 }
 
+/* Activesync styles. */
+.activesyncHdr1 {
+    width: 30%;
+}
+.activesyncHdr2 {
+    width: 22%;
+}
+.activesyncHdr3 {
+    width: 6%;
+}
+.activesyncHdr4 {
+    width: 10%;
+}
+.activesyncHdr5 {
+    width: 12%;
+}
+.activesyncHdr6 {
+    width: 10%;
+}
+
+/* Toggle quote styles. */
 .toggleQuoteHide, .toggleQuoteShow {
     font-size: 80%;
     cursor: pointer;