Allow sidebar tree object to be stored in configurable js variable
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 15 Jul 2010 22:48:15 +0000 (16:48 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 15 Jul 2010 22:48:15 +0000 (16:48 -0600)
framework/Core/lib/Horde/Core/Tree/Javascript.php
horde/lib/Ui/Sidebar.php

index e022ed4..986e3cf 100644 (file)
@@ -20,7 +20,11 @@ class Horde_Core_Tree_Javascript extends Horde_Core_Tree_Html
      * Constructor.
      *
      * @param string $name   @see parent::__construct().
-     * @param array $params  @see parent::__construct().
+     * @param array $params  @see parent::__construct(). Additional options:
+     * <pre>
+     * 'jsvar' - The JS variable name to store the tree object in.
+     *           DEFAULT: $_instance
+     * </pre>
      */
     public function __construct($name, array $params = array())
     {
@@ -97,8 +101,12 @@ class Horde_Core_Tree_Javascript extends Horde_Core_Tree_Html
             'initTree' => $this->renderNodeDefinitions()
         );
 
+        $js_var = empty($this->_options['jsvar'])
+            ? $this->_instance
+            : $this->_options['jsvar'];
+
         Horde::addInlineScript(array(
-            'window.' . $this->_instance . ' = new Horde_Tree(' . Horde_Serialize::serialize($opts, Horde_Serialize::JSON, $GLOBALS['registry']->getCharset()) . ')'
+            'window.' . $js_var . ' = new Horde_Tree(' . Horde_Serialize::serialize($opts, Horde_Serialize::JSON, $GLOBALS['registry']->getCharset()) . ')'
         ), 'dom');
 
         return '<div id="' . $this->_instance . '"></div>';
index 2600d33..62a1750 100644 (file)
@@ -191,7 +191,7 @@ class Horde_Ui_Sidebar
         }
 
         // Set up the tree.
-        $tree = $injector->getInstance('Horde_Tree')->getTree('HordeSidebar.tree', 'Javascript');
+        $tree = $injector->getInstance('Horde_Tree')->getTree('horde_sidebar', 'Javascript', array('jsvar' => 'HordeSidebar.tree'));
 
         foreach ($menu as $app => $params) {
             if ($params['status'] == 'block') {