/*############################################################################## # HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ############################################################################## */ //-------------------------------------- // All browser specific code goes here function createXmlHttpRequestObject() { var xmlhttp = null; // code for Mozilla, etc. if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } // code for IE else if (window.ActiveXObject) { try { xmlhttp=new ActiveXObject("Msxml2.XMLHTTP.4.0"); } catch (e) { try { xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } } } if (xmlhttp == null) alert("Can not create XMLHttpRequest object in your browser!"); return xmlhttp; } get_element = function(s_id) { return document.all ? document.all[s_id] : document.getElementById(s_id) }; function createXmlDomObject() { var xmlDom = null; if (window.ActiveXObject) { xmlDom = new ActiveXObject("Microsoft.XMLDOM"); } else if (document.implementation && document.implementation.createDocument) { xmlDom = document.implementation.createDocument("","",null); } if (xmlDom == null) alert("Can not create XML DOM object in your browser!"); return xmlDom; } // emulate IE selectNodes(), selectSingleNode() if(document.implementation && document.implementation.hasFeature("XPath", "3.0")) { // NodeList function XmlNodeList(i) { this.length = i; } XmlNodeList.prototype = new Array(0); XmlNodeList.prototype.constructor = Array; XmlNodeList.prototype.item = function(i) { return (i < 0 || i >= this.length)?null:this[i]; }; XmlNodeList.prototype.expr = ""; XMLDocument.prototype.setProperty = function(x,y){}; // IE: XMLDocument.selectNodes() XMLDocument.prototype.selectNodes = function(sExpr, contextNode){ var nsDoc = this; var nsResolver = this.createNSResolver(this.documentElement); var oResult = this.evaluate(sExpr, (contextNode?contextNode:this), nsResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); var nodeList = new XmlNodeList(oResult.snapshotLength); nodeList.expr = sExpr; for(var i=0;i 0) return nodeList.item(0); else return null; } // IE: Element.selectSingleNode() Element.prototype.selectSingleNode = function(sExpr){ var doc = this.ownerDocument; if(doc.selectSingleNode) return doc.selectSingleNode(sExpr, this); else throw "Method selectNodes is only supported by XML Elements"; } } function serializeDomNode(xmlDoc) { if (xmlDoc.xml) { return xmlDoc.xml; } else if(window.XMLSerializer) { return (new XMLSerializer()).serializeToString(xmlDoc); } return null; } // END: browser specific code //-------------------------------------- var ie = document.all ? 1 : 0; var ns = document.layers ? 1 : 0; /* - multiple selection - ability to dynamically add items - context menu with both item and tree specific commands - ability to add on_sel_changed, on_insert_child and on_expanding handlers - find xpaths for items and find items with given xpaths - demand loading of children - custom menus for individual items */ function tree (a_items, a_template) { this.n_tid = trees.length; trees[this.n_tid] = this; this.a_tpl = a_template; this.a_config = a_items; this.o_root = this; this.a_index = []; this.a_selected = []; this.a_deleted = []; this.b_selected = false; this.n_depth = -1; this.select_all = select_all; this.select_none= select_none; this.upstatus = function() {};//nothing this.o_parent = null; this.a_custom_menus = []; this.a_custom_menu_ids = []; this.n_items = 0; this.b_cache_children = true; this.get_item = function(id) { return this.a_index[id]; }; this.item_count = function() { return this.n_items; }; this.get_first_item = get_first_item; this.get_next_item = get_next_item; this.deleteAllChildren = deleteAllChildren; this.action = null; this.border = null; this.a_columns= null; this.a_columnWidths = null; this.add_tree_column = add_tree_column; this.timeoutId = 0; var o_icone = new Image(); var o_iconl = new Image(); o_icone.src = a_template['icon_e']; o_iconl.src = a_template['icon_l']; a_template['im_e'] = o_icone; a_template['im_l'] = o_iconl; for (var i = 0; i < 64; i++) if (a_template['icon_' + i]) { var o_icon = new Image(); a_template['im_' + i] = o_icon; o_icon.src = a_template['icon_' + i]; } this.expand = item_expand; this.toggle = toggle; this.select = function (n_id, e, treeid) { return this.get_item(n_id).select(e, treeid); }; this.mover = mouse_over_item; this.mout = mouse_left_item; this.oncontextmenu = function (n_id, e, treeid) { return this.get_item(n_id).oncontextmenu(e, treeid) }; this.show_context_menu = show_context_menu; this.handle_command = handle_command; this.on_sel_changed = null; this.on_expanding = null; this.on_context_menu= null; this.on_command = null; this.get_custom_menu = function(menu_name) { var index = this.a_custom_menu_ids[menu_name]; return (index != undefined) ? this.a_custom_menus[index] : null; } this.add_custom_menu = function(menu_name, a_menu) { if (!this.get_custom_menu(menu_name)) { var index = this.a_custom_menus.length; this.a_custom_menus[index] = a_menu; this.a_custom_menu_ids[menu_name] = index; } return index; } this.a_children = []; for (var i = 0; i < a_items.length; i++) new tree_item(this, i, this.a_config[i + (this.n_depth + 1 ? 2 : 0)]); var n_children = this.a_children.length; if (n_children) { var div = document.getElementById('tree_' + this.n_tid); var a_html = []; for (var i=0; i 0)//reclaim a previously deleted id this.n_id = this.o_root.a_deleted.shift(); else this.n_id = this.o_root.item_count(); //a_children is contiguous so pick next index this.o_root.a_index[this.n_id] = this; this.o_root.n_items++; o_parent.a_children[n_position] = this; this.a_children = []; for (var i = 0; i < this.a_config.length - 2; i++) new tree_item(this, i, this.a_config[i + (this.n_depth + 1 ? 2 : 0)]); this.get_icon = item_get_icon; this.expand = item_expand; this.select = handle_selection; this.init = item_init; this.upstatus = item_upstatus; this.oncontextmenu=context_menu; this.name = function () { return this.a_config[0]; } this.data = null; this.on_insert_child= null; this.is_last = function () { return this.n_position == this.o_parent.a_children.length - 1 }; if (o_parent.on_insert_child) o_parent.on_insert_child(this); } function item_init () { var o_tree = this.o_root; var treeId = o_tree.n_tid; var itemId = this.n_id; var tree = 'trees[' + treeId + ']'; var s = []; var i = 0; s[i++] = ' 1; j--) { s[j+i] = ''; o_current_item = o_current_item.o_parent; } i = s.length; if (this.b_load_on_demand || this.a_children.length) { s[i++] = ''; } else { s[i++] = ''; } } if (this.b_checkbox) { s[i++] = '' : ''); for (var i=0; i'); if (bCaption) { var innerHTML = column['innerHTML']; if (typeof innerHTML != 'undefined') a_html.push(innerHTML); } a_html.push(bCaption ? '' : ''); } a_html.push(bCaption ? '
' : ''); return a_html.join(''); } function redo_item(item) { var o_tree = item.o_root; if (item == o_tree) { var a_html = []; var n_children = item.a_children.length; for (var i = 0; i < n_children; i++) { var child = item.a_children[i]; a_html[i] = child.init(); child.expand(); } var div = get_element('tree_'+item.n_tid); if (o_tree.a_columns) { a_html.unshift(get_column_header_html(item, true)); var width = 0; var n_columns = o_tree.a_columns.length for (i=0; i 0) { var size = this.a_children.length; for (var i = item_id+1; i 1 || (n_selected==1 && !this.b_selected)) o_tree.select_none(); } if (b_select != this.b_selected) { if (b_select) o_tree.a_selected.push(this); else { //delete this object from the root's a_selected array var n_selected = o_tree.a_selected.length; for (var i=0; i0) s[i++] = ''; s[i++] = ' tag s[i++] = ' '; s[i++] = caption; } s[i++] = ''; } else horizLine = true; var numColumns = columns > itemsPerLine ? itemsPerLine : columns; if (popup_caption) s[iCaption] = '' + popup_caption + '
'; if (addCloseButton) s[i++] = '
' + '' + '' s[i++] =''; //alert(s); var xypos = YAHOO.util.Dom.getXY(treeid); xypos[0] = 0; if (oMenu) { oMenu.destroy(); } oMenu = new YAHOO.widget.Menu("treemenu", { position: "dynamic", xy: xypos }); oMenu.clearContent(); menuItems = null; menuItems = new Array(); for (var item in menu) { if (menu[item]) { var menuItem = menu[item]; var ocmd = menuItem[0]; var oaction = menuItem[1]; var ocaption = menuItem[2] ? menuItem[2] : menuItem[0]; var ohandler = menuItem[3] ? menuItem[3] : 'trees[' + this.o_root.n_tid + '].handle_command'; 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 }; } } function context_Menu_Select(Menu_Index) { trees[menuItems[Menu_Index].treeid].handle_command(menuItems[Menu_Index].treeid, menuItems[Menu_Index].itemid, menuItems[Menu_Index].command, menuItems[Menu_Index].action); } oMenu.addItems(menuItems); oMenu.render("menu"); oMenu.show(); return; } function test () { alert('test'); } /* this function takes a string of the form "prefix{javascript}suffix" and returns prefixXYZsuffix, where XYZ is the result of execution of javascript within braces after any 'this' occurrences have been substituted with 'item'. Multiple {javascript} blocks may be embedded within the string. */ /* unused for now... function process_embedded_scripts(url, item) { if (url.length == 0) return ''; var open_brace = url.indexOf('{'); if (open_brace == -1) return url; var close_brace = url.indexOf('}', open_brace+1); if (close_brace == -1) close_brace = url.length+1; var raw_script = url.substring(open_brace+1, close_brace); var output; if (raw_script.length) { var script = raw_script.replace('this.', 'item.'); var Fn = new Function('item', 'return ' + script); output = Fn(item); } return url.substring(0, open_brace) + output + process_embedded_scripts( url.substring(close_brace+1), item ); } */ function addToXmlDoc(xmlDoc, item) { if (item.o_parent == item.o_root) parentNode = xmlDoc.documentElement; else parentNode = addToXmlDoc(xmlDoc, item.o_parent); var name = item.name(); var node = parentNode.selectSingleNode( "*[@name='"+name+"']" ); if (!node) { var nodeName = item.b_load_on_demand ? 'DynamicFolder' : (item.a_children.length ? 'Folder' : 'Link'); node = xmlDoc.createElement( nodeName ); parentNode.appendChild(node); var attr = xmlDoc.createAttribute("name"); attr.value = name; node.setAttributeNode(attr); if (item.params) { attr = xmlDoc.createAttribute("params"); //attr.value = escape(item.params); attr.value = item.params; node.setAttributeNode(attr); } } return node; } function selectionToXmlDoc(tree) { var xmlDoc = createXmlDomObject(); var docElement = xmlDoc.createElement('EspNavigationData'); xmlDoc.appendChild(docElement); xmlDoc.async="false"; var nSelected = tree.o_root.a_selected.length; for (var i=0; i */ function addChildItemsFromNavData(xmlNode, parent) { var tree = parent.o_root; var a_nodes = xmlNode.getElementsByTagName('Menu'); var n_nodes = a_nodes.length; for (var i=0; i 0) { var s = new Array(); var j = 0; s[j++] = 'Exception'; if (n_nodes>1) s[j++] = 's'; s[j++] = ' encountered:\n'; for (var i=0; i parentOfTree.offsetWidth) { var xy = [0, 0]; get_screen_coords(link, xy) EnterContent('ToolTip',null, link.innerText, true); Activate(null, xy[0], xy[1]); } else deActivate(); /* if (!contextMenu || !contextMenu.isOpen) this.oncontextmenu(n_id); else { this.select(n_id, e); var popupBody = contextMenu.document.body; contextMenu.show(link.offsetWidth, 0, popupBody.offsetWidth, popupBody.offsetHeight, link); } set_popup_timer(); */ item.upstatus(true); } function mouse_left_item(n_id) { if (!window.event) return; deActivate() set_popup_timer(); this.get_item(n_id).upstatus(); } var contextMenu = null; var trees = [];