_name=$name; $this->json=new JSON(JSON_LOOSE_TYPE); } //optionally add json.js, required for making AJAX Calls. function include_json_reference($reference=null) { // if (empty($reference)) { // $this->_header_files[]='include/JSON.js'; // } else { // $this->_header_files[]=$reference; // } } function add_node($node) { $this->_nodes[$node->uid]=$node; } // returns html for including necessary javascript files. function generate_header() { $ret="\n"; foreach ($this->_header_files as $filename) { $ret.="\n"; } return $ret; } //properties set here will be accessible from //the tree's name space.. function set_param($name, $value) { if (!empty($name) && !empty($value)) { $this->_params[$name]=$value; } } function generate_nodes_array($scriptTags = true) { global $sugar_config; $node=null; $ret=array(); foreach ($this->_nodes as $node ) { $ret['nodes'][]=$node->get_definition(); } //todo removed site_url setting from here. //todo make these variables unique. $tree_data="var TREE_DATA= " . $this->json->encode($ret) . ";\n"; $tree_data.="var param= " . $this->json->encode($this->_params) . ";\n"; $tree_data.="var mytree;\n"; $tree_data.="treeinit(mytree,TREE_DATA,'{$this->_name}',param);\n"; if($scriptTags) return ''; else return $tree_data; } /** * Generates the javascript node arrays without calling treeinit(). Also generates a callback function that can be * easily called to instatiate the treeview object onload(). * * IE6/7 will throw an "Operation Aborted" error when calling certain types of scripts before the page is fully * loaded. The workaround is to move the init() call to the onload handler. See: http://www.viavirtualearth. * com/wiki/DeferScript.ashx * * @param bool insertScriptTags Flag to add "; } return $treeData; } function generateNodesRaw() { $node = null; $ret = array(); $return = array(); foreach($this->_nodes as $node) { $ret['nodes'][] = $node->get_definition(); } $return['tree_data'] = $ret; $return['param'] = $this->_params; return $return; } } ?>