root / trunk / web / dojo / dijit / Tree.js @ 10
History | View | Annotate | Download (19.7 KB)
| 1 |
/*
|
|---|---|
| 2 |
Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
| 3 |
Available via Academic Free License >= 2.1 OR the modified BSD license.
|
| 4 |
see: http://dojotoolkit.org/license for details
|
| 5 |
*/
|
| 6 |
|
| 7 |
|
| 8 |
if(!dojo._hasResource["dijit.Tree"]){ |
| 9 |
dojo._hasResource["dijit.Tree"]=true; |
| 10 |
dojo.provide("dijit.Tree");
|
| 11 |
dojo.require("dojo.fx");
|
| 12 |
dojo.require("dojo.DeferredList");
|
| 13 |
dojo.require("dijit._Widget");
|
| 14 |
dojo.require("dijit._Templated");
|
| 15 |
dojo.require("dijit._Container");
|
| 16 |
dojo.require("dijit._Contained");
|
| 17 |
dojo.require("dijit._CssStateMixin");
|
| 18 |
dojo.require("dojo.cookie");
|
| 19 |
dojo.declare("dijit._TreeNode",[dijit._Widget,dijit._Templated,dijit._Container,dijit._Contained,dijit._CssStateMixin],{item:null,isTreeNode:true,label:"",isExpandable:null,isExpanded:false,state:"UNCHECKED",templateString:dojo.cache("dijit","templates/TreeNode.html","<div class=\"dijitTreeNode\" waiRole=\"presentation\"\n\t><div dojoAttachPoint=\"rowNode\" class=\"dijitTreeRow\" waiRole=\"presentation\" dojoAttachEvent=\"onmouseenter:_onMouseEnter, onmouseleave:_onMouseLeave, onclick:_onClick, ondblclick:_onDblClick\"\n\t\t><img src=\"${_blankGif}\" alt=\"\" dojoAttachPoint=\"expandoNode\" class=\"dijitTreeExpando\" waiRole=\"presentation\"\n\t\t/><span dojoAttachPoint=\"expandoNodeText\" class=\"dijitExpandoText\" waiRole=\"presentation\"\n\t\t></span\n\t\t><span dojoAttachPoint=\"contentNode\"\n\t\t\tclass=\"dijitTreeContent\" waiRole=\"presentation\">\n\t\t\t<img src=\"${_blankGif}\" alt=\"\" dojoAttachPoint=\"iconNode\" class=\"dijitIcon dijitTreeIcon\" waiRole=\"presentation\"\n\t\t\t/><span dojoAttachPoint=\"labelNode\" class=\"dijitTreeLabel\" wairole=\"treeitem\" tabindex=\"-1\" waiState=\"selected-false\" dojoAttachEvent=\"onfocus:_onLabelFocus\"></span>\n\t\t</span\n\t></div>\n\t<div dojoAttachPoint=\"containerNode\" class=\"dijitTreeContainer\" waiRole=\"presentation\" style=\"display: none;\"></div>\n</div>\n"),baseClass:"dijitTreeNode",cssStateNodes:{rowNode:"dijitTreeRow",labelNode:"dijitTreeLabel"},attributeMap:dojo.delegate(dijit._Widget.prototype.attributeMap,{label:{node:"labelNode",type:"innerText"},tooltip:{node:"rowNode",type:"attribute",attribute:"title"}}),postCreate:function(){ |
| 20 |
this.inherited(arguments); |
| 21 |
this._setExpando();
|
| 22 |
this._updateItemClasses(this.item); |
| 23 |
if(this.isExpandable){ |
| 24 |
dijit.setWaiState(this.labelNode,"expanded",this.isExpanded); |
| 25 |
} |
| 26 |
},_setIndentAttr:function(_1){ |
| 27 |
this.indent=_1;
|
| 28 |
var _2=(Math.max(_1,0)*this.tree._nodePixelIndent)+"px"; |
| 29 |
dojo.style(this.domNode,"backgroundPosition",_2+" 0px"); |
| 30 |
dojo.style(this.rowNode,this.isLeftToRight()?"paddingLeft":"paddingRight",_2); |
| 31 |
dojo.forEach(this.getChildren(),function(_3){ |
| 32 |
_3.set("indent",_1+1); |
| 33 |
}); |
| 34 |
},markProcessing:function(){ |
| 35 |
this.state="LOADING"; |
| 36 |
this._setExpando(true); |
| 37 |
},unmarkProcessing:function(){ |
| 38 |
this._setExpando(false); |
| 39 |
},_updateItemClasses:function(_4){ |
| 40 |
var _5=this.tree,_6=_5.model; |
| 41 |
if(_5._v10Compat&&_4===_6.root){
|
| 42 |
_4=null;
|
| 43 |
} |
| 44 |
this._applyClassAndStyle(_4,"icon","Icon"); |
| 45 |
this._applyClassAndStyle(_4,"label","Label"); |
| 46 |
this._applyClassAndStyle(_4,"row","Row"); |
| 47 |
},_applyClassAndStyle:function(_7,_8,_9){ |
| 48 |
var _a="_"+_8+"Class"; |
| 49 |
var _b=_8+"Node"; |
| 50 |
if(this[_a]){ |
| 51 |
dojo.removeClass(this[_b],this[_a]); |
| 52 |
} |
| 53 |
this[_a]=this.tree["get"+_9+"Class"](_7,this.isExpanded); |
| 54 |
if(this[_a]){ |
| 55 |
dojo.addClass(this[_b],this[_a]); |
| 56 |
} |
| 57 |
dojo.style(this[_b],this.tree["get"+_9+"Style"](_7,this.isExpanded)||{}); |
| 58 |
},_updateLayout:function(){ |
| 59 |
var _c=this.getParent(); |
| 60 |
if(!_c||_c.rowNode.style.display=="none"){ |
| 61 |
dojo.addClass(this.domNode,"dijitTreeIsRoot"); |
| 62 |
}else{
|
| 63 |
dojo.toggleClass(this.domNode,"dijitTreeIsLast",!this.getNextSibling()); |
| 64 |
} |
| 65 |
},_setExpando:function(_d){ |
| 66 |
var _e=["dijitTreeExpandoLoading","dijitTreeExpandoOpened","dijitTreeExpandoClosed","dijitTreeExpandoLeaf"],_f=["*","-","+","*"],idx=_d?0:(this.isExpandable?(this.isExpanded?1:2):3); |
| 67 |
dojo.removeClass(this.expandoNode,_e);
|
| 68 |
dojo.addClass(this.expandoNode,_e[idx]);
|
| 69 |
this.expandoNodeText.innerHTML=_f[idx];
|
| 70 |
},expand:function(){ |
| 71 |
if(this._expandDeferred){ |
| 72 |
return this._expandDeferred; |
| 73 |
} |
| 74 |
this._wipeOut&&this._wipeOut.stop(); |
| 75 |
this.isExpanded=true; |
| 76 |
dijit.setWaiState(this.labelNode,"expanded","true"); |
| 77 |
dijit.setWaiRole(this.containerNode,"group"); |
| 78 |
dojo.addClass(this.contentNode,"dijitTreeContentExpanded"); |
| 79 |
this._setExpando();
|
| 80 |
this._updateItemClasses(this.item); |
| 81 |
if(this==this.tree.rootNode){ |
| 82 |
dijit.setWaiState(this.tree.domNode,"expanded","true"); |
| 83 |
} |
| 84 |
var def,_10=dojo.fx.wipeIn({node:this.containerNode,duration:dijit.defaultDuration,onEnd:function(){ |
| 85 |
def.callback(true);
|
| 86 |
}}); |
| 87 |
def=(this._expandDeferred=new dojo.Deferred(function(){ |
| 88 |
_10.stop(); |
| 89 |
})); |
| 90 |
_10.play(); |
| 91 |
return def;
|
| 92 |
},collapse:function(){ |
| 93 |
if(!this.isExpanded){ |
| 94 |
return;
|
| 95 |
} |
| 96 |
if(this._expandDeferred){ |
| 97 |
this._expandDeferred.cancel();
|
| 98 |
delete this._expandDeferred; |
| 99 |
} |
| 100 |
this.isExpanded=false; |
| 101 |
dijit.setWaiState(this.labelNode,"expanded","false"); |
| 102 |
if(this==this.tree.rootNode){ |
| 103 |
dijit.setWaiState(this.tree.domNode,"expanded","false"); |
| 104 |
} |
| 105 |
dojo.removeClass(this.contentNode,"dijitTreeContentExpanded"); |
| 106 |
this._setExpando();
|
| 107 |
this._updateItemClasses(this.item); |
| 108 |
if(!this._wipeOut){ |
| 109 |
this._wipeOut=dojo.fx.wipeOut({node:this.containerNode,duration:dijit.defaultDuration}); |
| 110 |
} |
| 111 |
this._wipeOut.play();
|
| 112 |
},indent:0,setChildItems:function(_11){ |
| 113 |
var _12=this.tree,_13=_12.model,_14=[]; |
| 114 |
dojo.forEach(this.getChildren(),function(_15){ |
| 115 |
dijit._Container.prototype.removeChild.call(this,_15);
|
| 116 |
},this);
|
| 117 |
this.state="LOADED"; |
| 118 |
if(_11&&_11.length>0){ |
| 119 |
this.isExpandable=true; |
| 120 |
dojo.forEach(_11,function(_16){
|
| 121 |
var id=_13.getIdentity(_16),_17=_12._itemNodesMap[id],_18;
|
| 122 |
if(_17){
|
| 123 |
for(var i=0;i<_17.length;i++){ |
| 124 |
if(_17[i]&&!_17[i].getParent()){
|
| 125 |
_18=_17[i]; |
| 126 |
_18.set("indent",this.indent+1); |
| 127 |
break;
|
| 128 |
} |
| 129 |
} |
| 130 |
} |
| 131 |
if(!_18){
|
| 132 |
_18=this.tree._createTreeNode({item:_16,tree:_12,isExpandable:_13.mayHaveChildren(_16),label:_12.getLabel(_16),tooltip:_12.getTooltip(_16),dir:_12.dir,lang:_12.lang,indent:this.indent+1}); |
| 133 |
if(_17){
|
| 134 |
_17.push(_18); |
| 135 |
}else{
|
| 136 |
_12._itemNodesMap[id]=[_18]; |
| 137 |
} |
| 138 |
} |
| 139 |
this.addChild(_18);
|
| 140 |
if(this.tree.autoExpand||this.tree._state(_16)){ |
| 141 |
_14.push(_12._expandNode(_18)); |
| 142 |
} |
| 143 |
},this);
|
| 144 |
dojo.forEach(this.getChildren(),function(_19,idx){ |
| 145 |
_19._updateLayout(); |
| 146 |
}); |
| 147 |
}else{
|
| 148 |
this.isExpandable=false; |
| 149 |
} |
| 150 |
if(this._setExpando){ |
| 151 |
this._setExpando(false); |
| 152 |
} |
| 153 |
this._updateItemClasses(this.item); |
| 154 |
if(this==_12.rootNode){ |
| 155 |
var fc=this.tree.showRoot?this:this.getChildren()[0]; |
| 156 |
if(fc){
|
| 157 |
fc.setFocusable(true);
|
| 158 |
_12.lastFocused=fc; |
| 159 |
}else{
|
| 160 |
_12.domNode.setAttribute("tabIndex","0"); |
| 161 |
} |
| 162 |
} |
| 163 |
return new dojo.DeferredList(_14); |
| 164 |
},removeChild:function(_1a){ |
| 165 |
this.inherited(arguments); |
| 166 |
var _1b=this.getChildren(); |
| 167 |
if(_1b.length==0){ |
| 168 |
this.isExpandable=false; |
| 169 |
this.collapse();
|
| 170 |
} |
| 171 |
dojo.forEach(_1b,function(_1c){
|
| 172 |
_1c._updateLayout(); |
| 173 |
}); |
| 174 |
},makeExpandable:function(){ |
| 175 |
this.isExpandable=true; |
| 176 |
this._setExpando(false); |
| 177 |
},_onLabelFocus:function(evt){ |
| 178 |
this.tree._onNodeFocus(this); |
| 179 |
},setSelected:function(_1d){ |
| 180 |
dijit.setWaiState(this.labelNode,"selected",_1d); |
| 181 |
dojo.toggleClass(this.rowNode,"dijitTreeRowSelected",_1d); |
| 182 |
},setFocusable:function(_1e){ |
| 183 |
this.labelNode.setAttribute("tabIndex",_1e?"0":"-1"); |
| 184 |
},_onClick:function(evt){ |
| 185 |
this.tree._onClick(this,evt); |
| 186 |
},_onDblClick:function(evt){ |
| 187 |
this.tree._onDblClick(this,evt); |
| 188 |
},_onMouseEnter:function(evt){ |
| 189 |
this.tree._onNodeMouseEnter(this,evt); |
| 190 |
},_onMouseLeave:function(evt){ |
| 191 |
this.tree._onNodeMouseLeave(this,evt); |
| 192 |
}}); |
| 193 |
dojo.declare("dijit.Tree",[dijit._Widget,dijit._Templated],{store:null,model:null,query:null,label:"",showRoot:true,childrenAttr:["children"],path:[],selectedItem:null,openOnClick:false,openOnDblClick:false,templateString:dojo.cache("dijit","templates/Tree.html","<div class=\"dijitTree dijitTreeContainer\" waiRole=\"tree\"\n\tdojoAttachEvent=\"onkeypress:_onKeyPress\">\n\t<div class=\"dijitInline dijitTreeIndent\" style=\"position: absolute; top: -9999px\" dojoAttachPoint=\"indentDetector\"></div>\n</div>\n"),persist:true,autoExpand:false,dndController:null,dndParams:["onDndDrop","itemCreator","onDndCancel","checkAcceptance","checkItemAcceptance","dragThreshold","betweenThreshold"],onDndDrop:null,itemCreator:null,onDndCancel:null,checkAcceptance:null,checkItemAcceptance:null,dragThreshold:5,betweenThreshold:0,_nodePixelIndent:19,_publish:function(_1f,_20){ |
| 194 |
dojo.publish(this.id,[dojo.mixin({tree:this,event:_1f},_20||{})]); |
| 195 |
},postMixInProperties:function(){ |
| 196 |
this.tree=this; |
| 197 |
if(this.autoExpand){ |
| 198 |
this.persist=false; |
| 199 |
} |
| 200 |
this._itemNodesMap={};
|
| 201 |
if(!this.cookieName){ |
| 202 |
this.cookieName=this.id+"SaveStateCookie"; |
| 203 |
} |
| 204 |
this._loadDeferred=new dojo.Deferred(); |
| 205 |
this.inherited(arguments); |
| 206 |
},postCreate:function(){ |
| 207 |
this._initState();
|
| 208 |
if(!this.model){ |
| 209 |
this._store2model();
|
| 210 |
} |
| 211 |
this.connect(this.model,"onChange","_onItemChange"); |
| 212 |
this.connect(this.model,"onChildrenChange","_onItemChildrenChange"); |
| 213 |
this.connect(this.model,"onDelete","_onItemDelete"); |
| 214 |
this._load();
|
| 215 |
this.inherited(arguments); |
| 216 |
if(this.dndController){ |
| 217 |
if(dojo.isString(this.dndController)){ |
| 218 |
this.dndController=dojo.getObject(this.dndController); |
| 219 |
} |
| 220 |
var _21={};
|
| 221 |
for(var i=0;i<this.dndParams.length;i++){ |
| 222 |
if(this[this.dndParams[i]]){ |
| 223 |
_21[this.dndParams[i]]=this[this.dndParams[i]]; |
| 224 |
} |
| 225 |
} |
| 226 |
this.dndController=new this.dndController(this,_21); |
| 227 |
} |
| 228 |
},_store2model:function(){ |
| 229 |
this._v10Compat=true; |
| 230 |
dojo.deprecated("Tree: from version 2.0, should specify a model object rather than a store/query");
|
| 231 |
var _22={id:this.id+"_ForestStoreModel",store:this.store,query:this.query,childrenAttrs:this.childrenAttr}; |
| 232 |
if(this.params.mayHaveChildren){ |
| 233 |
_22.mayHaveChildren=dojo.hitch(this,"mayHaveChildren"); |
| 234 |
} |
| 235 |
if(this.params.getItemChildren){ |
| 236 |
_22.getChildren=dojo.hitch(this,function(_23,_24,_25){ |
| 237 |
this.getItemChildren((this._v10Compat&&_23===this.model.root)?null:_23,_24,_25); |
| 238 |
}); |
| 239 |
} |
| 240 |
this.model=new dijit.tree.ForestStoreModel(_22); |
| 241 |
this.showRoot=Boolean(this.label); |
| 242 |
},onLoad:function(){ |
| 243 |
},_load:function(){ |
| 244 |
this.model.getRoot(dojo.hitch(this,function(_26){ |
| 245 |
var rn=(this.rootNode=this.tree._createTreeNode({item:_26,tree:this,isExpandable:true,label:this.label||this.getLabel(_26),indent:this.showRoot?0:-1})); |
| 246 |
if(!this.showRoot){ |
| 247 |
rn.rowNode.style.display="none";
|
| 248 |
} |
| 249 |
this.domNode.appendChild(rn.domNode);
|
| 250 |
var _27=this.model.getIdentity(_26); |
| 251 |
if(this._itemNodesMap[_27]){ |
| 252 |
this._itemNodesMap[_27].push(rn);
|
| 253 |
}else{
|
| 254 |
this._itemNodesMap[_27]=[rn];
|
| 255 |
} |
| 256 |
rn._updateLayout(); |
| 257 |
this._expandNode(rn).addCallback(dojo.hitch(this,function(){ |
| 258 |
this._loadDeferred.callback(true); |
| 259 |
this.onLoad();
|
| 260 |
})); |
| 261 |
}),function(err){
|
| 262 |
console.error(this,": error loading root: ",err); |
| 263 |
}); |
| 264 |
},getNodesByItem:function(_28){ |
| 265 |
if(!_28){
|
| 266 |
return [];
|
| 267 |
} |
| 268 |
var _29=dojo.isString(_28)?_28:this.model.getIdentity(_28); |
| 269 |
return [].concat(this._itemNodesMap[_29]); |
| 270 |
},_setSelectedItemAttr:function(_2a){ |
| 271 |
var _2b=this.get("selectedItem"); |
| 272 |
var _2c=(!_2a||dojo.isString(_2a))?_2a:this.model.getIdentity(_2a); |
| 273 |
if(_2c==_2b?this.model.getIdentity(_2b):null){ |
| 274 |
return;
|
| 275 |
} |
| 276 |
var _2d=this._itemNodesMap[_2c]; |
| 277 |
this._selectNode((_2d&&_2d[0])||null); |
| 278 |
},_getSelectedItemAttr:function(){ |
| 279 |
return this.selectedNode&&this.selectedNode.item; |
| 280 |
},_setPathAttr:function(_2e){ |
| 281 |
var d=new dojo.Deferred(); |
| 282 |
this._selectNode(null); |
| 283 |
if(!_2e||!_2e.length){
|
| 284 |
d.resolve(true);
|
| 285 |
return d;
|
| 286 |
} |
| 287 |
this._loadDeferred.addCallback(dojo.hitch(this,function(){ |
| 288 |
if(!this.rootNode){ |
| 289 |
d.reject(new Error("!this.rootNode")); |
| 290 |
return;
|
| 291 |
} |
| 292 |
if(_2e[0]!==this.rootNode.item&&(dojo.isString(_2e[0])&&_2e[0]!=this.model.getIdentity(this.rootNode.item))){ |
| 293 |
d.reject(new Error(this.id+":path[0] doesn't match this.rootNode.item. Maybe you are using the wrong tree.")); |
| 294 |
return;
|
| 295 |
} |
| 296 |
_2e.shift(); |
| 297 |
var _2f=this.rootNode; |
| 298 |
function _30(){ |
| 299 |
var _31=_2e.shift(),_32=dojo.isString(_31)?_31:this.model.getIdentity(_31); |
| 300 |
dojo.some(this._itemNodesMap[_32],function(n){ |
| 301 |
if(n.getParent()==_2f){
|
| 302 |
_2f=n; |
| 303 |
return true; |
| 304 |
} |
| 305 |
return false; |
| 306 |
}); |
| 307 |
if(_2e.length){
|
| 308 |
this._expandNode(_2f).addCallback(dojo.hitch(this,_30)); |
| 309 |
}else{
|
| 310 |
this._selectNode(_2f);
|
| 311 |
d.resolve(true);
|
| 312 |
} |
| 313 |
}; |
| 314 |
this._expandNode(_2f).addCallback(dojo.hitch(this,_30)); |
| 315 |
})); |
| 316 |
return d;
|
| 317 |
},_getPathAttr:function(){ |
| 318 |
if(!this.selectedNode){ |
| 319 |
return;
|
| 320 |
} |
| 321 |
var res=[];
|
| 322 |
var _33=this.selectedNode; |
| 323 |
while(_33&&_33!==this.rootNode){ |
| 324 |
res.unshift(_33.item); |
| 325 |
_33=_33.getParent(); |
| 326 |
} |
| 327 |
res.unshift(this.rootNode.item);
|
| 328 |
return res;
|
| 329 |
},mayHaveChildren:function(_34){ |
| 330 |
},getItemChildren:function(_35,_36){ |
| 331 |
},getLabel:function(_37){ |
| 332 |
return this.model.getLabel(_37); |
| 333 |
},getIconClass:function(_38,_39){ |
| 334 |
return (!_38||this.model.mayHaveChildren(_38))?(_39?"dijitFolderOpened":"dijitFolderClosed"):"dijitLeaf"; |
| 335 |
},getLabelClass:function(_3a,_3b){ |
| 336 |
},getRowClass:function(_3c,_3d){ |
| 337 |
},getIconStyle:function(_3e,_3f){ |
| 338 |
},getLabelStyle:function(_40,_41){ |
| 339 |
},getRowStyle:function(_42,_43){ |
| 340 |
},getTooltip:function(_44){ |
| 341 |
return ""; |
| 342 |
},_onKeyPress:function(e){ |
| 343 |
if(e.altKey){
|
| 344 |
return;
|
| 345 |
} |
| 346 |
var dk=dojo.keys;
|
| 347 |
var _45=dijit.getEnclosingWidget(e.target);
|
| 348 |
if(!_45){
|
| 349 |
return;
|
| 350 |
} |
| 351 |
var key=e.charOrCode;
|
| 352 |
if(typeof key=="string"){ |
| 353 |
if(!e.altKey&&!e.ctrlKey&&!e.shiftKey&&!e.metaKey){
|
| 354 |
this._onLetterKeyNav({node:_45,key:key.toLowerCase()}); |
| 355 |
dojo.stopEvent(e); |
| 356 |
} |
| 357 |
}else{
|
| 358 |
if(this._curSearch){ |
| 359 |
clearTimeout(this._curSearch.timer);
|
| 360 |
delete this._curSearch; |
| 361 |
} |
| 362 |
var map=this._keyHandlerMap; |
| 363 |
if(!map){
|
| 364 |
map={};
|
| 365 |
map[dk.ENTER]="_onEnterKey";
|
| 366 |
map[this.isLeftToRight()?dk.LEFT_ARROW:dk.RIGHT_ARROW]="_onLeftArrow"; |
| 367 |
map[this.isLeftToRight()?dk.RIGHT_ARROW:dk.LEFT_ARROW]="_onRightArrow"; |
| 368 |
map[dk.UP_ARROW]="_onUpArrow";
|
| 369 |
map[dk.DOWN_ARROW]="_onDownArrow";
|
| 370 |
map[dk.HOME]="_onHomeKey";
|
| 371 |
map[dk.END]="_onEndKey";
|
| 372 |
this._keyHandlerMap=map;
|
| 373 |
} |
| 374 |
if(this._keyHandlerMap[key]){ |
| 375 |
this[this._keyHandlerMap[key]]({node:_45,item:_45.item,evt:e}); |
| 376 |
dojo.stopEvent(e); |
| 377 |
} |
| 378 |
} |
| 379 |
},_onEnterKey:function(_46,evt){ |
| 380 |
this._publish("execute",{item:_46.item,node:_46.node}); |
| 381 |
this._selectNode(_46.node);
|
| 382 |
this.onClick(_46.item,_46.node,evt);
|
| 383 |
},_onDownArrow:function(_47){ |
| 384 |
var _48=this._getNextNode(_47.node); |
| 385 |
if(_48&&_48.isTreeNode){
|
| 386 |
this.focusNode(_48);
|
| 387 |
} |
| 388 |
},_onUpArrow:function(_49){ |
| 389 |
var _4a=_49.node;
|
| 390 |
var _4b=_4a.getPreviousSibling();
|
| 391 |
if(_4b){
|
| 392 |
_4a=_4b; |
| 393 |
while(_4a.isExpandable&&_4a.isExpanded&&_4a.hasChildren()){
|
| 394 |
var _4c=_4a.getChildren();
|
| 395 |
_4a=_4c[_4c.length-1];
|
| 396 |
} |
| 397 |
}else{
|
| 398 |
var _4d=_4a.getParent();
|
| 399 |
if(!(!this.showRoot&&_4d===this.rootNode)){ |
| 400 |
_4a=_4d; |
| 401 |
} |
| 402 |
} |
| 403 |
if(_4a&&_4a.isTreeNode){
|
| 404 |
this.focusNode(_4a);
|
| 405 |
} |
| 406 |
},_onRightArrow:function(_4e){ |
| 407 |
var _4f=_4e.node;
|
| 408 |
if(_4f.isExpandable&&!_4f.isExpanded){
|
| 409 |
this._expandNode(_4f);
|
| 410 |
}else{
|
| 411 |
if(_4f.hasChildren()){
|
| 412 |
_4f=_4f.getChildren()[0];
|
| 413 |
if(_4f&&_4f.isTreeNode){
|
| 414 |
this.focusNode(_4f);
|
| 415 |
} |
| 416 |
} |
| 417 |
} |
| 418 |
},_onLeftArrow:function(_50){ |
| 419 |
var _51=_50.node;
|
| 420 |
if(_51.isExpandable&&_51.isExpanded){
|
| 421 |
this._collapseNode(_51);
|
| 422 |
}else{
|
| 423 |
var _52=_51.getParent();
|
| 424 |
if(_52&&_52.isTreeNode&&!(!this.showRoot&&_52===this.rootNode)){ |
| 425 |
this.focusNode(_52);
|
| 426 |
} |
| 427 |
} |
| 428 |
},_onHomeKey:function(){ |
| 429 |
var _53=this._getRootOrFirstNode(); |
| 430 |
if(_53){
|
| 431 |
this.focusNode(_53);
|
| 432 |
} |
| 433 |
},_onEndKey:function(_54){ |
| 434 |
var _55=this.rootNode; |
| 435 |
while(_55.isExpanded){
|
| 436 |
var c=_55.getChildren();
|
| 437 |
_55=c[c.length-1];
|
| 438 |
} |
| 439 |
if(_55&&_55.isTreeNode){
|
| 440 |
this.focusNode(_55);
|
| 441 |
} |
| 442 |
},multiCharSearchDuration:250,_onLetterKeyNav:function(_56){ |
| 443 |
var cs=this._curSearch; |
| 444 |
if(cs){
|
| 445 |
cs.pattern=cs.pattern+_56.key; |
| 446 |
clearTimeout(cs.timer); |
| 447 |
}else{
|
| 448 |
cs=this._curSearch={pattern:_56.key,startNode:_56.node}; |
| 449 |
} |
| 450 |
var _57=this; |
| 451 |
cs.timer=setTimeout(function(){
|
| 452 |
delete _57._curSearch;
|
| 453 |
},this.multiCharSearchDuration);
|
| 454 |
var _58=cs.startNode;
|
| 455 |
do{
|
| 456 |
_58=this._getNextNode(_58);
|
| 457 |
if(!_58){
|
| 458 |
_58=this._getRootOrFirstNode();
|
| 459 |
} |
| 460 |
}while(_58!==cs.startNode&&(_58.label.toLowerCase().substr(0,cs.pattern.length)!=cs.pattern)); |
| 461 |
if(_58&&_58.isTreeNode){
|
| 462 |
if(_58!==cs.startNode){
|
| 463 |
this.focusNode(_58);
|
| 464 |
} |
| 465 |
} |
| 466 |
},_onClick:function(_59,e){ |
| 467 |
var _5a=e.target,_5b=(_5a==_59.expandoNode||_5a==_59.expandoNodeText);
|
| 468 |
if((this.openOnClick&&_59.isExpandable)||_5b){ |
| 469 |
if(_59.isExpandable){
|
| 470 |
this._onExpandoClick({node:_59}); |
| 471 |
} |
| 472 |
}else{
|
| 473 |
this._publish("execute",{item:_59.item,node:_59,evt:e}); |
| 474 |
this.onClick(_59.item,_59,e);
|
| 475 |
this.focusNode(_59);
|
| 476 |
} |
| 477 |
if(!_5b){
|
| 478 |
this._selectNode(_59);
|
| 479 |
} |
| 480 |
dojo.stopEvent(e); |
| 481 |
},_onDblClick:function(_5c,e){ |
| 482 |
var _5d=e.target,_5e=(_5d==_5c.expandoNode||_5d==_5c.expandoNodeText);
|
| 483 |
if((this.openOnDblClick&&_5c.isExpandable)||_5e){ |
| 484 |
if(_5c.isExpandable){
|
| 485 |
this._onExpandoClick({node:_5c}); |
| 486 |
} |
| 487 |
}else{
|
| 488 |
this._publish("execute",{item:_5c.item,node:_5c,evt:e}); |
| 489 |
this.onDblClick(_5c.item,_5c,e);
|
| 490 |
this.focusNode(_5c);
|
| 491 |
} |
| 492 |
if(!_5e){
|
| 493 |
this._selectNode(_5c);
|
| 494 |
} |
| 495 |
dojo.stopEvent(e); |
| 496 |
},_onExpandoClick:function(_5f){ |
| 497 |
var _60=_5f.node;
|
| 498 |
this.focusNode(_60);
|
| 499 |
if(_60.isExpanded){
|
| 500 |
this._collapseNode(_60);
|
| 501 |
}else{
|
| 502 |
this._expandNode(_60);
|
| 503 |
} |
| 504 |
},onClick:function(_61,_62,evt){ |
| 505 |
},onDblClick:function(_63,_64,evt){ |
| 506 |
},onOpen:function(_65,_66){ |
| 507 |
},onClose:function(_67,_68){ |
| 508 |
},_getNextNode:function(_69){ |
| 509 |
if(_69.isExpandable&&_69.isExpanded&&_69.hasChildren()){
|
| 510 |
return _69.getChildren()[0]; |
| 511 |
}else{
|
| 512 |
while(_69&&_69.isTreeNode){
|
| 513 |
var _6a=_69.getNextSibling();
|
| 514 |
if(_6a){
|
| 515 |
return _6a;
|
| 516 |
} |
| 517 |
_69=_69.getParent(); |
| 518 |
} |
| 519 |
return null; |
| 520 |
} |
| 521 |
},_getRootOrFirstNode:function(){ |
| 522 |
return this.showRoot?this.rootNode:this.rootNode.getChildren()[0]; |
| 523 |
},_collapseNode:function(_6b){ |
| 524 |
if(_6b._expandNodeDeferred){
|
| 525 |
delete _6b._expandNodeDeferred;
|
| 526 |
} |
| 527 |
if(_6b.isExpandable){
|
| 528 |
if(_6b.state=="LOADING"){ |
| 529 |
return;
|
| 530 |
} |
| 531 |
_6b.collapse(); |
| 532 |
this.onClose(_6b.item,_6b);
|
| 533 |
if(_6b.item){
|
| 534 |
this._state(_6b.item,false); |
| 535 |
this._saveState();
|
| 536 |
} |
| 537 |
} |
| 538 |
},_expandNode:function(_6c,_6d){ |
| 539 |
if(_6c._expandNodeDeferred&&!_6d){
|
| 540 |
return _6c._expandNodeDeferred;
|
| 541 |
} |
| 542 |
var _6e=this.model,_6f=_6c.item,_70=this; |
| 543 |
switch(_6c.state){
|
| 544 |
case "UNCHECKED": |
| 545 |
_6c.markProcessing(); |
| 546 |
var def=(_6c._expandNodeDeferred=new dojo.Deferred()); |
| 547 |
_6e.getChildren(_6f,function(_71){
|
| 548 |
_6c.unmarkProcessing(); |
| 549 |
var _72=_6c.setChildItems(_71);
|
| 550 |
var ed=_70._expandNode(_6c,true); |
| 551 |
_72.addCallback(function(){
|
| 552 |
ed.addCallback(function(){
|
| 553 |
def.callback(); |
| 554 |
}); |
| 555 |
}); |
| 556 |
},function(err){
|
| 557 |
console.error(_70,": error loading root children: ",err);
|
| 558 |
}); |
| 559 |
break;
|
| 560 |
default:
|
| 561 |
def=(_6c._expandNodeDeferred=_6c.expand()); |
| 562 |
this.onOpen(_6c.item,_6c);
|
| 563 |
if(_6f){
|
| 564 |
this._state(_6f,true); |
| 565 |
this._saveState();
|
| 566 |
} |
| 567 |
} |
| 568 |
return def;
|
| 569 |
},focusNode:function(_73){ |
| 570 |
dijit.focus(_73.labelNode); |
| 571 |
},_selectNode:function(_74){ |
| 572 |
if(this.selectedNode&&!this.selectedNode._destroyed){ |
| 573 |
this.selectedNode.setSelected(false); |
| 574 |
} |
| 575 |
if(_74){
|
| 576 |
_74.setSelected(true);
|
| 577 |
} |
| 578 |
this.selectedNode=_74;
|
| 579 |
},_onNodeFocus:function(_75){ |
| 580 |
if(_75&&_75!=this.lastFocused){ |
| 581 |
if(this.lastFocused&&!this.lastFocused._destroyed){ |
| 582 |
this.lastFocused.setFocusable(false); |
| 583 |
} |
| 584 |
_75.setFocusable(true);
|
| 585 |
this.lastFocused=_75;
|
| 586 |
} |
| 587 |
},_onNodeMouseEnter:function(_76){ |
| 588 |
},_onNodeMouseLeave:function(_77){ |
| 589 |
},_onItemChange:function(_78){ |
| 590 |
var _79=this.model,_7a=_79.getIdentity(_78),_7b=this._itemNodesMap[_7a]; |
| 591 |
if(_7b){
|
| 592 |
var _7c=this.getLabel(_78),_7d=this.getTooltip(_78); |
| 593 |
dojo.forEach(_7b,function(_7e){
|
| 594 |
_7e.set({item:_78,label:_7c,tooltip:_7d});
|
| 595 |
_7e._updateItemClasses(_78); |
| 596 |
}); |
| 597 |
} |
| 598 |
},_onItemChildrenChange:function(_7f,_80){ |
| 599 |
var _81=this.model,_82=_81.getIdentity(_7f),_83=this._itemNodesMap[_82]; |
| 600 |
if(_83){
|
| 601 |
dojo.forEach(_83,function(_84){
|
| 602 |
_84.setChildItems(_80); |
| 603 |
}); |
| 604 |
} |
| 605 |
},_onItemDelete:function(_85){ |
| 606 |
var _86=this.model,_87=_86.getIdentity(_85),_88=this._itemNodesMap[_87]; |
| 607 |
if(_88){
|
| 608 |
dojo.forEach(_88,function(_89){
|
| 609 |
var _8a=_89.getParent();
|
| 610 |
if(_8a){
|
| 611 |
_8a.removeChild(_89); |
| 612 |
} |
| 613 |
_89.destroyRecursive(); |
| 614 |
}); |
| 615 |
delete this._itemNodesMap[_87]; |
| 616 |
} |
| 617 |
},_initState:function(){ |
| 618 |
if(this.persist){ |
| 619 |
var _8b=dojo.cookie(this.cookieName); |
| 620 |
this._openedItemIds={};
|
| 621 |
if(_8b){
|
| 622 |
dojo.forEach(_8b.split(","),function(_8c){ |
| 623 |
this._openedItemIds[_8c]=true; |
| 624 |
},this);
|
| 625 |
} |
| 626 |
} |
| 627 |
},_state:function(_8d,_8e){ |
| 628 |
if(!this.persist){ |
| 629 |
return false; |
| 630 |
} |
| 631 |
var id=this.model.getIdentity(_8d); |
| 632 |
if(arguments.length===1){ |
| 633 |
return this._openedItemIds[id]; |
| 634 |
} |
| 635 |
if(_8e){
|
| 636 |
this._openedItemIds[id]=true; |
| 637 |
}else{
|
| 638 |
delete this._openedItemIds[id]; |
| 639 |
} |
| 640 |
},_saveState:function(){ |
| 641 |
if(!this.persist){ |
| 642 |
return;
|
| 643 |
} |
| 644 |
var ary=[];
|
| 645 |
for(var id in this._openedItemIds){ |
| 646 |
ary.push(id); |
| 647 |
} |
| 648 |
dojo.cookie(this.cookieName,ary.join(","),{expires:365}); |
| 649 |
},destroy:function(){ |
| 650 |
if(this._curSearch){ |
| 651 |
clearTimeout(this._curSearch.timer);
|
| 652 |
delete this._curSearch; |
| 653 |
} |
| 654 |
if(this.rootNode){ |
| 655 |
this.rootNode.destroyRecursive();
|
| 656 |
} |
| 657 |
if(this.dndController&&!dojo.isString(this.dndController)){ |
| 658 |
this.dndController.destroy();
|
| 659 |
} |
| 660 |
this.rootNode=null; |
| 661 |
this.inherited(arguments); |
| 662 |
},destroyRecursive:function(){ |
| 663 |
this.destroy();
|
| 664 |
},resize:function(_8f){ |
| 665 |
if(_8f){
|
| 666 |
dojo.marginBox(this.domNode,_8f);
|
| 667 |
dojo.style(this.domNode,"overflow","auto"); |
| 668 |
} |
| 669 |
this._nodePixelIndent=dojo.marginBox(this.tree.indentDetector).w; |
| 670 |
if(this.tree.rootNode){ |
| 671 |
this.tree.rootNode.set("indent",this.showRoot?0:-1); |
| 672 |
} |
| 673 |
},_createTreeNode:function(_90){ |
| 674 |
return new dijit._TreeNode(_90); |
| 675 |
}}); |
| 676 |
dojo.require("dijit.tree.TreeStoreModel");
|
| 677 |
dojo.require("dijit.tree.ForestStoreModel");
|
| 678 |
} |