/* Copyright Scand LLC http://www.scbr.com This version of Software is free for using in non-commercial applications. For commercial use please contact info@scbr.com to obtain license */ function dhtmlXTreeObject(htmlObject,width,height,rootId){ this._isOpera=(navigator.userAgent.indexOf('Opera')!= -1); if(typeof(htmlObject)!="object") this.parentObject=document.getElementById(htmlObject); else this.parentObject=htmlObject; this.xmlstate=0; this.mytype="tree"; this.smcheck=true; this.width=width; this.height=height; this.rootId=rootId; this.childCalc=null; this.def_img_x="18px"; this.def_img_y="18px"; this.style_pointer="pointer"; if(navigator.appName == 'Microsoft Internet Explorer')this.style_pointer="hand"; this._aimgs=true; this.htmlcA=" ["; this.htmlcB="]"; this.lWin=window; this.cMenu=0; this.mlitems=0; this.dadmode=0; this.slowParse=false; this.autoScroll=true; this.hfMode=0; this.nodeCut=0; this.XMLsource=0; this.XMLloadingWarning=0; this._globalIdStorage=new Array(); this.globalNodeStorage=new Array(); this._globalIdStorageSize=0; this.treeLinesOn=true; this.checkFuncHandler=0; this.openFuncHandler=0; this.dblclickFuncHandler=0; this.tscheck=false; this.timgen=true; this.dpcpy=false; this.imPath="treeGfx/"; this.checkArray=new Array("iconUnCheckAll.gif","iconCheckAll.gif","iconCheckGray.gif","iconUncheckDis.gif"); this.lineArray=new Array("line2.gif","line3.gif","line4.gif","blank.gif","blank.gif"); this.minusArray=new Array("minus2.gif","minus3.gif","minus4.gif","minus.gif","minus5.gif"); this.plusArray=new Array("plus2.gif","plus3.gif","plus4.gif","plus.gif","plus5.gif"); this.imageArray=new Array("leaf.gif","folderOpen.gif","folderClosed.gif"); this.cutImg= new Array(0,0,0); this.cutImage="but_cut.gif"; this.dragger= new dhtmlDragAndDropObject(); this.htmlNode=new dhtmlXTreeItemObject(this.rootId,"",0,this); this.htmlNode.htmlNode.childNodes[0].childNodes[0].style.display="none"; this.htmlNode.htmlNode.childNodes[0].childNodes[0].childNodes[0].className="hiddenRow"; this.allTree=this._createSelf(); this.allTree.appendChild(this.htmlNode.htmlNode); this.allTree.onselectstart=new Function("return false;"); this.XMLLoader=new dtmlXMLLoaderObject(this._parseXMLTree,this); this.selectionBar=document.createElement("DIV"); this.selectionBar.className="selectionBar"; this.selectionBar.innerHTML=" "; if(this.allTree.offsetWidth>20)this.selectionBar.style.width=this.allTree.offsetWidth-20; this.selectionBar.style.display="none"; this.allTree.appendChild(this.selectionBar); return this; }; function dhtmlXTreeItemObject(itemId,itemText,parentObject,treeObject,actionHandler,mode){ this.htmlNode=""; this.acolor=""; this.scolor=""; this.tr=0; this.childsCount=0; this.tempDOMM=0; this.tempDOMU=0; this.dragSpan=0; this.dragMove=0; this.span=0; this.closeble=1; this.childNodes=new Array(); this.userData=new Object(); this.checkstate=0; this.treeNod=treeObject; this.label=itemText; this.parentObject=parentObject; this.actionHandler=actionHandler; this.images=new Array(treeObject.imageArray[0],treeObject.imageArray[1],treeObject.imageArray[2]); this.id=treeObject._globalIdStorageAdd(itemId,this); if(this.treeNod.checkBoxOff)this.htmlNode=this.treeNod._createItem(1,this,mode); else this.htmlNode=this.treeNod._createItem(0,this,mode); this.htmlNode.objBelong=this; return this; }; dhtmlXTreeObject.prototype._globalIdStorageAdd=function(itemId,itemObject){ if(this._globalIdStorageFind(itemId,1,1)){d=new Date();itemId=d.valueOf()+"_"+itemId;return this._globalIdStorageAdd(itemId,itemObject);} this._globalIdStorage[this._globalIdStorageSize]=itemId; this.globalNodeStorage[this._globalIdStorageSize]=itemObject; this._globalIdStorageSize++; return itemId; }; dhtmlXTreeObject.prototype._globalIdStorageSub=function(itemId){ for(var i=0;i0){beforeNode=new Object;beforeNode.tr=parentObject.childNodes[0].tr.previousSibling;} for(ik=0;ik=2) { this._correctPlus(Nodes[parentObject.childsCount-2]); this._correctLine(Nodes[parentObject.childsCount-2]); } if(parentObject.childsCount!=2)this._correctPlus(Nodes[0]); if(this.tscheck)this._correctCheckStates(parentObject); } if(this.cMenu)this.cMenu.setContextZone(Nodes[Count].span,Nodes[Count].id); return Nodes[Count]; }; dhtmlXTreeObject.prototype.insertNewItem=function(parentId,itemId,itemText,itemActionHandler,image1,image2,image3,optionStr,childs){ var parentObject=this._globalIdStorageFind(parentId); if(!parentObject)return(-1); return this._attachChildNode(parentObject,itemId,itemText,itemActionHandler,image1,image2,image3,optionStr,childs); }; dhtmlXTreeObject.prototype._parseXMLTree=function(dhtmlObject,node,parentId,level){ if(!dhtmlObject.parsCount)dhtmlObject.parsCount=1;else dhtmlObject.parsCount++; dhtmlObject.XMLloadingWarning=1; var nodeAskingCall=""; if(!node){ node=dhtmlObject.XMLLoader.getXMLTopNode("tree"); parentId=node.getAttribute("id"); dhtmlObject.parsingOn=parentId; dhtmlObject.parsedArray=new Array(); dhtmlObject.setCheckList=""; } if(node.getAttribute("order")) dhtmlObject._reorderXMLBranch(node); for(var i=0;i0){ for(var a=0;a1){ if(((Nodes[1].style.display!="none")||(mode==1))&&(mode!=2)){ this.allTree.childNodes[0].border = "1"; this.allTree.childNodes[0].border = "0"; nodestyle="none"; } else nodestyle=""; for(var i=1;ithis._getNodeLevel(nodeB,0)) { return this._moveNodeTo(itemObject,nodeA.parentObject); } else { return this._moveNodeTo(itemObject,nodeB.parentObject,nodeB); } } else return this._moveNodeTo(itemObject,targetObject); } dhtmlXTreeObject.prototype._fixNodesCollection=function(target,zParent){ var flag=0;var icount=0; var Nodes=target.childNodes; var Count=target.childsCount-1; if(zParent==Nodes[Count])return; for(var i=0;i=2) { this._correctPlus(Nodes[targetObject.childsCount-2]); this._correctLine(Nodes[targetObject.childsCount-2]); } this._correctPlus(Nodes[targetObject.childsCount-1]); if(this.tscheck)this._correctCheckStates(targetObject); if(oldTree.tscheck)oldTree._correctCheckStates(z); } if(c>1){oldTree._correctPlus(z.childNodes[c-2]); oldTree._correctLine(z.childNodes[c-2]); } oldTree._correctPlus(z); if(this.dropFunc)this.dropFunc(itemObject.id,targetObject.id,(beforeNode?beforeNode.id:null),itemObject.treeNod,targetObject.treeNod); return itemObject.id; }; dhtmlXTreeObject.prototype._checkParenNodes=function(itemId,htmlObject,shtmlObject){ if(shtmlObject){if(shtmlObject.parentObject.id==htmlObject.id)return 1;} if(htmlObject.id==itemId)return 1; if(htmlObject.parentObject)return this._checkParenNodes(itemId,htmlObject.parentObject);else return 0; }; dhtmlXTreeObject.prototype._clearStyles=function(itemObject){ var td1=itemObject.htmlNode.childNodes[0].childNodes[0].childNodes[1]; var td3=td1.nextSibling.nextSibling; itemObject.span.innerHTML=itemObject.label; if(this.checkBoxOff){td1.childNodes[0].style.display="";td1.childNodes[0].onclick=this.onCheckBoxClick;} else td1.childNodes[0].style.display="none"; td1.childNodes[0].treeNod=this; this.dragger.removeDraggableItem(td3); if(this.dragAndDropOff)this.dragger.addDraggableItem(td3,this); td3.childNodes[0].className="standartTreeRow"; td3.onclick=this.onRowSelect;td3.ondblclick=this.onRowClick2; td1.previousSibling.onclick=this.onRowClick; this._correctLine(itemObject); this._correctPlus(itemObject); for(var i=0;i0))) if(!htmlNode.nocheckbox){if(list)list+=","+htmlNode.id;else list=htmlNode.id;} var j=htmlNode.childsCount; for(var i=0;iz.childsCount))return null; return z.childNodes[index].id; }; dhtmlXTreeObject.prototype.getChildItemIdByIndex=function(itemId,index){ var z=this._globalIdStorageFind(itemId); if((!z)||(index>z.childsCount))return null; return z.childNodes[index].id; }; dhtmlXTreeObject.prototype.setDragHandler=function(func){if(typeof(func)=="function")this.dragFunc=func;else this.dragFunc=eval(func);}; dhtmlXTreeObject.prototype._clearMove=function(htmlNode){ if((htmlNode.parentObject)&&(htmlNode.parentObject.span)){ htmlNode.parentObject.span.className='standartTreeRow'; if(htmlNode.parentObject.acolor)htmlNode.parentObject.span.style.color=htmlNode.parentObject.acolor; } this.selectionBar.style.display="none"; this.allTree.className="containerTableStyle"; }; dhtmlXTreeObject.prototype.enableDragAndDrop=function(mode){ this.dragAndDropOff=convertStringToBoolean(mode); if(this.dragAndDropOff)this.dragger.addDragLanding(this.allTree,this); }; dhtmlXTreeObject.prototype._setMove=function(htmlNode,x,y){ if(htmlNode.parentObject.span){ var a1=getAbsoluteTop(htmlNode); var a2=getAbsoluteTop(this.allTree); this.dadmodec=this.dadmode; this.dadmodefix=0; if(this.dadmodec==0) { htmlNode.parentObject.span.className='selectedTreeRow'; if(htmlNode.parentObject.scolor)htmlNode.parentObject.span.style.color=htmlNode.parentObject.scolor; } else{ htmlNode.parentObject.span.className='standartTreeRow'; if(htmlNode.parentObject.acolor)htmlNode.parentObject.span.style.color=htmlNode.parentObject.acolor; this.selectionBar.style.top=a1-a2+16+this.dadmodefix; this.selectionBar.style.left=5; this.selectionBar.style.display=""; } if(this.autoScroll) { if((a1-a2-parseInt(this.allTree.scrollTop))>(parseInt(this.allTree.offsetHeight)-50)) this.allTree.scrollTop=parseInt(this.allTree.scrollTop)+20; if((a1-a2)<(parseInt(this.allTree.scrollTop)+30)) this.allTree.scrollTop=parseInt(this.allTree.scrollTop)-20; } } }; dhtmlXTreeObject.prototype._createDragNode=function(htmlObject){ dhtmlObject=htmlObject.parentObject; if(this.lastSelected)this._clearMove(this.lastSelected); var dragSpan=document.createElement('div'); dragSpan.innerHTML=dhtmlObject.label; dragSpan.style.position="absolute"; dragSpan.className="dragSpanDiv"; return dragSpan; } dhtmlXTreeObject.prototype._preventNsDrag=function(e){ if((e)&&(e.preventDefault)){e.preventDefault();return false;} return false; } dhtmlXTreeObject.prototype._drag=function(sourceHtmlObject,dhtmlObject,targetHtmlObject){ if(this._autoOpenTimer)clearTimeout(this._autoOpenTimer); if(!targetHtmlObject.parentObject){ targetHtmlObject=this.htmlNode.htmlNode.childNodes[0].childNodes[0].childNodes[1].childNodes[0]; this.dadmodec=0; } this._clearMove(targetHtmlObject); var z=targetHtmlObject.parentObject.treeNod; z._clearMove(""); if((!this.dragMove)||(this.dragMove())) { var newID=this._moveNode(sourceHtmlObject.parentObject,targetHtmlObject.parentObject); z.selectItem(newID); } try{} catch(e){ return; } } dhtmlXTreeObject.prototype._dragIn=function(htmlObject,shtmlObject,x,y){ if(!htmlObject.parentObject) { this.allTree.className="containerTableStyle selectionBox"; return htmlObject; } if((!this._checkParenNodes(shtmlObject.parentObject.id,htmlObject.parentObject,shtmlObject.parentObject))&&(htmlObject.parentObject.id!=shtmlObject.parentObject.id)) { htmlObject.parentObject.span.parentNode.appendChild(this.selectionBar); this._setMove(htmlObject,x,y); if(this._getOpenState(htmlObject.parentObject)<0) this._autoOpenTimer=window.setTimeout(new callerFunction(this._autoOpenItem,this),1000); this._autoOpenId=htmlObject.parentObject.id; return htmlObject; } else return 0; } dhtmlXTreeObject.prototype._autoOpenItem=function(e,treeObject){ treeObject.openItem(treeObject._autoOpenId); }; dhtmlXTreeObject.prototype._dragOut=function(htmlObject){ this._clearMove(htmlObject); if(this._autoOpenTimer)clearTimeout(this._autoOpenTimer); } dhtmlXTreeObject.prototype._getNextNode=function(item,mode){ if((!mode)&&(item.childsCount))return item.childNodes[0]; if(item==this.htmlNode) return -1; if((item.tr)&&(item.tr.nextSibling)&&(item.tr.nextSibling.nodem)) return item.tr.nextSibling.nodem; return this._getNextNode(item.parentObject,true); }; dhtmlXTreeObject.prototype._lastChild=function(item){ if(item.childsCount) return this._lastChild(item.childNodes[item.childsCount-1]); else return item; }; dhtmlXTreeObject.prototype._getPrevNode=function(node,mode){ if((node.tr)&&(node.tr.previousSibling)&&(node.tr.previousSibling.nodem)) return this._lastChild(node.tr.previousSibling.nodem); if(node.parentObject) return node.parentObject; else return -1; };