/*--------------------------------------------------| | dTree 2.05 | www.destroydrop.com/javascript/tree/ | |---------------------------------------------------| | Copyright (c) 2002-2003 Geir Landr? | | | | This script can be used freely as long as all | | copyright messages are intact. | | | | Updated: 17.04.2003 | |--------------------------------------------------*/ // Node object function Node(id, pid, name, checked ,url, title, target, icon, iconOpen, open,mktype) { this.id = id; this.pid = pid; this.name = name; this.mktype = url; this.url = url; this.title = title; this.target = target; this.icon = icon; this.iconOpen = iconOpen; this._io = open || false; this._is = false; this._ls = false; this._hc = false; this._ai = 0; this._p; this.checked = checked;//add by zhangwei }; // Tree object function dTree(objName, iPath, formId) { this.config = { target : null, folderLinks : true, useSelection : true, useCookies : true, useLines : true, useIcons : false, useCheckBox : true, useStatusText : false, closeSameLevel : false, inOrder : false } this.icon = { root : '../dtree/img/base.gif', folder : '../dtree/img/folder.gif', folderOpen : '../dtree/img/folderopen.gif', node : '../dtree/img/page.gif', empty : '../dtree/img/empty.gif', line : '../dtree/img/line.gif', join : '../dtree/img/join.gif', joinBottom : '../dtree/img/joinbottom.gif', plus : '../dtree/img/plus.gif', plusBottom : '../dtree/img/plusbottom.gif', minus : '../dtree/img/minus.gif', minusBottom : '../dtree/img/minusbottom.gif', nlPlus : '../dtree/img/nolines_plus.gif', nlMinus : '../dtree/img/nolines_minus.gif' }; this.parEnum = ""; this.obj = objName; this.aNodes = []; this.aIndent = []; this.root = new Node(-1); this.selectedNode = null; this.selectedFound = false; this.completed = false; this.formId = (formId==null)?"dTreeForm":formId; }; // Adds a new node to the node array dTree.prototype.add = function(id, pid, name, checked, url, title, target, icon, iconOpen, open) { this.aNodes[this.aNodes.length] = new Node(id, pid, name, checked, url, title, target, icon, iconOpen, open); }; // Open/close all nodes dTree.prototype.openAll = function() { this.oAll(true); }; dTree.prototype.closeAll = function() { this.oAll(false); }; // Outputs the tree to the page dTree.prototype.toString = function() { var str = '
\n'; if (document.getElementById) { if (this.config.useCookies) this.selectedNode = this.getSelected(); str += this.addNode(this.root); } else str += 'Browser not supported.'; str += '
'; //document.getElementById("test").value = str; //alert(str); if (!this.selectedFound) this.selectedNode = null; this.completed = true; return str; }; // Creates the tree structure dTree.prototype.addNode = function(pNode) { var str = ''; var n=0; if (this.config.inOrder) n = pNode._ai; for (n; n' + this.indent(node, nodeId); if (this.config.useIcons) { if (!node.icon) node.icon = (this.root.id == node.pid) ? this.icon.root : ((node._hc) ? this.icon.folder : this.icon.node); if (!node.iconOpen) node.iconOpen = (node._hc) ? this.icon.folderOpen : this.icon.node; if (this.root.id == node.pid) { node.icon = this.icon.root; node.iconOpen = this.icon.root; } str += ''; } if(this.config.useCheckBox && nodeId!=0){ if(node.pid==0){ this.parEnum += node.id + "-"; } else{ //alert("parEnum1 = " + this.parEnum + "node id = " + node.pid); var pL = this.parEnum.indexOf(node.pid+"-"); //alert(this.parEnum.substring(0,pL+(node.pid+"-").length)) this.parEnum = this.parEnum.substring(0,pL+(node.pid+"-").length) + node.id + "-"; //alert("parEnum2 = " + this.parEnum); } //name='mkid',此处name的内容根据具体需要修改,add by zhangwei str += ''; } if (node.url) { str += ''; str += node.name; if (node.url || ((!this.config.folderLinks || !node.url) && node._hc)) str += ''; str += ''; if (node._hc) { str += '
'; str += this.addNode(node); str += '
'; } this.aIndent.pop(); return str; }; // Adds the empty and line icons dTree.prototype.indent = function(node, nodeId) { var str = ''; if (this.root.id != node.pid) { for (var n=0; n'; (node._ls) ? this.aIndent.push(0) : this.aIndent.push(1); if (node._hc) { str += ''; } else str += ''; } return str; }; // Checks if a node has any children and if it is the last sibling dTree.prototype.setCS = function(node) { var lastId; for (var n=0; n