tree.js 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654
  1. /*##############################################################################
  2. # HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. ############################################################################## */
  16. //--------------------------------------
  17. // All browser specific code goes here
  18. function createXmlHttpRequestObject()
  19. {
  20. var xmlhttp = null;
  21. // code for Mozilla, etc.
  22. if (window.XMLHttpRequest) {
  23. xmlhttp=new XMLHttpRequest();
  24. }
  25. // code for IE
  26. else if (window.ActiveXObject) {
  27. try {
  28. xmlhttp=new ActiveXObject("Msxml2.XMLHTTP.4.0");
  29. } catch (e) {
  30. try {
  31. xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
  32. } catch (e) {
  33. xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  34. }
  35. }
  36. }
  37. if (xmlhttp == null)
  38. alert("Can not create XMLHttpRequest object in your browser!");
  39. return xmlhttp;
  40. }
  41. get_element = function(s_id) { return document.all ? document.all[s_id] : document.getElementById(s_id) };
  42. function createXmlDomObject()
  43. {
  44. var xmlDom = null;
  45. if (window.ActiveXObject) {
  46. xmlDom = new ActiveXObject("Microsoft.XMLDOM");
  47. } else if (document.implementation && document.implementation.createDocument) {
  48. xmlDom = document.implementation.createDocument("","",null);
  49. }
  50. if (xmlDom == null)
  51. alert("Can not create XML DOM object in your browser!");
  52. return xmlDom;
  53. }
  54. // emulate IE selectNodes(), selectSingleNode()
  55. if(document.implementation && document.implementation.hasFeature("XPath", "3.0"))
  56. {
  57. // NodeList
  58. function XmlNodeList(i) {
  59. this.length = i;
  60. }
  61. XmlNodeList.prototype = new Array(0);
  62. XmlNodeList.prototype.constructor = Array;
  63. XmlNodeList.prototype.item = function(i) {
  64. return (i < 0 || i >= this.length)?null:this[i];
  65. };
  66. XmlNodeList.prototype.expr = "";
  67. XMLDocument.prototype.setProperty = function(x,y){};
  68. // IE: XMLDocument.selectNodes()
  69. XMLDocument.prototype.selectNodes = function(sExpr, contextNode){
  70. var nsDoc = this;
  71. var nsResolver = this.createNSResolver(this.documentElement);
  72. var oResult = this.evaluate(sExpr,
  73. (contextNode?contextNode:this),
  74. nsResolver,
  75. XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  76. var nodeList = new XmlNodeList(oResult.snapshotLength);
  77. nodeList.expr = sExpr;
  78. for(var i=0;i<nodeList.length;i++)
  79. nodeList[i] = oResult.snapshotItem(i);
  80. return nodeList;
  81. }
  82. // IE: Element.selectNodes()
  83. Element.prototype.selectNodes = function(sExpr){
  84. var doc = this.ownerDocument;
  85. if(doc.selectNodes)
  86. return doc.selectNodes(sExpr, this);
  87. else
  88. throw "Method selectNodes is only supported by XML Elements";
  89. }
  90. // IE: XMLDocument.selectSingleNodes()
  91. XMLDocument.prototype.selectSingleNode = function(sExpr, contextNode){
  92. var ctx = contextNode?contextNode:null;
  93. sExpr = "("+sExpr+")[1]";
  94. var nodeList = this.selectNodes(sExpr, ctx);
  95. if(nodeList.length > 0)
  96. return nodeList.item(0);
  97. else
  98. return null;
  99. }
  100. // IE: Element.selectSingleNode()
  101. Element.prototype.selectSingleNode = function(sExpr){
  102. var doc = this.ownerDocument;
  103. if(doc.selectSingleNode)
  104. return doc.selectSingleNode(sExpr, this);
  105. else
  106. throw "Method selectNodes is only supported by XML Elements";
  107. }
  108. }
  109. function serializeDomNode(xmlDoc)
  110. {
  111. if (xmlDoc.xml) {
  112. return xmlDoc.xml;
  113. } else if(window.XMLSerializer) {
  114. return (new XMLSerializer()).serializeToString(xmlDoc);
  115. }
  116. return null;
  117. }
  118. // END: browser specific code
  119. //--------------------------------------
  120. var ie = document.all ? 1 : 0;
  121. var ns = document.layers ? 1 : 0;
  122. /*
  123. - multiple selection
  124. - ability to dynamically add items
  125. - context menu with both item and tree specific commands
  126. - ability to add on_sel_changed, on_insert_child and on_expanding handlers
  127. - find xpaths for items and find items with given xpaths
  128. - demand loading of children
  129. - custom menus for individual items
  130. */
  131. function tree (a_items, a_template) {
  132. this.n_tid = trees.length;
  133. trees[this.n_tid] = this;
  134. this.a_tpl = a_template;
  135. this.a_config = a_items;
  136. this.o_root = this;
  137. this.a_index = [];
  138. this.a_selected = [];
  139. this.a_deleted = [];
  140. this.b_selected = false;
  141. this.n_depth = -1;
  142. this.select_all = select_all;
  143. this.select_none= select_none;
  144. this.upstatus = function() {};//nothing
  145. this.o_parent = null;
  146. this.a_custom_menus = [];
  147. this.a_custom_menu_ids = [];
  148. this.n_items = 0;
  149. this.b_cache_children = true;
  150. this.get_item = function(id) { return this.a_index[id]; };
  151. this.item_count = function() { return this.n_items; };
  152. this.get_first_item = get_first_item;
  153. this.get_next_item = get_next_item;
  154. this.deleteAllChildren = deleteAllChildren;
  155. this.action = null;
  156. this.border = null;
  157. this.a_columns= null;
  158. this.a_columnWidths = null;
  159. this.add_tree_column = add_tree_column;
  160. this.timeoutId = 0;
  161. var o_icone = new Image();
  162. var o_iconl = new Image();
  163. o_icone.src = a_template['icon_e'];
  164. o_iconl.src = a_template['icon_l'];
  165. a_template['im_e'] = o_icone;
  166. a_template['im_l'] = o_iconl;
  167. for (var i = 0; i < 64; i++)
  168. if (a_template['icon_' + i])
  169. {
  170. var o_icon = new Image();
  171. a_template['im_' + i] = o_icon;
  172. o_icon.src = a_template['icon_' + i];
  173. }
  174. this.expand = item_expand;
  175. this.toggle = toggle;
  176. this.select = function (n_id, e, treeid) { return this.get_item(n_id).select(e, treeid); };
  177. this.mover = mouse_over_item;
  178. this.mout = mouse_left_item;
  179. this.oncontextmenu = function (n_id, e, treeid) { return this.get_item(n_id).oncontextmenu(e, treeid) };
  180. this.show_context_menu = show_context_menu;
  181. this.handle_command = handle_command;
  182. this.on_sel_changed = null;
  183. this.on_expanding = null;
  184. this.on_context_menu= null;
  185. this.on_command = null;
  186. this.get_custom_menu = function(menu_name) {
  187. var index = this.a_custom_menu_ids[menu_name];
  188. return (index != undefined) ? this.a_custom_menus[index] : null;
  189. }
  190. this.add_custom_menu = function(menu_name, a_menu) {
  191. if (!this.get_custom_menu(menu_name))
  192. {
  193. var index = this.a_custom_menus.length;
  194. this.a_custom_menus[index] = a_menu;
  195. this.a_custom_menu_ids[menu_name] = index;
  196. }
  197. return index;
  198. }
  199. this.a_children = [];
  200. for (var i = 0; i < a_items.length; i++)
  201. new tree_item(this, i, this.a_config[i + (this.n_depth + 1 ? 2 : 0)]);
  202. var n_children = this.a_children.length;
  203. if (n_children) {
  204. var div = document.getElementById('tree_' + this.n_tid);
  205. var a_html = [];
  206. for (var i=0; i<n_children; i++) {
  207. var child = this.a_children[i];
  208. a_html[i] = child.init();
  209. child.expand();
  210. }
  211. div.innerHTML = a_html.join('');
  212. }
  213. }
  214. function loadXMLDoc(url)
  215. {
  216. var xmlhttp = createXmlHttpRequestObject();
  217. if (xmlhttp)
  218. {
  219. xmlhttp.open("GET", url, false);
  220. xmlhttp.send(null);
  221. }
  222. return xmlhttp;
  223. }
  224. function tree_item (o_parent, n_position, config) {
  225. this.n_depth = o_parent.n_depth + 1;
  226. this.a_config = config;
  227. if (!this.a_config) return;
  228. this.o_root = o_parent.o_root;
  229. this.o_parent = o_parent;
  230. this.n_position = n_position;
  231. this.b_expanded = !this.n_depth;
  232. this.b_selected= false;
  233. this.b_load_on_demand = false;
  234. this.b_cache_children = this.o_root.b_cache_children;
  235. this.action = null;
  236. this.a_columns = null;
  237. this.add_column = add_column;
  238. this.b_checkbox = false;
  239. this.b_checked = false;
  240. if (this.o_root.a_deleted.length > 0)//reclaim a previously deleted id
  241. this.n_id = this.o_root.a_deleted.shift();
  242. else
  243. this.n_id = this.o_root.item_count(); //a_children is contiguous so pick next index
  244. this.o_root.a_index[this.n_id] = this;
  245. this.o_root.n_items++;
  246. o_parent.a_children[n_position] = this;
  247. this.a_children = [];
  248. for (var i = 0; i < this.a_config.length - 2; i++)
  249. new tree_item(this, i, this.a_config[i + (this.n_depth + 1 ? 2 : 0)]);
  250. this.get_icon = item_get_icon;
  251. this.expand = item_expand;
  252. this.select = handle_selection;
  253. this.init = item_init;
  254. this.upstatus = item_upstatus;
  255. this.oncontextmenu=context_menu;
  256. this.name = function () { return this.a_config[0]; }
  257. this.data = null;
  258. this.on_insert_child= null;
  259. this.is_last =
  260. function () {
  261. return this.n_position == this.o_parent.a_children.length - 1
  262. };
  263. if (o_parent.on_insert_child)
  264. o_parent.on_insert_child(this);
  265. }
  266. function item_init () {
  267. var o_tree = this.o_root;
  268. var treeId = o_tree.n_tid;
  269. var itemId = this.n_id;
  270. var tree = 'trees[' + treeId + ']';
  271. var s = [];
  272. var i = 0;
  273. s[i++] = '<table cellpadding="0" cellspacing="0"'
  274. if (o_tree.border)
  275. s[i++] = ' style="border-bottom:1px groove lightgray"';
  276. s[i++] = '>';
  277. if (o_tree.a_columns)
  278. s[i++] = get_column_header_html(o_tree, false);
  279. s[i++] = '<tr><td nowrap valign="bottom">';
  280. if (this.n_depth)
  281. {
  282. var o_current_item = this.o_parent;
  283. for (var j = this.n_depth; j > 1; j--) {
  284. s[j+i] = '<img src="' + this.o_root.a_tpl[o_current_item.is_last() ? 'icon_e' : 'icon_l'] + '" border="0" align="absbottom">';
  285. o_current_item = o_current_item.o_parent;
  286. }
  287. i = s.length;
  288. if (this.b_load_on_demand || this.a_children.length)
  289. {
  290. s[i++] = '<a class="tree" href="javascript:';
  291. s[i++] = tree;
  292. s[i++] = '.toggle(';
  293. s[i++] = itemId;
  294. // s[i++] = ')" onmouseover="';
  295. // s[i++] = tree;
  296. // s[i++] = '.mover(';
  297. // s[i++] = itemId;
  298. // s[i++] = ')" onmouseout="';
  299. // s[i++] = tree;
  300. // s[i++] = '.mout(';
  301. // s[i++] = itemId;
  302. s[i++] = ')"><img src="';
  303. s[i++] = this.get_icon(true);
  304. s[i++] = '" border="0" align="absbottom" name="j_img';
  305. s[i++] = treeId;
  306. s[i++] = '_';
  307. s[i++] = itemId;
  308. s[i++] = '"></a>';
  309. }
  310. else
  311. {
  312. s[i++] = '<img src="';
  313. s[i++] = this.get_icon(true);
  314. s[i++] = '" border="0" align="absbottom">';
  315. }
  316. }
  317. if (this.b_checkbox)
  318. {
  319. s[i++] = '<input type="checkbox" style="zoom:0.8"';
  320. if (this.b_checked)
  321. s[i++] = ' checked="true"'
  322. s[i++] = '>';
  323. }
  324. s[i++] = '<a href="';
  325. s[i++] = this.a_config[1] == null ? 'javascript:void(0)' : this.a_config[1];
  326. s[i++] = '" target="';
  327. s[i++] = this.o_root.a_tpl['target']=='_self' ? 'javacript:void(0)' : this.o_root.a_tpl['target'];
  328. s[i++] = '" onclick="return ';
  329. s[i++] = tree;
  330. s[i++] = '.select(';
  331. s[i++] = itemId;
  332. s[i++] = ', event, ';
  333. s[i++] = '\'i_txt';
  334. s[i++] = treeId;
  335. s[i++] = '_';
  336. s[i++] = itemId;
  337. s[i++] = '\')" ondblclick="';
  338. s[i++] = tree;
  339. s[i++] = '.toggle(';
  340. s[i++] = itemId;
  341. // s[i++] = ')" onmouseover="alert(\'here\');" ';
  342. // s[i++] = tree;
  343. // s[i++] = '.mover(';
  344. // s[i++] = itemId;
  345. // s[i++] = ')" onmouseout="';
  346. // s[i++] = tree;
  347. // s[i++] = '.mout(';
  348. // s[i++] = itemId;
  349. s[i++] = ')" oncontextmenu="return ';
  350. s[i++] = tree;
  351. s[i++] = '.oncontextmenu(';
  352. s[i++] = itemId;
  353. s[i++] = ', event, ';
  354. s[i++] = '\'i_txt';
  355. s[i++] = treeId;
  356. s[i++] = '_';
  357. s[i++] = itemId;
  358. s[i++] = '\')" class="t';
  359. s[i++] = treeId;
  360. s[i++] = 'i" id="i_txt';
  361. s[i++] = treeId;
  362. s[i++] = '_';
  363. s[i++] = itemId;
  364. s[i++] = '"';
  365. if (this.n_depth == 0)
  366. s[i++] = ' style="font-weight:bold"';
  367. s[i++] = '>';
  368. s[i++] = '<img src="';
  369. s[i++] = this.get_icon();
  370. s[i++] = '" border="0" align="absbottom" name="i_img';
  371. s[i++] = treeId;
  372. s[i++] = '_';
  373. s[i++] = itemId;
  374. s[i++] = '" class="t';
  375. s[i++] = treeId;
  376. s[i++] = 'im"/>';
  377. s[i++] = this.name();
  378. s[i++] = '</a></td>';
  379. if (o_tree.a_columns)
  380. {
  381. //the a_columns array of item only holds non-empty
  382. //column contents for columns after first column and
  383. //may not have any columns even though the tree may
  384. //have more columns defined
  385. var n_columns = this.a_columns ? this.a_columns.length : 0;
  386. for (var c=0; c<n_columns; c++)
  387. {
  388. s[i++] = '<td class="small">';
  389. s[i++] = this.a_columns[c];
  390. s[i++] = '</td>';
  391. }
  392. //now create table cells for empty columns
  393. n_columns = o_tree.a_columns.length;
  394. c++;
  395. for (; c<n_columns; c++)
  396. s[i++] = '<td/>';
  397. }
  398. s[i++] = '</tr></table>';
  399. s[i++] = '<div id="i_div';
  400. s[i++] = treeId;
  401. s[i++] = '_';
  402. s[i++] = itemId;
  403. s[i++] = '" style="display:';
  404. s[i++] = this.b_expanded ? 'block' : 'none';
  405. s[i++] = '">';
  406. if (this.b_expanded)
  407. for (var j = 0; j < this.a_children.length; j++)
  408. s[i++] = this.a_children[j].init();
  409. s[i++] = '</div>';
  410. return s.join('');
  411. }
  412. //add column for a tree
  413. //
  414. function add_tree_column(column)
  415. {
  416. if (this.a_columns == null)
  417. {
  418. this.a_columns = new Array();
  419. this.a_columnWidths = new Array();
  420. }
  421. this.a_columns.push( column );
  422. var width = column['width'];
  423. this.a_columnWidths[ this.a_columnWidths.length ] = typeof width != 'undefined' ? width : 300;
  424. }
  425. //add column for a tree item
  426. //
  427. function add_column(innerHTML)
  428. {
  429. if (this.a_columns == null)
  430. this.a_columns = new Array();
  431. this.a_columns.push( innerHTML );
  432. }
  433. function load_children_on_demand(item)
  434. {
  435. var rc = false;
  436. if (item.b_load_on_demand && item.a_children.length==0)
  437. {
  438. window.status = 'Loading child items ...';
  439. var url = '/esp/navdata';
  440. if (item.params)
  441. url += '?' + item.params;
  442. var xmlHttp = loadXMLDoc(url);
  443. if (xmlHttp.status==200)
  444. {
  445. addChildItemsFromNavData(xmlHttp.responseXML.documentElement, item);
  446. rc = true;
  447. }
  448. else
  449. alert("Error in dynamically loading the children:\n" + xmlHttp.statusText);
  450. }
  451. window.status = '';
  452. return rc;//don't expand if error occurred
  453. }
  454. function item_expand (b_expand, b_recursive) {
  455. if (this.a_children.length == 0)
  456. return;
  457. var treeId = this.o_root.n_tid;
  458. var o_idiv = get_element('i_div' + treeId + '_' + this.n_id);
  459. if (o_idiv)
  460. {
  461. if (!o_idiv.innerHTML) {
  462. var a_children = [];
  463. for (var i = 0; i < this.a_children.length; i++)
  464. a_children[i] = this.a_children[i].init();
  465. o_idiv.innerHTML = a_children.join('');
  466. }
  467. o_idiv.style.display = b_expand ? 'block' : 'none';
  468. this.b_expanded = b_expand;
  469. var o_jicon = document.images['j_img' + treeId + '_' + this.n_id],
  470. o_iicon = document.images['i_img' + treeId + '_' + this.n_id];
  471. if (o_jicon)
  472. o_jicon.src = this.get_icon(true);
  473. if (o_iicon && this.get_icon)
  474. o_iicon.src = this.get_icon();
  475. if (this.upstatus)
  476. this.upstatus();
  477. }
  478. if (b_recursive)
  479. for (var i = 0; i < this.a_children.length; i++)
  480. this.a_children[i].expand(b_expand, b_recursive);
  481. }
  482. function get_column_header_html(table, bCaption)
  483. {
  484. var a_columns = table.a_columns;
  485. var n_columns = a_columns ? a_columns.length : 0;
  486. if (!n_columns)
  487. return '';
  488. var a_html = [];
  489. a_html.push(bCaption ? '<table><thead class="sort-table"><tr>' : '<colgroup>');
  490. for (var i=0; i<n_columns; i++)
  491. {
  492. var column = a_columns[i];
  493. a_html.push(bCaption ? '<th class="sort-table"' : '<col');
  494. for (attrib in column)
  495. if (attrib != 'innerHTML')
  496. a_html.push(' ' + attrib + '="' + column[attrib] + '"');
  497. a_html.push('>');
  498. if (bCaption)
  499. {
  500. var innerHTML = column['innerHTML'];
  501. if (typeof innerHTML != 'undefined')
  502. a_html.push(innerHTML);
  503. }
  504. a_html.push(bCaption ? '</th>' : '</col>');
  505. }
  506. a_html.push(bCaption ? '</tr></thead></table>' : '</colgroup>');
  507. return a_html.join('');
  508. }
  509. function redo_item(item)
  510. {
  511. var o_tree = item.o_root;
  512. if (item == o_tree)
  513. {
  514. var a_html = [];
  515. var n_children = item.a_children.length;
  516. for (var i = 0; i < n_children; i++)
  517. {
  518. var child = item.a_children[i];
  519. a_html[i] = child.init();
  520. child.expand();
  521. }
  522. var div = get_element('tree_'+item.n_tid);
  523. if (o_tree.a_columns)
  524. {
  525. a_html.unshift(get_column_header_html(item, true));
  526. var width = 0;
  527. var n_columns = o_tree.a_columns.length
  528. for (i=0; i<n_columns; i++)
  529. width += Number(o_tree.a_columnWidths[i]);
  530. div.style.width = width;
  531. }
  532. div.innerHTML = a_html.join('');
  533. }
  534. else
  535. {
  536. var o_idiv = get_element('i_div' + o_tree.n_tid + '_' + item.n_id);
  537. if (o_idiv)
  538. {
  539. var a_html = [];
  540. for (var i = 0; i < item.a_children.length; i++)
  541. a_html[i] = item.a_children[i].init();
  542. o_idiv.innerHTML = a_html.join('');
  543. return o_idiv.innerHTML;
  544. }
  545. }
  546. }
  547. function insert_item(parent, item_name, b_load_on_demand)
  548. {
  549. if (!parent.a_children)
  550. parent.a_children = new Array();
  551. var pos = parent.a_children.length;
  552. var new_item = new tree_item(parent, pos, [item_name, null]);
  553. new_item.b_load_on_demand = b_load_on_demand;
  554. //window.status = '';
  555. redo_item(parent.o_parent != parent.o_root ? parent.o_parent : parent);
  556. if (!parent.b_expanded)
  557. parent.expand(true);
  558. new_item.select(false);
  559. return new_item;
  560. }
  561. function add_item(tree, parent_id, item_type, name, tooltip, menu, params)
  562. {
  563. var parent = parent_id == -1 ? tree.o_root : tree.a_index[parent_id];
  564. var pos = parent.a_children.length;
  565. var new_item = new tree_item(parent, pos, [name, null]);
  566. if (tooltip != '')
  567. new_item.tooltip = tooltip;
  568. if (item_type == 'DynamicFolder')
  569. new_item.b_load_on_demand = true;
  570. if (menu != '')
  571. {
  572. var menu_id = tree.a_custom_menu_ids[menu];
  573. if (menu_id != -1)
  574. new_item.n_custom_menu = menu_id;
  575. }
  576. if (params != '')
  577. new_item.params = params; //unescape(params);
  578. return new_item;
  579. }
  580. function delete_item(tree, item_id, b_refresh)
  581. {
  582. if (typeof b_refresh == 'undefined')
  583. b_refresh = true;
  584. //remove children of this item first, if any
  585. //
  586. var item = tree.get_item(item_id);
  587. var children = item.a_children;
  588. var n_children = children.length;
  589. for (var i=0; i<n_children; i++)
  590. delete_item(tree, children[i].n_id, false);
  591. if (item.b_selected)
  592. {
  593. selected = tree.a_selected;
  594. n_selected = selected.length;
  595. for (i=0; i<n_selected; i++)
  596. if (selected[i] == item)
  597. {
  598. selected.splice(i, 1);
  599. break;
  600. }
  601. }
  602. tree.a_deleted[ tree.a_deleted.length ] = item_id;
  603. tree.a_index[ item_id ] = null;
  604. tree.n_items--;
  605. //update this item's parent's a_children - only for top most item getting deleted
  606. //
  607. var o_parent = item.o_parent;
  608. if (b_refresh)
  609. {
  610. //remove this item from its parent's a_children array
  611. //
  612. children = o_parent.a_children;
  613. n_children = children.length;
  614. for (i=0; i<n_children; i++)
  615. if (children[i] == item)
  616. {
  617. children.splice(i, 1);
  618. break;
  619. }
  620. redo_item(o_parent.o_parent != o_parent.o_root ? o_parent.o_parent : o_parent);
  621. }
  622. }
  623. function deleteAllChildren(item)
  624. {
  625. var children = item.a_children;
  626. var n_children = children.length;
  627. for (var i=0; i<n_children; i++)
  628. delete_item(this, children[i].n_id, false);
  629. children.length=0;
  630. }
  631. function refresh_item(tree, item_id)
  632. {
  633. var item = tree.get_item(item_id);
  634. if (!item.b_load_on_demand)
  635. return;
  636. var b_expanded = item.b_expanded;
  637. if (b_expanded)
  638. item.expand(false);
  639. tree.deleteAllChildren(item);
  640. if (b_expanded && load_children_on_demand(item))
  641. item.expand(true);
  642. return true;
  643. }
  644. function import_xml_nodeset(parent, objNodes)
  645. {
  646. var len = objNodes.length;
  647. for (var i=0; i<len; i++)
  648. {
  649. var pos = parent.a_children.length;
  650. var item_name = objNodes[i].text;
  651. new tree_item(parent, pos, [item_name, null]);
  652. }
  653. redo_item(parent.o_parent != parent.o_root ? parent.o_parent : parent);
  654. }
  655. function get_xml_attrib(xmlNode, attribName, defaultValue)
  656. {
  657. var attr = xmlNode.attributes.getNamedItem(attribName);
  658. return attr ? attr.nodeValue : defaultValue;
  659. }
  660. function import_xml(parent, objNode)
  661. {
  662. var a_nodes = objNode.childNodes;
  663. var n_nodes = a_nodes.length;
  664. for (var i=0; i<n_nodes; i++)
  665. {
  666. var name = get_xml_attrib(a_nodes[i], 'name', 'unknown')
  667. var pos = parent.a_children.length;
  668. var item = new tree_item(parent, pos, [name, null]);
  669. if (a_nodes[i].tagName == 'Folder')
  670. import_xml(item, a_nodes[i]);
  671. }
  672. redo_item(parent.o_parent != parent.o_root ? parent.o_parent : parent);
  673. }
  674. function get_first_item()
  675. {
  676. return get_next_item(-1);
  677. }
  678. function get_next_item(item_id)
  679. {
  680. var n_items = this.item_count();
  681. if (n_items > 0)
  682. {
  683. var size = this.a_children.length;
  684. for (var i = item_id+1; i<size; )
  685. if (this.a_children[i])
  686. return i;
  687. }
  688. return -1;
  689. }
  690. function select_all()
  691. {
  692. this.o_root.expand(true, true);
  693. this.o_root.a_selected.length = 0;
  694. var i=0;
  695. for ( var item_id = this.o_root.get_first_item();
  696. item_id != -1;
  697. item_id = this.o_root.get_next_item(item_id))
  698. {
  699. this.o_root.a_selected[i] = this.o_root.get_item(item_id);
  700. select_item(this.o_root.a_selected[i++], true);
  701. }
  702. this.o_root.upstatus();
  703. }
  704. function select_none()
  705. {
  706. var n_selected = this.a_selected.length;
  707. for (var i=0; i<n_selected; i++)
  708. select_item(this.a_selected[i], false);
  709. this.a_selected.length = 0;
  710. this.o_root.upstatus();
  711. }
  712. function handle_selection(e)
  713. {
  714. var n_selected = this.o_root.a_selected.length;
  715. var b_multiselect;
  716. var b_select;
  717. var o_tree = this.o_root;
  718. //if either the control key is pressed or an already selected item is clicked
  719. //upon with right mouse button then this is the case of multiple selection
  720. //
  721. if (!e) {
  722. e = window.event;
  723. }
  724. if ((e && e.ctrlKey) || (this.b_selected && o_tree.b_rightMouseButton))
  725. {
  726. b_multiselect = true;
  727. //select this item unless the control key is pressed without right mouse button
  728. //and object is already selected
  729. b_select = !(e.ctrlKey && this.b_selected);
  730. }
  731. else
  732. {
  733. b_multiselect = false;
  734. b_select = true;
  735. //if either multiple items are currently selected or some other item is then unselect all
  736. if (n_selected > 1 || (n_selected==1 && !this.b_selected))
  737. o_tree.select_none();
  738. }
  739. if (b_select != this.b_selected)
  740. {
  741. if (b_select)
  742. o_tree.a_selected.push(this);
  743. else
  744. {
  745. //delete this object from the root's a_selected array
  746. var n_selected = o_tree.a_selected.length;
  747. for (var i=0; i<n_selected; i++)
  748. if (o_tree.a_selected[i] == this)
  749. {
  750. o_tree.a_selected.splice(i, 1);
  751. break;
  752. }
  753. }
  754. select_item(this, b_select);
  755. if (o_tree.on_sel_changed)
  756. o_tree.on_sel_changed(o_tree);
  757. this.upstatus();
  758. }
  759. if ((o_tree.action || this.action) && !o_tree.b_rightMouseButton && !b_multiselect)
  760. o_tree.handle_command(o_tree.n_tid, this, 'click', this.action ? this.action : o_tree.action);
  761. return Boolean(this.a_config[1]);
  762. }
  763. function select_item (item, b_select) {
  764. item.b_selected = b_select;
  765. var o_iicon = document.images['i_img' + item.o_root.n_tid + '_' + item.n_id];
  766. if (o_iicon)
  767. o_iicon.src = item.get_icon();
  768. var obj = get_element('i_txt' + item.o_root.n_tid + '_' + item.n_id);
  769. obj.style.backgroundColor = b_select ? 'highlight' : 'window';
  770. obj.style.color = b_select ? 'white' : 'black';
  771. }
  772. function item_upstatus (b_clear) {
  773. //window.setTimeout('window.status="' + (b_clear ? '' : this.name() +
  774. // (this.a_config[1] ? ' ('+ this.a_config[1] + ')' : '')) + '"', 10);
  775. }
  776. function item_get_icon (b_junction) {
  777. var b_has_children = this.b_load_on_demand || this.a_children.length;
  778. var icon_id = this.n_depth ? 0 : 32;
  779. if (b_has_children)
  780. {
  781. icon_id += 16;
  782. if (this.b_expanded)
  783. icon_id += 8;
  784. }
  785. if (b_junction)
  786. {
  787. icon_id += 2;
  788. if (this.is_last())
  789. icon_id++;
  790. }
  791. //else
  792. // if (this.b_selected)
  793. // icon_id += 4;
  794. return this.o_root.a_tpl['icon_' + icon_id];
  795. }
  796. /* not used yet...
  797. function get_xpath(item)
  798. {
  799. var xpath = null;
  800. while (item != item.o_root)
  801. {
  802. xpath = xpath ? item.name() + '/' + xpath : item.name();
  803. item = item.o_parent;
  804. }
  805. return xpath ? xpath : "";
  806. }
  807. */
  808. function get_items_with_name(parent, name)
  809. {
  810. var a_children = [];
  811. var nChildren = parent.a_children.length;
  812. for (var i = 0; i < nChildren; i++)
  813. if (name == '*' || parent.a_children[i].name() == name)
  814. a_children.push(parent.a_children[i]);
  815. return a_children;
  816. }
  817. /* unused for now...
  818. function get_items_at_xpath(parent, xpath)
  819. {
  820. var items = [];
  821. var ndx = xpath.indexOf('/');
  822. var prefix;
  823. var suffix;
  824. if (ndx == -1)// no slash found in xpath
  825. {
  826. prefix = xpath;
  827. suffix = '';
  828. }
  829. else
  830. {
  831. prefix = xpath.substring(0, ndx);
  832. suffix = xpath.substring(ndx+1);
  833. }
  834. if (prefix.length)
  835. {
  836. var found = get_items_with_name(parent, prefix);
  837. if (suffix == '')
  838. return found;
  839. else
  840. for (var i=0; i<found.length; i++)
  841. {
  842. var found2 = get_items_at_xpath(found[i], suffix);
  843. for (var j=0; j<found2.length; j++)
  844. items.push( found2[j] );
  845. }
  846. }
  847. return items;
  848. }
  849. */
  850. function handle_command(tree_id, focus_item_id, cmd, action) {
  851. //hide_popup_menu();
  852. var tree = this.o_root;
  853. if (cmd == 'Select All')
  854. {
  855. tree.select_all();
  856. if (tree.on_sel_changed)
  857. tree.on_sel_changed(tree);
  858. }
  859. else if (cmd == 'Select None')
  860. {
  861. tree.select_none();
  862. if (tree.on_sel_changed)
  863. tree.on_sel_changed(tree);
  864. }
  865. else if (cmd == 'Expand All')
  866. {
  867. tree.expand(true, true);
  868. }
  869. else if (cmd == 'Collapse All')
  870. {
  871. tree.expand(false, true);
  872. }
  873. else if (cmd == 'Expand')
  874. {
  875. for (var i=0; i<tree.a_selected.length; i++)
  876. tree.a_selected[i].expand(true, true);
  877. }
  878. else if (cmd == 'Collapse')
  879. {
  880. for (var i=0; i<tree.a_selected.length; i++)
  881. tree.a_selected[i].expand(false, true);
  882. }
  883. else if (cmd == 'New')
  884. {
  885. var item_name = prompt('Enter name of new item:', 'New Item');
  886. if (item_name)
  887. {
  888. var item = tree.get_item(focus_item_id);
  889. insert_item(item, item_name, true);
  890. }
  891. }
  892. else if (cmd == 'Delete')
  893. {
  894. delete_item(tree, focus_item_id);
  895. }
  896. else if (cmd == 'Refresh')
  897. {
  898. refresh_item(tree, focus_item_id);
  899. }
  900. else if (tree.on_command)
  901. {
  902. tree.on_command(tree, cmd, action);
  903. }
  904. return true;
  905. }
  906. function search_array(a_array, item)
  907. {
  908. var len = a_array.length;
  909. for (var i=0; i<len; i++)
  910. if (a_array[i] == item)
  911. return i;
  912. return -1;
  913. }
  914. function context_menu(e, treeid)
  915. {
  916. //document.all.menu.innerHTML = '';
  917. //document.all.src.value = '';
  918. //document.all.src.value = document.body.innerHTML;
  919. //debugger;
  920. //hack: the web page does not remember that right mouse button
  921. //is pressed to remember it so item selection can use that fact
  922. this.o_root.b_rightMouseButton = true;
  923. this.select(e);
  924. if (!this.b_selected)
  925. this.select(e);
  926. this.o_root.b_rightMouseButton = false;
  927. /* define a menu as an array of menu items. Each menu item is as follows:
  928. null - separator
  929. command [, action [, caption [, handler [, showCheckbox]]] //only command is required
  930. where:
  931. command: the command that is passed to the handler
  932. action : the parameter string needed to run the command like a url
  933. caption: the menu item text. If this is not supplied then command is shown as text
  934. handler: of the form function handler(item_id, command, action) {...} or null to disable
  935. showCheckbox: if null, no checkbox is shown, true/false indicate check states otherwise
  936. for instance:
  937. var menu=[["cmd_1", "action_1", "Caption 1", "menuHandler", true], //true for checked item
  938. null, //separator
  939. ["cmd_2", "action_2", "Caption 2", null, false]];//false for unchecked item
  940. */
  941. //do a dedup of all custom menus of selected items
  942. var a_custom_menu_ids = [];
  943. var n_custom_menu_id = -1;
  944. var b_all_dynamic_folders = true;
  945. for (var i=0; i<this.o_root.a_selected.length; i++)
  946. {
  947. var sel_item = this.o_root.a_selected[i];
  948. if (!sel_item.b_load_on_demand)
  949. b_all_dynamic_folders = false;
  950. var menu_id = sel_item.n_custom_menu;
  951. if (menu_id != undefined)
  952. {
  953. if (a_custom_menu_ids.length == 0)//none set yet
  954. n_custom_menu_id = menu_id;
  955. else
  956. if (n_custom_menu_id != -1)//multiple selected items already had different menus
  957. {
  958. if (n_custom_menu_id != menu_id)
  959. n_custom_menu_id = -1;
  960. }
  961. if (search_array(a_custom_menu_ids, menu_id) == -1)
  962. a_custom_menu_ids.push(menu_id);
  963. }
  964. else//some item does not have custom menu so disallow all custom menus
  965. break;
  966. }
  967. //define default menu...
  968. var default_menu = [
  969. /*
  970. ["New"],
  971. ["Delete"],
  972. ["Refresh"],
  973. null,
  974. ["Expand"],
  975. ["Collapse"],
  976. null,
  977. ["Select All"],
  978. ["Select None"],
  979. ["Expand All"],
  980. ["Collapse All"]
  981. */
  982. ];
  983. var menu;
  984. if (n_custom_menu_id != -1)//all selected items had same menu
  985. {
  986. //menu = this.o_root.a_custom_menus[n_custom_menu_id].concat([null], default_menu);
  987. menu = this.o_root.a_custom_menus[n_custom_menu_id].concat(default_menu);
  988. }
  989. else
  990. {
  991. if (a_custom_menu_ids.length == 0)//none of the selected items had any custom menus
  992. menu = default_menu;
  993. else
  994. {
  995. //the selected items had different custom menus
  996. //so make a menu with items that are intersection of these menus
  997. var n_first_id = a_custom_menu_ids[0];
  998. var a_first_menu = this.o_root.a_custom_menus[n_first_id];//start with first menu
  999. var new_custom_menu = [];
  1000. for (var i=0; i<a_first_menu.length; i++)//enumerate first menu's items
  1001. {
  1002. var menu_item_cmd = a_first_menu[i][0];
  1003. var b_add = true;
  1004. for (var j=1; j<a_custom_menu_ids.length; j++)
  1005. {
  1006. var a_menu = this.o_root.a_custom_menus[ a_custom_menu_ids[j] ];
  1007. var b_found = false;
  1008. for (var k=0; k<a_menu.length; k++)
  1009. if (a_menu[k][0] == menu_item_cmd)
  1010. {
  1011. b_found = true;
  1012. break;
  1013. }
  1014. if (!b_found)
  1015. {
  1016. b_add = false;
  1017. break;
  1018. }
  1019. }
  1020. if (b_add)
  1021. new_custom_menu.push( a_first_menu[i] );
  1022. }
  1023. menu = new_custom_menu;
  1024. }
  1025. }
  1026. if (b_all_dynamic_folders)
  1027. {
  1028. var hasRefreshCmd = false;
  1029. for (var i=0; i<menu.length; i++)//enumerate first menu's items
  1030. if (menu[i][0] == 'Refresh')
  1031. {
  1032. hasRefreshCmd = true;
  1033. break;
  1034. }
  1035. if (!hasRefreshCmd)
  1036. {
  1037. if (menu.length)
  1038. menu.push(null);
  1039. menu.push(['Refresh']);
  1040. }
  1041. }
  1042. if (this.o_root.on_context_menu)
  1043. this.o_root.on_context_menu(this.o_root, menu); //allow callback to override the default menu
  1044. if (menu.length)
  1045. {
  1046. this.o_root.show_context_menu(this.n_id, menu, null, false, 1, treeid);
  1047. return false; //don't let even propagate up to allow browser's menu
  1048. }
  1049. return true;//let event propagate to show browser's menu
  1050. }
  1051. var oMenu;
  1052. var menuItems;
  1053. function show_context_menu(item_id, menu, popup_caption, addCloseButton, itemsPerLine, treeid)//"View Columns:"
  1054. {
  1055. var s = new Array();
  1056. var i = 0;
  1057. s[i++] = '<table style="font:bold 8pt verdana, arial, helvetica, sans-serif" id="tab" width="10" oncontextmenu="return false" onselectstart="return false">';
  1058. //s[i++] = 'onmouseover="parent.clear_popup_timer()" onmouseout="parent.set_popup_timer()">';
  1059. var iCaption = i; //leave an item as place holder for possible caption to be added later below
  1060. s[i++] = ' '; //caption
  1061. s[i++] = '<tr>';
  1062. var horizLine = false;
  1063. var columns = 0;
  1064. for(var item in menu)
  1065. if(menu[item])
  1066. {
  1067. var menuItem= menu[item];
  1068. var cmd = menuItem[0];
  1069. var action = menuItem[1];
  1070. var caption = menuItem[2] ? menuItem[2] : menuItem[0];
  1071. var handler = menuItem[3] ? menuItem[3] : 'trees['+this.o_root.n_tid+'].handle_command';
  1072. var checked = menuItem[4];
  1073. var disabled=!menuItem[1];
  1074. if ((columns++ % itemsPerLine == 0) && columns>0)
  1075. s[i++] = '</tr><tr>';
  1076. s[i++] = '<td nowrap style="paddiyesng:0';
  1077. if (horizLine)
  1078. {
  1079. s[i++] = ';border-top:solid 1px gray';
  1080. horizLine = false;
  1081. }
  1082. s[i++] = '" onmouseover=\'this.runtimeStyle.cssText="background-color:highlight; color:';
  1083. s[i++] = disabled ? 'graytext' : 'highlighttext';
  1084. s[i++] = ';";\' onmouseout=\'this.runtimeStyle.cssText=""\'';
  1085. if (checked != null)
  1086. {
  1087. s[i++] = '>'; //close <td> tag
  1088. s[i++] = ' <input type="checkbox" ';
  1089. if (checked)
  1090. s[i++] = 'checked="true" ';
  1091. if (!disabled)
  1092. {
  1093. s[i++] = 'onclick="return parent.';
  1094. s[i++] = handler;
  1095. s[i++] = '(';
  1096. s[i++] = this.n_tid;
  1097. s[i++] = ',';
  1098. s[i++] = item_id;
  1099. s[i++] = ',\'';
  1100. s[i++] = cmd;
  1101. s[i++] = '\', ';
  1102. s[i++] = action;
  1103. s[i++] = '\')"';
  1104. }
  1105. s[i++] = ' style="background-color:transparent;cursor:default" valign="center" >';
  1106. s[i++] = caption;
  1107. s[i++] = '</input>';
  1108. }
  1109. else
  1110. {
  1111. s[i++] = ' onclick="return parent.' + handler + '(' + this.n_tid + ',' + item_id + ',\'' + cmd + '\', \'' + action + '\')">';
  1112. s[i++] = caption;
  1113. }
  1114. s[i++] = '</td>';
  1115. }
  1116. else
  1117. horizLine = true;
  1118. var numColumns = columns > itemsPerLine ? itemsPerLine : columns;
  1119. if (popup_caption)
  1120. s[iCaption] = '<tr><th align="center" colspan="' + numColumns + '">' + popup_caption + '<hr/></th></tr>';
  1121. if (addCloseButton)
  1122. s[i++] = '<tr><th align="center" colspan="' + numColumns + '"><hr/>' +
  1123. '<input type="button" value="Close" onclick="parent.contextMenu.hide()"/>' +
  1124. '</th></tr>'
  1125. s[i++] ='</tr></table>';
  1126. //alert(s);
  1127. var xypos = YAHOO.util.Dom.getXY(treeid);
  1128. xypos[0] = 0;
  1129. if (oMenu) {
  1130. oMenu.destroy();
  1131. }
  1132. oMenu = new YAHOO.widget.Menu("treemenu", { position: "dynamic", xy: xypos });
  1133. oMenu.clearContent();
  1134. menuItems = null;
  1135. menuItems = new Array();
  1136. for (var item in menu) {
  1137. if (menu[item]) {
  1138. var menuItem = menu[item];
  1139. var ocmd = menuItem[0];
  1140. var oaction = menuItem[1];
  1141. var ocaption = menuItem[2] ? menuItem[2] : menuItem[0];
  1142. var ohandler = menuItem[3] ? menuItem[3] : 'trees[' + this.o_root.n_tid + '].handle_command';
  1143. menuItems[menuItems.length] = { text: ocaption.toString(), onclick: { fn: function() { context_Menu_Select(this.index); } }, treeid: this.n_tid, itemid: item_id, command: ocmd, action: oaction };
  1144. }
  1145. }
  1146. function context_Menu_Select(Menu_Index) {
  1147. trees[menuItems[Menu_Index].treeid].handle_command(menuItems[Menu_Index].treeid, menuItems[Menu_Index].itemid, menuItems[Menu_Index].command, menuItems[Menu_Index].action);
  1148. }
  1149. oMenu.addItems(menuItems);
  1150. oMenu.render("menu");
  1151. oMenu.show();
  1152. return;
  1153. }
  1154. function test ()
  1155. {
  1156. alert('test');
  1157. }
  1158. /* this function takes a string of the form "prefix{javascript}suffix" and
  1159. returns prefixXYZsuffix, where XYZ is the result of execution of javascript
  1160. within braces after any 'this' occurrences have been substituted with 'item'.
  1161. Multiple {javascript} blocks may be embedded within the string.
  1162. */
  1163. /* unused for now...
  1164. function process_embedded_scripts(url, item)
  1165. {
  1166. if (url.length == 0)
  1167. return '';
  1168. var open_brace = url.indexOf('{');
  1169. if (open_brace == -1)
  1170. return url;
  1171. var close_brace = url.indexOf('}', open_brace+1);
  1172. if (close_brace == -1)
  1173. close_brace = url.length+1;
  1174. var raw_script = url.substring(open_brace+1, close_brace);
  1175. var output;
  1176. if (raw_script.length)
  1177. {
  1178. var script = raw_script.replace('this.', 'item.');
  1179. var Fn = new Function('item', 'return ' + script);
  1180. output = Fn(item);
  1181. }
  1182. return url.substring(0, open_brace) + output + process_embedded_scripts( url.substring(close_brace+1), item );
  1183. }
  1184. */
  1185. function addToXmlDoc(xmlDoc, item)
  1186. {
  1187. if (item.o_parent == item.o_root)
  1188. parentNode = xmlDoc.documentElement;
  1189. else
  1190. parentNode = addToXmlDoc(xmlDoc, item.o_parent);
  1191. var name = item.name();
  1192. var node = parentNode.selectSingleNode( "*[@name='"+name+"']" );
  1193. if (!node)
  1194. {
  1195. var nodeName = item.b_load_on_demand ? 'DynamicFolder' : (item.a_children.length ? 'Folder' : 'Link');
  1196. node = xmlDoc.createElement( nodeName );
  1197. parentNode.appendChild(node);
  1198. var attr = xmlDoc.createAttribute("name");
  1199. attr.value = name;
  1200. node.setAttributeNode(attr);
  1201. if (item.params)
  1202. {
  1203. attr = xmlDoc.createAttribute("params");
  1204. //attr.value = escape(item.params);
  1205. attr.value = item.params;
  1206. node.setAttributeNode(attr);
  1207. }
  1208. }
  1209. return node;
  1210. }
  1211. function selectionToXmlDoc(tree)
  1212. {
  1213. var xmlDoc = createXmlDomObject();
  1214. var docElement = xmlDoc.createElement('EspNavigationData');
  1215. xmlDoc.appendChild(docElement);
  1216. xmlDoc.async="false";
  1217. var nSelected = tree.o_root.a_selected.length;
  1218. for (var i=0; i<nSelected; i++)
  1219. {
  1220. var item = tree.o_root.a_selected[i];
  1221. var node = addToXmlDoc(xmlDoc, item);
  1222. var attr = xmlDoc.createAttribute("selected");
  1223. attr.value = 'true';
  1224. node.setAttributeNode(attr);
  1225. }
  1226. return xmlDoc;
  1227. }
  1228. function postForm(xmlDoc, url)
  1229. {
  1230. var xmlhttp = createXmlHttpRequestObject();
  1231. xmlhttp.open("POST", url, false);
  1232. xmlhttp.SetRequestHeader("Content-Type", "text/xml");
  1233. xmlhttp.send(xmlDoc);
  1234. //Confirm HTTP request succeeded.
  1235. var resp = '';
  1236. if ((xmlhttp.status == 200) || (xmlhttp.status == 300 /*multiple choices*/))
  1237. resp = xmlhttp.responseText;
  1238. else
  1239. alert('Failed to post data to service!');
  1240. return resp;
  1241. }
  1242. /*
  1243. <EspNavigationData>
  1244. <Folder name="Attribute Servers" tooltip="Attribute Servers">
  1245. <DynamicFolder menu="rcmenu1"
  1246. name="DefaultAttrServer"
  1247. params="type=repository&amp;subtype=as&amp;name=DefaultAttrServer&amp;netAddress=http://10.150.29.202:8145"
  1248. tooltip="DefaultAttrServer"/>
  1249. <DynamicFolder menu="rcmenu1"
  1250. name="Configured Attribute Server"
  1251. params="type=repository&amp;subtype=as&amp;name=Configured Attribute Server&amp;netAddress=http://10.150.29.202:8145"
  1252. tooltip="Configured Attribute Server"/>
  1253. <DynamicFolder menu="rcmenu1"
  1254. name="attrSvr1"
  1255. params="type=repository&amp;subtype=as&amp;name=attrSvr1&amp;netAddress=http://10.150.64.208:8145"
  1256. tooltip="attrSvr1"/>
  1257. </Folder>
  1258. <Folder name="Roxie Clusters" tooltip="Roxie Clusters">
  1259. <DynamicFolder menu="rcmenu1"
  1260. name="roxie1"
  1261. params="type=repository&amp;subtype=rc&amp;name=roxie1&amp;netAddress=roxieAddr1"
  1262. tooltip="roxie1"/>
  1263. </Folder>
  1264. <Menu name="rcmenu1">
  1265. <MenuItem action="/ws_roxieconfig/NavMenuPublishEvent?parm1=y" name="Publish" tooltip="Publish"/>
  1266. </Menu>
  1267. </EspNavigationData>
  1268. */
  1269. function addChildItemsFromNavData(xmlNode, parent)
  1270. {
  1271. var tree = parent.o_root;
  1272. var a_nodes = xmlNode.getElementsByTagName('Menu');
  1273. var n_nodes = a_nodes.length;
  1274. for (var i=0; i<n_nodes; i++)
  1275. {
  1276. var node = a_nodes[i];
  1277. var menuName = get_xml_attrib(node, 'name', null);
  1278. if (menuName)
  1279. {
  1280. var o_menu = new Array;
  1281. var a_menu_items = node.getElementsByTagName('MenuItem');
  1282. var n_menu_items = a_menu_items.length;
  1283. for (var j=0; j<n_menu_items; j++)
  1284. {
  1285. var menu_item = a_menu_items[j];
  1286. var item_name = get_xml_attrib(menu_item, 'name', null);
  1287. var item_tip = get_xml_attrib(menu_item, 'tooltip', null);
  1288. var item_action = get_xml_attrib(menu_item, 'action', null);//handler
  1289. if (item_tip == null)
  1290. item_tip = item_name;
  1291. o_menu_item = new Array;
  1292. o_menu_item.push(item_name, item_action, item_tip);
  1293. o_menu.push( o_menu_item );
  1294. }
  1295. tree.add_custom_menu(menu_name, o_menu);
  1296. }
  1297. }
  1298. a_nodes = xmlNode.childNodes;
  1299. n_nodes = a_nodes.length;
  1300. var n_children = n_nodes;
  1301. for (var i=0; i<n_nodes; i++)
  1302. {
  1303. var node = a_nodes[i];
  1304. if (node.nodeName == 'Folder' || node.nodeName == 'DynamicFolder' || node.nodeName == 'Link')
  1305. {
  1306. var item;
  1307. var name = get_xml_attrib(node, 'name', 'unknown');
  1308. var tooltip = get_xml_attrib(node, 'tooltip', '');
  1309. var params = get_xml_attrib(node, 'params', '');
  1310. var menu_name = get_xml_attrib(node, 'menu', '');
  1311. //item.nodeName can either be DynamicFolder, Folder or Link
  1312. var item = add_item(tree, parent.n_id, node.nodeName, name, tooltip, menu_name, params);
  1313. if (node.nodeName == 'Folder')
  1314. addChildItemsFromNavData(node, item);
  1315. if (menu_name)
  1316. {
  1317. var menu_id = tree.a_custom_menu_ids[menu_name];
  1318. if (menu_id != undefined)
  1319. item.menu_id = menu_id;
  1320. }
  1321. }
  1322. }//for
  1323. redo_item(parent);
  1324. a_nodes = xmlNode.getElementsByTagName('Exception');
  1325. n_nodes = a_nodes.length;
  1326. if (n_nodes > 0)
  1327. {
  1328. var s = new Array();
  1329. var j = 0;
  1330. s[j++] = 'Exception';
  1331. if (n_nodes>1)
  1332. s[j++] = 's';
  1333. s[j++] = ' encountered:\n';
  1334. for (var i=0; i<n_nodes; i++)
  1335. {
  1336. var node = a_nodes[i];
  1337. var msg = get_xml_attrib(node, 'message', null);
  1338. if (msg)
  1339. {
  1340. var source = get_xml_attrib(node, 'source', null);
  1341. if (source)
  1342. {
  1343. s[j++] = source;
  1344. s[j++] = ': ';
  1345. }
  1346. s[j++] = msg;
  1347. s[j++] = '\n';
  1348. }
  1349. }
  1350. alert(s.join(''));
  1351. }
  1352. return n_children;
  1353. }
  1354. function toggle(n_id)
  1355. {
  1356. var o_item = this.get_item(n_id);
  1357. var b_expand = !o_item.b_expanded;
  1358. if (this.on_expanding && !this.on_expanding(o_item, b_expand))
  1359. return;
  1360. if (b_expand && o_item.b_load_on_demand)
  1361. {
  1362. if (o_item.a_children.length && !o_item.b_cache_children)
  1363. this.deleteAllChildren(o_item);
  1364. load_children_on_demand(o_item);
  1365. }
  1366. o_item.expand(b_expand);
  1367. //document.all['textarea'].value = document.all['tree_0'].outerHTML;
  1368. }
  1369. function set_popup_timer()
  1370. {
  1371. /*
  1372. if (this.timeoutId)
  1373. clearTimeout(this.timeoutId);
  1374. this.timeoutId = window.setTimeout('hide_popup_menu()', 2000);
  1375. */
  1376. }
  1377. function clear_popup_timer()
  1378. {
  1379. /*
  1380. if (this.timeoutId)
  1381. clearTimeout(this.timeoutId);
  1382. */
  1383. }
  1384. function hide_popup_menu()
  1385. {
  1386. if (ie)
  1387. {
  1388. if (parent.contextMenu && parent.contextMenu.isOpen)
  1389. parent.contextMenu.hide();
  1390. else
  1391. if (contextMenu && contextMenu.isOpen)
  1392. contextMenu.hide();
  1393. }
  1394. else
  1395. if (ns)
  1396. contextMenu.style.visibility = 'hidden';
  1397. }
  1398. function get_screen_coords(obj, xy)
  1399. {
  1400. if (obj == document.body)
  1401. {
  1402. xy[0] += window.screenLeft;
  1403. xy[1] += window.screenTop;
  1404. }
  1405. else
  1406. {
  1407. get_screen_coords(obj.parentNode, xy);
  1408. xy[0] += obj.offsetLeft;
  1409. xy[1] += obj.offsetTop;
  1410. }
  1411. }
  1412. function mouse_over_item(n_id)
  1413. {
  1414. if (!window.event)
  1415. return;
  1416. var item = this.get_item(n_id);
  1417. var img = document.getElementById('i_img' + this.n_tid + '_' + n_id);
  1418. var link = document.getElementById('i_txt' + this.n_tid + '_' + n_id);
  1419. var tree_div = document.getElementById('tree_' + this.n_tid);
  1420. var parentOfTree = tree_div.parentNode;
  1421. if (link.offsetLeft + link.offsetWidth > parentOfTree.offsetWidth)
  1422. {
  1423. var xy = [0, 0];
  1424. get_screen_coords(link, xy)
  1425. EnterContent('ToolTip',null, link.innerText, true);
  1426. Activate(null, xy[0], xy[1]);
  1427. }
  1428. else
  1429. deActivate();
  1430. /*
  1431. if (!contextMenu || !contextMenu.isOpen)
  1432. this.oncontextmenu(n_id);
  1433. else
  1434. {
  1435. this.select(n_id, e);
  1436. var popupBody = contextMenu.document.body;
  1437. contextMenu.show(link.offsetWidth, 0, popupBody.offsetWidth, popupBody.offsetHeight, link);
  1438. }
  1439. set_popup_timer();
  1440. */
  1441. item.upstatus(true);
  1442. }
  1443. function mouse_left_item(n_id)
  1444. {
  1445. if (!window.event)
  1446. return;
  1447. deActivate()
  1448. set_popup_timer();
  1449. this.get_item(n_id).upstatus();
  1450. }
  1451. var contextMenu = null;
  1452. var trees = [];