Allow session storage to be disabled for a given Horde_Tree instance
authorMichael M Slusarz <slusarz@curecanti.org>
Sat, 28 Aug 2010 22:20:29 +0000 (16:20 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Sat, 28 Aug 2010 22:20:29 +0000 (16:20 -0600)
framework/Core/lib/Horde/Core/Factory/Tree.php
framework/Core/lib/Horde/Core/Tree/Javascript.php
horde/js/hordetree.js

index 2a0fd98..a8a94dc 100644 (file)
@@ -57,7 +57,11 @@ class Horde_Core_Factory_Tree
      * @param string $name     The name of this tree instance.
      * @param mixed $renderer  The type of tree renderer.
      * @param array $params    Any additional parameters the constructor
-     *                         needs.
+     *                         needs. Defined by this class:
+     * <pre>
+     * 'nosession' - (boolean) Don't store tree state in the session.
+     *               DEFAULT: false
+     * </pre>
      *
      * @return Horde_Tree_Base  The singleton instance.
      * @throws Horde_Tree_Exception
@@ -82,7 +86,9 @@ class Horde_Core_Factory_Tree
                 break;
             }
 
-            $params['session'] = 'horde_tree';
+            if (empty($params['nosession'])) {
+                $params['session'] = 'horde_tree';
+            }
 
             $this->_instances[$id] = Horde_Tree::factory($name, $renderer, $params);
         }
index e02757b..18e3856 100644 (file)
@@ -73,6 +73,7 @@ class Horde_Core_Tree_Javascript extends Horde_Core_Tree_Html
             'extraColsLeft' => $this->_colsLeft,
             'extraColsRight' => $this->_colsRight,
             'header' => $this->_header,
+            'nocookie' => !$this->getOption('session'),
             'options' => $this->_options,
             'target' => $this->_instance,
 
index 53de092..3659e62 100644 (file)
@@ -442,6 +442,10 @@ var Horde_Tree = Class.create({
 
     saveState: function(nodeId, expanded)
     {
+        if (this.opts.nocookie) {
+            return;
+        }
+
         var newCookie = '',
             newNodes = [],
             oldCookie = this._getCookie(this.opts.target + '_expanded');
@@ -459,7 +463,7 @@ var Horde_Tree = Class.create({
             newCookie = newNodes.join(',');
         }
 
-        this._setCookie(this.opts.target + '_expanded', newCookie);
+        document.cookie = this.opts.target + '_expanded=exp' + escape(newCookie) + ';DOMAIN=' + this.opts.cookieDomain + ';PATH=' + this.opts.cookiePath + ';';
     },
 
     _getCookie: function(name)
@@ -486,10 +490,6 @@ var Horde_Tree = Class.create({
         return unescape(dc.substring(begin + prefix.length, end));
     },
 
-    _setCookie: function(name, value)
-    {
-        document.cookie = name + '=exp' + escape(value) + ';DOMAIN=' + this.opts.cookieDomain + ';PATH=' + this.opts.cookiePath + ';';
-    },
     _onClick: function(e)
     {
         var elt = e.element(),