2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
7 * This program is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU Affero General Public License version 3 as published by the
9 * Free Software Foundation with the addition of the following permission added
10 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
19 * You should have received a copy of the GNU Affero General Public License along with
20 * this program; if not, see http://www.gnu.org/licenses or write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
27 * The interactive user interfaces in modified source and object code versions
28 * of this program must display Appropriate Legal Notices, as required under
29 * Section 5 of the GNU Affero General Public License version 3.
31 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32 * these Appropriate Legal Notices must retain the display of the "Powered by
33 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34 * technical reasons, the Appropriate Legal Notices must display the words
35 * "Powered by SugarCRM".
36 ********************************************************************************/
38 /*usage: initialize the tree, add nodes, generate header for required files inclusion.
39 * generate function that has tree data and script to convert data into tree init.
40 * generate call to tree init function.
41 * subsequent tree data calls will be served by the node class.
42 * tree view by default make ajax based calls for all requests.
44 //require_once('include/entryPoint.php');
46 require_once ('include/ytree/Tree.php');
47 require_once ('include/JSON.php');
50 var $tree_style='include/ytree/TreeView/css/folders/tree.css';
51 var $_header_files=array(
52 'include/javascript/yui/build/treeview/treeview.js',
53 'include/ytree/treeutil.js',
57 var $_debug_window=false;
58 var $_debug_div_name='debug_tree';
62 //collection of parmeter properties;
65 function Tree($name) {
67 $this->json=new JSON(JSON_LOOSE_TYPE);
70 //optionally add json.js, required for making AJAX Calls.
71 function include_json_reference($reference=null) {
72 if (empty($reference)) {
73 $this->_header_files[]='include/JSON.js';
75 $this->_header_files[]=$reference;
79 function add_node($node) {
80 $this->_nodes[$node->uid]=$node;
83 // returns html for including necessary javascript files.
84 function generate_header() {
85 $ret="<link rel='stylesheet' href='{$this->tree_style}'>\n";
86 foreach ($this->_header_files as $filename) {
87 $ret.="<script language='JavaScript' src='" . getJSPath($filename) . "'></script>\n";
92 //properties set here will be accessible from
93 //the tree's name space..
94 function set_param($name, $value) {
95 if (!empty($name) && !empty($value)) {
96 $this->_params[$name]=$value;
100 function generate_nodes_array($scriptTags = true) {
101 global $sugar_config;
104 foreach ($this->_nodes as $node ) {
105 $ret['nodes'][]=$node->get_definition();
108 //todo removed site_url setting from here.
109 //todo make these variables unique.
110 $tree_data="var TREE_DATA= " . $this->json->encode($ret) . ";\n";
111 $tree_data.="var param= " . $this->json->encode($this->_params) . ";\n";
113 $tree_data.="var mytree;\n";
114 $tree_data.="treeinit(mytree,TREE_DATA,'{$this->_name}',param);\n";
115 if($scriptTags) return '<script>'.$tree_data.'</script>';
116 else return $tree_data;
121 * Generates the javascript node arrays without calling treeinit(). Also generates a callback function that can be
122 * easily called to instatiate the treeview object onload().
124 * IE6/7 will throw an "Operation Aborted" error when calling certain types of scripts before the page is fully
125 * loaded. The workaround is to move the init() call to the onload handler. See: http://www.viavirtualearth.
126 * com/wiki/DeferScript.ashx
128 * @param bool insertScriptTags Flag to add <script> tags
129 * @param string customInitFunction Defaults to "onloadTreeInit"
132 function generateNodesNoInit($insertScriptTags=true, $customInitFunction="") {
136 $initFunction = (empty($customInitFunction)) ? 'treeinit' : $customInitFunction;
138 foreach($this->_nodes as $node) {
139 $ret['nodes'][] = $node->get_definition();
142 $treeData = "var TREE_DATA = ".$this->json->encode($ret).";\n";
143 $treeData .= "var param = ".$this->json->encode($this->_params).";\n";
144 $treeData .= "var mytree;\n";
145 $treeData .= "function onloadTreeinit() { {$initFunction}(mytree,TREE_DATA,'{$this->_name}',param); }\n";
147 if($insertScriptTags) {
148 $treeData = "<script type='text/javascript' language='javascript'>{$treeData}</script>";
154 function generateNodesRaw() {
159 foreach($this->_nodes as $node) {
160 $ret['nodes'][] = $node->get_definition();
163 $return['tree_data'] = $ret;
164 $return['param'] = $this->_params;