tree.js 48 KB

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