| dojo.provide("dojo.widget.TreeNode"); |
| dojo.require("dojo.html.*"); |
| dojo.require("dojo.event.*"); |
| dojo.require("dojo.io.*"); |
| dojo.widget.defineWidget("dojo.widget.TreeNode",dojo.widget.HtmlWidget,function(){ |
| this.actionsDisabled=[]; |
| },{widgetType:"TreeNode",loadStates:{UNCHECKED:"UNCHECKED",LOADING:"LOADING",LOADED:"LOADED"},actions:{MOVE:"MOVE",REMOVE:"REMOVE",EDIT:"EDIT",ADDCHILD:"ADDCHILD"},isContainer:true,lockLevel:0,templateString:("<div class=\"dojoTreeNode\"> "+"<span treeNode=\"${this.widgetId}\" class=\"dojoTreeNodeLabel\" dojoAttachPoint=\"labelNode\"> "+"\t\t<span dojoAttachPoint=\"titleNode\" dojoAttachEvent=\"onClick: onTitleClick\" class=\"dojoTreeNodeLabelTitle\">${this.title}</span> "+"</span> "+"<span class=\"dojoTreeNodeAfterLabel\" dojoAttachPoint=\"afterLabelNode\">${this.afterLabel}</span> "+"<div dojoAttachPoint=\"containerNode\" style=\"display:none\"></div> "+"</div>").replace(/(>|<)\s+/g,"$1"),childIconSrc:"",childIconFolderSrc:dojo.uri.moduleUri("dojo.widget","templates/images/Tree/closed.gif"),childIconDocumentSrc:dojo.uri.moduleUri("dojo.widget","templates/images/Tree/document.gif"),childIcon:null,isTreeNode:true,objectId:"",afterLabel:"",afterLabelNode:null,expandIcon:null,title:"",object:"",isFolder:false,labelNode:null,titleNode:null,imgs:null,expandLevel:"",tree:null,depth:0,isExpanded:false,state:null,domNodeInitialized:false,isFirstChild:function(){ |
| return this.getParentIndex()==0?true:false; |
| },isLastChild:function(){ |
| return this.getParentIndex()==this.parent.children.length-1?true:false; |
| },lock:function(){ |
| return this.tree.lock.apply(this,arguments); |
| },unlock:function(){ |
| return this.tree.unlock.apply(this,arguments); |
| },isLocked:function(){ |
| return this.tree.isLocked.apply(this,arguments); |
| },cleanLock:function(){ |
| return this.tree.cleanLock.apply(this,arguments); |
| },actionIsDisabled:function(_1){ |
| var _2=this; |
| var _3=false; |
| if(this.tree.strictFolders&&_1==this.actions.ADDCHILD&&!this.isFolder){ |
| _3=true; |
| } |
| if(dojo.lang.inArray(_2.actionsDisabled,_1)){ |
| _3=true; |
| } |
| if(this.isLocked()){ |
| _3=true; |
| } |
| return _3; |
| },getInfo:function(){ |
| var _4={widgetId:this.widgetId,objectId:this.objectId,index:this.getParentIndex(),isFolder:this.isFolder}; |
| return _4; |
| },initialize:function(_5,_6){ |
| this.state=this.loadStates.UNCHECKED; |
| for(var i=0;i<this.actionsDisabled.length;i++){ |
| this.actionsDisabled[i]=this.actionsDisabled[i].toUpperCase(); |
| } |
| this.expandLevel=parseInt(this.expandLevel); |
| },adjustDepth:function(_8){ |
| for(var i=0;i<this.children.length;i++){ |
| this.children[i].adjustDepth(_8); |
| } |
| this.depth+=_8; |
| if(_8>0){ |
| for(var i=0;i<_8;i++){ |
| var _a=this.tree.makeBlankImg(); |
| this.imgs.unshift(_a); |
| dojo.html.insertBefore(this.imgs[0],this.domNode.firstChild); |
| } |
| } |
| if(_8<0){ |
| for(var i=0;i<-_8;i++){ |
| this.imgs.shift(); |
| dojo.html.removeNode(this.domNode.firstChild); |
| } |
| } |
| },markLoading:function(){ |
| this._markLoadingSavedIcon=this.expandIcon.src; |
| this.expandIcon.src=this.tree.expandIconSrcLoading; |
| },unMarkLoading:function(){ |
| if(!this._markLoadingSavedIcon){ |
| return; |
| } |
| var im=new Image(); |
| im.src=this.tree.expandIconSrcLoading; |
| if(this.expandIcon.src==im.src){ |
| this.expandIcon.src=this._markLoadingSavedIcon; |
| } |
| this._markLoadingSavedIcon=null; |
| },setFolder:function(){ |
| dojo.event.connect(this.expandIcon,"onclick",this,"onTreeClick"); |
| this.expandIcon.src=this.isExpanded?this.tree.expandIconSrcMinus:this.tree.expandIconSrcPlus; |
| this.isFolder=true; |
| },createDOMNode:function(_c,_d){ |
| this.tree=_c; |
| this.depth=_d; |
| this.imgs=[]; |
| for(var i=0;i<this.depth+1;i++){ |
| var _f=this.tree.makeBlankImg(); |
| this.domNode.insertBefore(_f,this.labelNode); |
| this.imgs.push(_f); |
| } |
| this.expandIcon=this.imgs[this.imgs.length-1]; |
| this.childIcon=this.tree.makeBlankImg(); |
| this.imgs.push(this.childIcon); |
| dojo.html.insertBefore(this.childIcon,this.titleNode); |
| if(this.children.length||this.isFolder){ |
| this.setFolder(); |
| }else{ |
| this.state=this.loadStates.LOADED; |
| } |
| dojo.event.connect(this.childIcon,"onclick",this,"onIconClick"); |
| for(var i=0;i<this.children.length;i++){ |
| this.children[i].parent=this; |
| var _10=this.children[i].createDOMNode(this.tree,this.depth+1); |
| this.containerNode.appendChild(_10); |
| } |
| if(this.children.length){ |
| this.state=this.loadStates.LOADED; |
| } |
| this.updateIcons(); |
| this.domNodeInitialized=true; |
| dojo.event.topic.publish(this.tree.eventNames.createDOMNode,{source:this}); |
| return this.domNode; |
| },onTreeClick:function(e){ |
| dojo.event.topic.publish(this.tree.eventNames.treeClick,{source:this,event:e}); |
| },onIconClick:function(e){ |
| dojo.event.topic.publish(this.tree.eventNames.iconClick,{source:this,event:e}); |
| },onTitleClick:function(e){ |
| dojo.event.topic.publish(this.tree.eventNames.titleClick,{source:this,event:e}); |
| },markSelected:function(){ |
| dojo.html.addClass(this.titleNode,"dojoTreeNodeLabelSelected"); |
| },unMarkSelected:function(){ |
| dojo.html.removeClass(this.titleNode,"dojoTreeNodeLabelSelected"); |
| },updateExpandIcon:function(){ |
| if(this.isFolder){ |
| this.expandIcon.src=this.isExpanded?this.tree.expandIconSrcMinus:this.tree.expandIconSrcPlus; |
| }else{ |
| this.expandIcon.src=this.tree.blankIconSrc; |
| } |
| },updateExpandGrid:function(){ |
| if(this.tree.showGrid){ |
| if(this.depth){ |
| this.setGridImage(-2,this.isLastChild()?this.tree.gridIconSrcL:this.tree.gridIconSrcT); |
| }else{ |
| if(this.isFirstChild()){ |
| this.setGridImage(-2,this.isLastChild()?this.tree.gridIconSrcX:this.tree.gridIconSrcY); |
| }else{ |
| this.setGridImage(-2,this.isLastChild()?this.tree.gridIconSrcL:this.tree.gridIconSrcT); |
| } |
| } |
| }else{ |
| this.setGridImage(-2,this.tree.blankIconSrc); |
| } |
| },updateChildGrid:function(){ |
| if((this.depth||this.tree.showRootGrid)&&this.tree.showGrid){ |
| this.setGridImage(-1,(this.children.length&&this.isExpanded)?this.tree.gridIconSrcP:this.tree.gridIconSrcC); |
| }else{ |
| if(this.tree.showGrid&&!this.tree.showRootGrid){ |
| this.setGridImage(-1,(this.children.length&&this.isExpanded)?this.tree.gridIconSrcZ:this.tree.blankIconSrc); |
| }else{ |
| this.setGridImage(-1,this.tree.blankIconSrc); |
| } |
| } |
| },updateParentGrid:function(){ |
| var _14=this.parent; |
| for(var i=0;i<this.depth;i++){ |
| var idx=this.imgs.length-(3+i); |
| var img=(this.tree.showGrid&&!_14.isLastChild())?this.tree.gridIconSrcV:this.tree.blankIconSrc; |
| this.setGridImage(idx,img); |
| _14=_14.parent; |
| } |
| },updateExpandGridColumn:function(){ |
| if(!this.tree.showGrid){ |
| return; |
| } |
| var _18=this; |
| var _19=this.isLastChild()?this.tree.blankIconSrc:this.tree.gridIconSrcV; |
| dojo.lang.forEach(_18.getDescendants(),function(_1a){ |
| _1a.setGridImage(_18.depth,_19); |
| }); |
| this.updateExpandGrid(); |
| },updateIcons:function(){ |
| this.imgs[0].style.display=this.tree.showRootGrid?"inline":"none"; |
| this.buildChildIcon(); |
| this.updateExpandGrid(); |
| this.updateChildGrid(); |
| this.updateParentGrid(); |
| dojo.profile.stop("updateIcons"); |
| },buildChildIcon:function(){ |
| if(this.childIconSrc){ |
| this.childIcon.src=this.childIconSrc; |
| } |
| this.childIcon.style.display=this.childIconSrc?"inline":"none"; |
| },setGridImage:function(idx,src){ |
| if(idx<0){ |
| idx=this.imgs.length+idx; |
| } |
| this.imgs[idx].style.backgroundImage="url("+src+")"; |
| },updateIconTree:function(){ |
| this.tree.updateIconTree.call(this); |
| },expand:function(){ |
| if(this.isExpanded){ |
| return; |
| } |
| if(this.children.length){ |
| this.showChildren(); |
| } |
| this.isExpanded=true; |
| this.updateExpandIcon(); |
| dojo.event.topic.publish(this.tree.eventNames.expand,{source:this}); |
| },collapse:function(){ |
| if(!this.isExpanded){ |
| return; |
| } |
| this.hideChildren(); |
| this.isExpanded=false; |
| this.updateExpandIcon(); |
| dojo.event.topic.publish(this.tree.eventNames.collapse,{source:this}); |
| },hideChildren:function(){ |
| this.tree.toggleObj.hide(this.containerNode,this.toggleDuration,this.explodeSrc,dojo.lang.hitch(this,"onHide")); |
| if(dojo.exists(dojo,"dnd.dragManager.dragObjects")&&dojo.dnd.dragManager.dragObjects.length){ |
| dojo.dnd.dragManager.cacheTargetLocations(); |
| } |
| },showChildren:function(){ |
| this.tree.toggleObj.show(this.containerNode,this.toggleDuration,this.explodeSrc,dojo.lang.hitch(this,"onShow")); |
| if(dojo.exists(dojo,"dnd.dragManager.dragObjects")&&dojo.dnd.dragManager.dragObjects.length){ |
| dojo.dnd.dragManager.cacheTargetLocations(); |
| } |
| },addChild:function(){ |
| return this.tree.addChild.apply(this,arguments); |
| },doAddChild:function(){ |
| return this.tree.doAddChild.apply(this,arguments); |
| },edit:function(_1d){ |
| dojo.lang.mixin(this,_1d); |
| if(_1d.title){ |
| this.titleNode.innerHTML=this.title; |
| } |
| if(_1d.afterLabel){ |
| this.afterLabelNode.innerHTML=this.afterLabel; |
| } |
| if(_1d.childIconSrc){ |
| this.buildChildIcon(); |
| } |
| },removeNode:function(){ |
| return this.tree.removeNode.apply(this,arguments); |
| },doRemoveNode:function(){ |
| return this.tree.doRemoveNode.apply(this,arguments); |
| },toString:function(){ |
| return "["+this.widgetType+" Tree:"+this.tree+" ID:"+this.widgetId+" Title:"+this.title+"]"; |
| }}); |