* @param array $params @see parent::__construct(). Additional options:
* <pre>
* 'jsvar' - The JS variable name to store the tree object in.
- * DEFAULT: $_instance
+ * DEFAULT: Instance name.
* </pre>
*/
public function __construct($name, array $params = array())
Horde::addScriptFile('hordetree.js', 'horde');
/* Check for a javascript session state. */
- if (!empty($this->_options['session']) &&
+ if (($session = $this->getOption('session')) &&
isset($_COOKIE[$this->_instance . '_expanded'])) {
/* Remove "exp" prefix from cookie value. */
$nodes = explode(',', substr($_COOKIE[$this->_instance . '_expanded'], 3));
/* Save nodes to the session. */
- $_SESSION[$this->_options['session']][$this->_instance]['expanded'] = array_combine(
+ $_SESSION[$session][$this->_instance]['expanded'] = array_combine(
$nodes,
array_fill(0, count($nodes), true)
);
'initTree' => $this->renderNodeDefinitions()
);
- $js_var = empty($this->_options['jsvar'])
- ? $this->_instance
- : $this->_options['jsvar'];
+ if (!($js_var = $this->getOption('jsvar'))) {
+ $js_var = $this->_instance;
+ }
Horde::addInlineScript(array(
'window.' . $js_var . ' = new Horde_Tree(' . Horde_Serialize::serialize($opts, Horde_Serialize::JSON, $GLOBALS['registry']->getCharset()) . ')'
/**
* Returns just the JS node definitions as a string.
*
- * @return array The following keys: 'is_static', 'nodes', 'root_nodes'.
+ * @return object Object with the following properties: 'is_static',
+ * 'nodes', 'root_nodes'.
*/
public function renderNodeDefinitions()
{
$this->_buildIndents($this->_root_nodes);
- return array(
- 'is_static' => intval($this->_static),
- 'nodes' => $this->_nodes,
- 'root_nodes' => $this->_root_nodes
- );
+ $result = new stdClass;
+ $result->is_static = intval($this->_static);
+ $result->nodes = $this->_nodes;
+ $result->root_nodes = $this->_root_nodes;
+
+ return $result;
}
}
/**
* AJAX action: Update sidebar.
*
- * @return stdClass An object with the following entries:
- * <pre>
- * 'is_static'
- * 'nodes'
- * 'root_nodes'
- * </pre>
+ * @return object See Horde_Tree_Javascript#renderNodeDefinitions().
*/
public function sidebarUpdate()
{
$sidebar = new Horde_Ui_Sidebar();
- $tree = $sidebar->getTree();
-
- $defs = $tree->renderNodeDefinitions();
-
- $result = new stdClass;
- $result->is_static = $defs['is_static'];
- $result->nodes = $defs['nodes'];
- $result->root_nodes = $defs['root_nodes'];
-
- return $result;
+ return $sidebar->getTree()->renderNodeDefinitions();
}
}