Add 'lines_base' option
authorMichael M Slusarz <slusarz@curecanti.org>
Mon, 23 Aug 2010 23:54:16 +0000 (17:54 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 24 Aug 2010 06:00:58 +0000 (00:00 -0600)
framework/Core/lib/Horde/Core/Tree/Html.php
framework/Core/lib/Horde/Core/Tree/Javascript.php
framework/Tree/lib/Horde/Tree/Html.php
horde/js/hordetree.js

index 13b006d..7930628 100644 (file)
@@ -26,6 +26,7 @@ class Horde_Core_Tree_Html extends Horde_Tree_Html
         'blank' => '',
         'join' => 2,
         'join_bottom' => 4,
+        'join_top' => 3,
         'plus' => 10,
         'plus_bottom' => 11,
         'plus_only' => 12,
index c743ba7..c842302 100644 (file)
@@ -87,6 +87,7 @@ class Horde_Core_Tree_Javascript extends Horde_Core_Tree_Html
             'imgLine' => $this->_images['line'],
             'imgJoin' => $this->_images['join'],
             'imgJoinBottom' => $this->_images['join_bottom'],
+            'imgJoinTop' => $this->_images['join_top'],
             'imgPlus' => $this->_images['plus'],
             'imgPlusBottom' => $this->_images['plus_bottom'],
             'imgPlusOnly' => $this->_images['plus_only'],
index 29653ab..78243a8 100644 (file)
@@ -70,6 +70,7 @@ class Horde_Tree_Html extends Horde_Tree
         'blank' => null,
         'join' => null,
         'join_bottom' => null,
+        'join_top' => null,
         'plus' => null,
         'plus_bottom' => null,
         'plus_only' => null,
@@ -275,7 +276,7 @@ class Horde_Tree_Html extends Horde_Tree
         }
 
         for ($i = intval($this->_static); $i < $this->_nodes[$node_id]['indent']; ++$i) {
-            $line .= $this->_generateImage(($this->_dropline[$i] && $this->getOption('lines', false, true)) ? $this->_images['line'] : $this->_images['blank']);
+            $line .= $this->_generateImage(($this->_dropline[$i] && $this->getOption('lines')) ? $this->_images['line'] : $this->_images['blank']);
         }
         $line .= $this->_setNodeToggle($node_id) . $this->_setNodeIcon($node_id);
         if ($this->getOption('multiline')) {
@@ -356,46 +357,81 @@ class Horde_Tree_Html extends Horde_Tree
     {
         $link_start = '';
 
-        if (($this->_nodes[$node_id]['indent'] == 0) &&
-            isset($this->_nodes[$node_id]['children'])) {
-            /* Top level node with children. */
+        /* Top level node. */
+        if ($this->_nodes[$node_id]['indent'] == 0) {
             $this->_dropline[0] = false;
+
             if ($this->_static) {
                 return '';
-            } elseif (!$this->getOption('lines', false, true)) {
-                $img = $this->_images['blank'];
-            } elseif ($this->_nodes[$node_id]['expanded']) {
-                $img = $this->_images['minus_only'];
-            } else {
-                $img = $this->_images['plus_only'];
             }
 
-            if (!$this->_static) {
-                $link_start = $this->_generateUrlTag($node_id);
+            /* KEY:
+             * 0: Only node
+             * 1: Top node
+             * 2: Middle node
+             * 3: Bottom node */
+            $node_type = 0;
+            if ($this->getOption('lines_base') &&
+                (count($this->_root_nodes) > 1)) {
+                switch (array_search($node_id, $this->_root_nodes)) {
+                case 0:
+                    $node_type = 1;
+                    $this->_dropline[0] = true;
+                    break;
+
+                case (count($this->_root_nodes) - 1):
+                    $node_type = 3;
+                    break;
+
+                default:
+                    $node_type = 2;
+                    $this->_dropline[0] = true;
+                    break;
+                }
             }
-        } elseif (($this->_nodes[$node_id]['indent'] != 0) &&
-            !isset($this->_nodes[$node_id]['children'])) {
-            /* Node without children. */
-            if ($this->_node_pos[$node_id]['pos'] < $this->_node_pos[$node_id]['count']) {
-                /* Not last node. */
-                $img = $this->getOption('lines', false, true)
-                    ? $this->_images['join']
-                    : $this->_images['blank'];
 
-                $this->_dropline[$this->_nodes[$node_id]['indent']] = true;
-            } else {
-                /* Last node. */
-                $img = $this->getOption('lines', false, true)
-                    ? $this->_images['join_bottom']
-                    : $this->_images['blank'];
+            if (isset($this->_nodes[$node_id]['children'])) {
+                if (!$this->getOption('lines')) {
+                    $img = $this->_images['blank'];
+                } elseif ($this->_nodes[$node_id]['expanded']) {
+                    $img = $node_type
+                        ? (($node_type == 2) ? $this->_images['minus'] : $this->_images['minus_bottom'])
+                        : $this->_images['minus_only'];
+                } else {
+                    $img = $node_type
+                        ? (($node_type == 2) ? $this->_images['plus'] : $this->_images['plus_bottom'])
+                        : $this->_images['plus_only'];
+                }
 
-                $this->_dropline[$this->_nodes[$node_id]['indent']] = false;
+                $link_start = $this->_generateUrlTag($node_id);
+            } else {
+                if ($this->getOption('lines')) {
+                    switch ($node_type) {
+                    case 0:
+                        $img = $this->_images['null_only'];
+                        break;
+
+                    case 1:
+                        $img = $this->_images['join_top'];
+                        break;
+
+                    case 2:
+                        $img = $this->_images['join'];
+                        break;
+
+                    case 3:
+                        $img = $this->_images['join_bottom'];
+                        break;
+                    }
+                } else {
+                    $img = $this->_images['blank'];
+                }
             }
         } elseif (isset($this->_nodes[$node_id]['children'])) {
             /* Node with children. */
             if ($this->_node_pos[$node_id]['pos'] < $this->_node_pos[$node_id]['count']) {
                 /* Not last node. */
-                if (!$this->getOption('lines', false, true)) {
+                if (!$this->getOption('lines')) {
                     $img = $this->_images['blank'];
                 } elseif ($this->_static) {
                     $img = $this->_images['join'];
@@ -407,7 +443,7 @@ class Horde_Tree_Html extends Horde_Tree
                 $this->_dropline[$this->_nodes[$node_id]['indent']] = true;
             } else {
                 /* Last node. */
-                if (!$this->getOption('lines', false, true)) {
+                if (!$this->getOption('lines')) {
                     $img = $this->_images['blank'];
                 } elseif ($this->_static) {
                     $img = $this->_images['join_bottom'];
@@ -423,16 +459,22 @@ class Horde_Tree_Html extends Horde_Tree
                 $link_start = $this->_generateUrlTag($node_id);
             }
         } else {
-            /* Top level node with no children. */
-            if ($this->_static) {
-                return '';
-            }
+            /* Node without children. */
+            if ($this->_node_pos[$node_id]['pos'] < $this->_node_pos[$node_id]['count']) {
+                /* Not last node. */
+                $img = $this->getOption('lines')
+                    ? $this->_images['join']
+                    : $this->_images['blank'];
 
-            $img = $this->getOption('lines', false, true)
-                ? $this->_images['null_only']
-                : $this->_images['blank'];
+                $this->_dropline[$this->_nodes[$node_id]['indent']] = true;
+            } else {
+                /* Last node. */
+                $img = $this->getOption('lines')
+                    ? $this->_images['join_bottom']
+                    : $this->_images['blank'];
 
-            $this->_dropline[0] = false;
+                $this->_dropline[$this->_nodes[$node_id]['indent']] = false;
+            }
         }
 
         return $link_start .
index bc47916..9384b7f 100644 (file)
@@ -215,23 +215,22 @@ var Horde_Tree = Class.create({
     {
         var node = this.nodes[nodeId];
 
-        if (node.indent == '0' && node.children) {
+        if (node.indent == '0') {
             // Top level with children.
             this.dropline[0] = false;
+
             if (this.renderStatic) {
                 return '';
             }
-        } else if (node.indent != '0' && !node.children) {
-            // Node no children.
-            this.dropline[node.indent] = (this.node_pos[nodeId].pos < this.node_pos[nodeId].count);
-        } else if (node.children) {
-            this.dropline[node.indent] = (this.node_pos[nodeId].pos < this.node_pos[nodeId].count);
-        } else {
-            // Top level node with no children.
-            if (this.renderStatic) {
-                return '';
+
+            switch (this._getLineType(nodeId)) {
+            case 1:
+            case 2:
+                this.dropline[0] = true;
+                break;
             }
-            this.dropline[0] = false;
+        } else {
+            this.dropline[node.indent] = (this.node_pos[nodeId].pos < this.node_pos[nodeId].count);
         }
 
         return new Element('SPAN', { id: "nodeToggle_" + nodeId }).addClassName('treeToggle').addClassName('treeImg').addClassName('treeImg' + this._getNodeToggle(nodeId));
@@ -239,34 +238,46 @@ var Horde_Tree = Class.create({
 
     _getNodeToggle: function(nodeId)
     {
-        var node = this.nodes[nodeId];
+        var type,
+            node = this.nodes[nodeId];
 
-        if (node.indent == '0' && node.children) {
-            // Top level with children.
+        if (node.indent == '0') {
             if (this.renderStatic) {
                 return '';
-            } else if (!this.opts.options.lines) {
+            }
+
+            if (!this.opts.options.lines) {
                 return this.opts.imgBlank;
-            } else if (node.expanded) {
-                return this.opts.imgMinusOnly;
             }
 
-            return this.opts.imgPlusOnly;
-        }
+            type = this._getLineType(nodeId);
 
-        if (node.indent != '0' && !node.children) {
-            // Node no children.
-            if (this.node_pos[nodeId].pos < this.node_pos[nodeId].count) {
-                // Not last node.
-                return this.opts.options.lines
-                    ? this.opts.imgJoin
-                    : this.opts.imgBlank;
+            if (node.children) {
+                // Top level with children.
+                if (node.expanded) {
+                    return type
+                        ? ((type == 2) ? this.opts.imgMinus : this.opts.imgMinusBottom)
+                        : this.opts.imgMinusOnly;
+                }
+
+                return type
+                    ? ((type == 2) ? this.opts.imgPlus : this.opts.imgPlusBottom)
+                    : this.opts.imgPlusOnly;
             }
 
-            // Last node.
-            return this.opts.options.lines
-                ? this.opts.imgJoinBottom
-                : this.opts.imgBlank;
+            switch (type) {
+            case 0:
+                return this.opts.imgNullOnly;
+
+            case 1:
+                return this.opts.imgJoinTop;
+
+            case 2:
+                return this.opts.imgJoin;
+
+            case 3:
+                return this.opts.imgJoinBottom;
+            }
         }
 
         if (node.children) {
@@ -296,16 +307,39 @@ var Horde_Tree = Class.create({
             return this.opts.imgPlusBottom;
         }
 
-        // Top level node with no children.
-        if (this.renderStatic) {
-            return '';
+        // Node no children.
+        if (this.node_pos[nodeId].pos < this.node_pos[nodeId].count) {
+            // Not last node.
+            return this.opts.options.lines
+                ? this.opts.imgJoin
+                : this.opts.imgBlank;
         }
 
+        // Last node.
         return this.opts.options.lines
-            ? this.opts.imgNullOnly
+            ? this.opts.imgJoinBottom
             : this.opts.imgBlank;
     },
 
+    _getLineType: function(nodeId)
+    {
+        if (this.opts.options.lines_base &&
+            this.rootNodes.size() > 1) {
+            switch (this.rootNodes.indexOf(nodeId)) {
+            case 0:
+                return 1;
+
+            case (this.rootNodes.size() - 1):
+                return 3;
+
+            default:
+                return 2;
+            }
+        }
+
+        return 0;
+    },
+
     _setNodeIcon: function(nodeId)
     {
         var img,