Total Complexity | 749 |
Complexity/F | 3.65 |
Lines of Code | 3860 |
Function Count | 205 |
Duplicated Lines | 312 |
Ratio | 8.08 % |
Changes | 0 |
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like api/js/dhtmlxtree/sources/dhtmlxtree.js often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
1 | //v.3.6 build 131023 |
||
19 | function xmlPointer(data){ |
||
20 | this.d=data; |
||
21 | } |
||
22 | xmlPointer.prototype={ |
||
23 | text:function(){ if (!_isFF) return this.d.xml; var x = new XMLSerializer(); return x.serializeToString(this.d); }, |
||
24 | get:function(name){return this.d.getAttribute(name); }, |
||
25 | exists:function(){return !!this.d }, |
||
26 | content:function(){return this.d.firstChild?this.d.firstChild.data:""; }, // <4k in FF |
||
27 | each:function(name,f,t,i){ var a=this.d.childNodes; var c=new xmlPointer(); if (a.length) for (i=i||0; i<a.length; i++) if (a[i].tagName==name) { c.d=a[i]; if(f.apply(t,[c,i])==-1) return; } }, |
||
28 | get_all:function(){ var a={}; var b=this.d.attributes; for (var i=0; i<b.length; i++) a[b[i].name]=b[i].value; return a; }, |
||
29 | sub:function(name){ var a=this.d.childNodes; var c=new xmlPointer(); if (a.length) for (var i=0; i<a.length; i++) if (a[i].tagName==name) { c.d=a[i]; return c; } }, |
||
30 | up:function(name){ return new xmlPointer(this.d.parentNode); }, |
||
31 | set:function(name,val){ this.d.setAttribute(name,val); }, |
||
32 | clone:function(name){ return new xmlPointer(this.d); }, |
||
33 | sub_exists:function(name){ var a=this.d.childNodes; if (a.length) for (var i=0; i<a.length; i++) if (a[i].tagName==name) return true; return false; }, |
||
34 | through:function(name,rule,v,f,t){ var a=this.d.childNodes; if (a.length) for (var i=0; i<a.length; i++) { if (a[i].tagName==name && a[i].getAttribute(rule)!=null && a[i].getAttribute(rule)!="" && (!v || a[i].getAttribute(rule)==v )) { var c=new xmlPointer(a[i]); f.apply(t,[c,i]); } var w=this.d; this.d=a[i]; this.through(name,rule,v,f,t); this.d=w; } } |
||
35 | } |
||
36 | |||
37 | |||
38 | |||
39 | /** |
||
40 | * @desc: tree constructor |
||
41 | * @param: htmlObject - parent html object or id of parent html object |
||
42 | * @param: width - tree width |
||
43 | * @param: height - tree height |
||
44 | * @param: rootId - id of virtual root node (same as tree node id attribute in xml) |
||
45 | * @type: public |
||
46 | * @topic: 0 |
||
47 | */ |
||
48 | function dhtmlXTreeObject(htmlObject, width, height, rootId){ |
||
49 | if (_isIE) try { document.execCommand("BackgroundImageCache", false, true); } catch (e){} |
||
|
|||
50 | if (typeof(htmlObject)!="object") |
||
51 | this.parentObject=document.getElementById(htmlObject); |
||
52 | else |
||
53 | this.parentObject=htmlObject; |
||
54 | |||
55 | this.parentObject.style.overflow="hidden"; |
||
56 | this._itim_dg=true; |
||
57 | this.dlmtr=","; |
||
58 | this.dropLower=false; |
||
59 | this.enableIEImageFix(); |
||
60 | |||
61 | this.xmlstate=0; |
||
62 | this.mytype="tree"; |
||
63 | this.smcheck=true; //smart checkboxes |
||
64 | this.width=width; |
||
65 | this.height=height; |
||
66 | this.rootId=rootId; |
||
67 | this.childCalc=null; |
||
68 | this.def_img_x="18px"; |
||
69 | this.def_img_y="18px"; |
||
70 | this.def_line_img_x="18px"; |
||
71 | this.def_line_img_y="18px"; |
||
72 | |||
73 | this._dragged=new Array(); |
||
74 | this._selected=new Array(); |
||
75 | |||
76 | this.style_pointer="pointer"; |
||
77 | |||
78 | this._aimgs=true; |
||
79 | this.htmlcA=" ["; |
||
80 | this.htmlcB="]"; |
||
81 | this.lWin=window; |
||
82 | this.cMenu=0; |
||
83 | this.mlitems=0; |
||
84 | this.iconURL=""; |
||
85 | this.dadmode=0; |
||
86 | this.slowParse=false; |
||
87 | this.autoScroll=true; |
||
88 | this.hfMode=0; |
||
89 | this.nodeCut=new Array(); |
||
90 | this.XMLsource=0; |
||
91 | this.XMLloadingWarning=0; |
||
92 | this._idpull={}; |
||
93 | this._pullSize=0; |
||
94 | this.treeLinesOn=true; |
||
95 | this.tscheck=false; |
||
96 | this.timgen=true; |
||
97 | this.dpcpy=false; |
||
98 | this._ld_id=null; |
||
99 | this._oie_onXLE=[]; |
||
100 | this.imPath=window.dhx_globalImgPath||""; |
||
101 | this.checkArray=new Array("iconUncheckAll.gif","iconCheckAll.gif","iconCheckGray.gif","iconUncheckDis.gif","iconCheckDis.gif","iconCheckDis.gif"); |
||
102 | this.radioArray=new Array("radio_off.gif","radio_on.gif","radio_on.gif","radio_off.gif","radio_on.gif","radio_on.gif"); |
||
103 | |||
104 | this.lineArray=new Array("line2.gif","line3.gif","line4.gif","blank.gif","blank.gif","line1.gif"); |
||
105 | this.minusArray=new Array("minus2.gif","minus3.gif","minus4.gif","minus.gif","minus5.gif"); |
||
106 | this.plusArray=new Array("plus2.gif","plus3.gif","plus4.gif","plus.gif","plus5.gif"); |
||
107 | this.imageArray=new Array("leaf.gif","folderOpen.gif","folderClosed.gif"); |
||
108 | this.cutImg= new Array(0,0,0); |
||
109 | this.cutImage="but_cut.gif"; |
||
110 | |||
111 | dhtmlxEventable(this); |
||
112 | |||
113 | this.dragger= new dhtmlDragAndDropObject(); |
||
114 | //create root |
||
115 | this.htmlNode=new dhtmlXTreeItemObject(this.rootId,"",0,this); |
||
116 | this.htmlNode.htmlNode.childNodes[0].childNodes[0].style.display="none"; |
||
117 | this.htmlNode.htmlNode.childNodes[0].childNodes[0].childNodes[0].className="hiddenRow"; |
||
118 | //init tree structures |
||
119 | this.allTree=this._createSelf(); |
||
120 | this.allTree.appendChild(this.htmlNode.htmlNode); |
||
121 | |||
122 | if (dhtmlx.$customScroll) |
||
123 | dhtmlx.CustomScroll.enable(this); |
||
124 | |||
125 | if(_isFF){ |
||
126 | this.allTree.childNodes[0].width="100%"; |
||
127 | this.allTree.childNodes[0].style.overflow="hidden"; |
||
128 | } |
||
129 | |||
130 | var self=this; |
||
131 | this.allTree.onselectstart=new Function("return false;"); |
||
132 | if (_isMacOS) |
||
133 | this.allTree.oncontextmenu = function(e){ |
||
134 | return self._doContClick(e||window.event, true); |
||
135 | }; |
||
136 | this.allTree.onmousedown = function(e){ return self._doContClick(e||window.event); }; |
||
137 | |||
138 | this.XMLLoader=new dtmlXMLLoaderObject(this._parseXMLTree,this,true,this.no_cashe); |
||
139 | if (_isIE) this.preventIECashing(true); |
||
140 | |||
141 | |||
142 | |||
143 | |||
144 | if (window.addEventListener) window.addEventListener("unload",function(){try{ self.destructor(); } catch(e){}},false); |
||
145 | if (window.attachEvent) window.attachEvent("onunload",function(){ try{ self.destructor(); } catch(e){}}); |
||
146 | |||
147 | this.setImagesPath=this.setImagePath; |
||
148 | this.setIconsPath=this.setIconPath; |
||
149 | |||
150 | if (dhtmlx.image_path) this.setImagePath(dhtmlx.image_path); |
||
151 | if (dhtmlx.skin) this.setSkin(dhtmlx.skin); |
||
152 | |||
153 | return this; |
||
154 | }; |
||
155 | |||
156 | |||
157 | /** |
||
158 | * @desc: set default data transfer mode |
||
159 | * @param: mode - data mode (json,xml,csv) |
||
160 | * @type: public |
||
161 | * @topic: 0 |
||
162 | */ |
||
163 | dhtmlXTreeObject.prototype.setDataMode=function(mode){ |
||
164 | this._datamode=mode; |
||
165 | } |
||
166 | |||
167 | |||
168 | |||
169 | dhtmlXTreeObject.prototype._doContClick=function(ev, force){ |
||
170 | if (!force && ev.button!=2) { |
||
171 | if(this._acMenu){ |
||
172 | if (this._acMenu.hideContextMenu) |
||
173 | this._acMenu.hideContextMenu() |
||
174 | else |
||
175 | this.cMenu._contextEnd(); |
||
176 | } |
||
177 | return true; |
||
178 | } |
||
179 | |||
180 | |||
181 | |||
182 | |||
183 | var el=(_isIE?ev.srcElement:ev.target); |
||
184 | while ((el)&&(el.tagName!="BODY")) { |
||
185 | if (el.parentObject) break; |
||
186 | el=el.parentNode; |
||
187 | } |
||
188 | |||
189 | if ((!el)||(!el.parentObject)) return true; |
||
190 | |||
191 | var obj=el.parentObject; |
||
192 | |||
193 | if (!this.callEvent("onRightClick",[obj.id,ev])) |
||
194 | (ev.srcElement||ev.target).oncontextmenu = function(e){ (e||event).cancelBubble=true; return false; }; |
||
195 | |||
196 | this._acMenu=(obj.cMenu||this.cMenu); |
||
197 | if (this._acMenu){ |
||
198 | if (!(this.callEvent("onBeforeContextMenu", [ |
||
199 | obj.id |
||
200 | ]))) return true; |
||
201 | if(!_isMacOS) |
||
202 | (ev.srcElement||ev.target).oncontextmenu = function(e){ (e||event).cancelBubble=true; return false; }; |
||
203 | |||
204 | if (this._acMenu.showContextMenu){ |
||
205 | |||
206 | var dEl0=window.document.documentElement; |
||
207 | var dEl1=window.document.body; |
||
208 | var corrector = new Array((dEl0.scrollLeft||dEl1.scrollLeft),(dEl0.scrollTop||dEl1.scrollTop)); |
||
209 | if (_isIE){ |
||
210 | var x= ev.clientX+corrector[0]; |
||
211 | var y = ev.clientY+corrector[1]; |
||
212 | } else { |
||
213 | var x= ev.pageX; |
||
214 | var y = ev.pageY; |
||
215 | } |
||
216 | |||
217 | this._acMenu.showContextMenu(x-1,y-1) |
||
218 | this.contextID=obj.id; |
||
219 | ev.cancelBubble=true; |
||
220 | this._acMenu._skip_hide=true; |
||
221 | } else { |
||
222 | el.contextMenuId=obj.id; |
||
223 | el.contextMenu=this._acMenu; |
||
224 | el.a=this._acMenu._contextStart; |
||
225 | el.a(el, ev); |
||
226 | el.a=null; |
||
227 | } |
||
228 | |||
229 | return false; |
||
230 | } |
||
231 | return true; |
||
232 | } |
||
233 | |||
234 | |||
235 | /** |
||
236 | * @desc: replace IMG tag with background images - solve problem with IE image caching , not works for IE6 SP1 |
||
237 | * @param: mode - true/false - enable/disable fix |
||
238 | * @type: public |
||
239 | * @topic: 0 |
||
240 | */ |
||
241 | dhtmlXTreeObject.prototype.enableIEImageFix=function(mode){ |
||
242 | if (!mode){ |
||
243 | |||
244 | this._getImg=function(id){ return document.createElement((id==this.rootId)?"div":"img"); } |
||
245 | this._setSrc=function(a,b){ a.src=b; } |
||
246 | this._getSrc=function(a){ return a.src; } |
||
247 | } else { |
||
248 | |||
249 | this._getImg=function(){ var z=document.createElement("DIV"); z.innerHTML=" "; z.className="dhx_bg_img_fix"; return z; } |
||
250 | this._setSrc=function(a,b){ a.style.backgroundImage="url("+b+")"; } |
||
251 | this._getSrc=function(a){ var z=a.style.backgroundImage; return z.substr(4,z.length-5).replace(/(^")|("$)/g,""); } |
||
252 | } |
||
253 | } |
||
254 | |||
255 | /** |
||
256 | * @desc: deletes tree and clears memory |
||
257 | * @type: public |
||
258 | */ |
||
259 | dhtmlXTreeObject.prototype.destructor=function(){ |
||
260 | for (var a in this._idpull){ |
||
261 | var z=this._idpull[a]; |
||
262 | if (!z) continue; |
||
263 | z.parentObject=null;z.treeNod=null;z.childNodes=null;z.span=null;z.tr.nodem=null;z.tr=null;z.htmlNode.objBelong=null;z.htmlNode=null; |
||
264 | this._idpull[a]=null; |
||
265 | } |
||
266 | this.parentObject.innerHTML=""; |
||
267 | |||
268 | if(this.XMLLoader) |
||
269 | this.XMLLoader.destructor(); |
||
270 | |||
271 | this.allTree.onselectstart = null; |
||
272 | this.allTree.oncontextmenu = null; |
||
273 | this.allTree.onmousedown = null; |
||
274 | |||
275 | for(var a in this){ |
||
276 | this[a]=null; |
||
277 | } |
||
278 | } |
||
279 | |||
280 | function cObject(){ |
||
281 | return this; |
||
282 | } |
||
283 | cObject.prototype= new Object; |
||
284 | cObject.prototype.clone = function () { |
||
285 | function _dummy(){}; |
||
286 | _dummy.prototype=this; |
||
287 | return new _dummy(); |
||
288 | } |
||
289 | |||
290 | /** |
||
291 | * @desc: tree node constructor |
||
292 | * @param: itemId - node id |
||
293 | * @param: itemText - node label |
||
294 | * @param: parentObject - parent item object |
||
295 | * @param: treeObject - tree object |
||
296 | * @param: actionHandler - onclick event handler(optional) |
||
297 | * @param: mode - do not show images |
||
298 | * @type: private |
||
299 | * @topic: 0 |
||
300 | */ |
||
301 | View Code Duplication | function dhtmlXTreeItemObject(itemId,itemText,parentObject,treeObject,actionHandler,mode){ |
|
302 | this.htmlNode=""; |
||
303 | this.acolor=""; |
||
304 | this.scolor=""; |
||
305 | this.tr=0; |
||
306 | this.childsCount=0; |
||
307 | this.tempDOMM=0; |
||
308 | this.tempDOMU=0; |
||
309 | this.dragSpan=0; |
||
310 | this.dragMove=0; |
||
311 | this.span=0; |
||
312 | this.closeble=1; |
||
313 | this.childNodes=new Array(); |
||
314 | this.userData=new cObject(); |
||
315 | |||
316 | |||
317 | this.checkstate=0; |
||
318 | this.treeNod=treeObject; |
||
319 | this.label=itemText; |
||
320 | this.parentObject=parentObject; |
||
321 | this.actionHandler=actionHandler; |
||
322 | this.images=new Array(treeObject.imageArray[0],treeObject.imageArray[1],treeObject.imageArray[2]); |
||
323 | |||
324 | |||
325 | this.id=treeObject._globalIdStorageAdd(itemId,this); |
||
326 | if (this.treeNod.checkBoxOff ) this.htmlNode=this.treeNod._createItem(1,this,mode); |
||
327 | else this.htmlNode=this.treeNod._createItem(0,this,mode); |
||
328 | |||
329 | this.htmlNode.objBelong=this; |
||
330 | return this; |
||
331 | }; |
||
332 | |||
333 | |||
334 | /** |
||
335 | * @desc: register node |
||
336 | * @type: private |
||
337 | * @param: itemId - node id |
||
338 | * @param: itemObject - node object |
||
339 | * @topic: 3 |
||
340 | */ |
||
341 | dhtmlXTreeObject.prototype._globalIdStorageAdd=function(itemId,itemObject){ |
||
342 | if (this._globalIdStorageFind(itemId,1,1)) { itemId=itemId +"_"+(new Date()).valueOf(); return this._globalIdStorageAdd(itemId,itemObject); } |
||
343 | this._idpull[itemId]=itemObject; |
||
344 | this._pullSize++; |
||
345 | return itemId; |
||
346 | }; |
||
347 | |||
348 | /** |
||
349 | * @desc: unregister node |
||
350 | * @type: private |
||
351 | * @param: itemId - node id |
||
352 | * @topic: 3 |
||
353 | */ |
||
354 | dhtmlXTreeObject.prototype._globalIdStorageSub=function(itemId){ |
||
355 | if (this._idpull[itemId]){ |
||
356 | this._unselectItem(this._idpull[itemId]); |
||
357 | this._idpull[itemId]=null; |
||
358 | this._pullSize--; |
||
359 | } |
||
360 | if ((this._locker)&&(this._locker[itemId])) this._locker[itemId]=false; |
||
361 | }; |
||
362 | |||
363 | /** |
||
364 | * @desc: return node object |
||
365 | * @param: itemId - node id |
||
366 | * @type: private |
||
367 | * @topic: 3 |
||
368 | */ |
||
369 | dhtmlXTreeObject.prototype._globalIdStorageFind=function(itemId,skipXMLSearch,skipParsing,isreparse){ |
||
370 | var z=this._idpull[itemId] |
||
371 | if (z){ |
||
372 | |||
373 | return z; |
||
374 | } |
||
375 | |||
376 | return null; |
||
377 | }; |
||
378 | |||
379 | |||
380 | /** |
||
381 | * @desc: escape string |
||
382 | * @param: itemId - item ID |
||
383 | * @type: private |
||
384 | * @topic: 3 |
||
385 | */ |
||
386 | dhtmlXTreeObject.prototype._escape=function(str){ |
||
387 | switch(this.utfesc){ |
||
388 | case "none": |
||
389 | return str; |
||
390 | break; |
||
391 | case "utf8": |
||
392 | return encodeURIComponent(str); |
||
393 | break; |
||
394 | default: |
||
395 | return escape(str); |
||
396 | break; |
||
397 | } |
||
398 | } |
||
399 | |||
400 | |||
401 | |||
402 | /** |
||
403 | * @desc: create and return new line in tree |
||
404 | * @type: private |
||
405 | * @param: htmlObject - parent Node object |
||
406 | * @param: node - item object |
||
407 | * @topic: 2 |
||
408 | */ |
||
409 | dhtmlXTreeObject.prototype._drawNewTr=function(htmlObject,node) |
||
410 | { |
||
411 | var tr =document.createElement('tr'); |
||
412 | var td1=document.createElement('td'); |
||
413 | var td2=document.createElement('td'); |
||
414 | td1.appendChild(document.createTextNode(" ")); |
||
415 | td2.colSpan=3; |
||
416 | td2.appendChild(htmlObject); |
||
417 | tr.appendChild(td1); tr.appendChild(td2); |
||
418 | return tr; |
||
419 | }; |
||
420 | /** |
||
421 | * @desc: load tree from xml string |
||
422 | * @type: public |
||
423 | * @param: xmlString - XML string |
||
424 | * @param: afterCall - function which will be called after xml loading |
||
425 | * @topic: 0 |
||
426 | */ |
||
427 | dhtmlXTreeObject.prototype.loadXMLString=function(xmlString,afterCall){ |
||
428 | var that=this; |
||
429 | if (!this.parsCount) this.callEvent("onXLS",[that,null]); |
||
430 | this.xmlstate=1; |
||
431 | |||
432 | if (afterCall) this.XMLLoader.waitCall=afterCall; |
||
433 | this.XMLLoader.loadXMLString(xmlString); }; |
||
434 | /** |
||
435 | * @desc: load tree from xml file |
||
436 | * @type: public |
||
437 | * @param: file - link to XML file |
||
438 | * @param: afterCall - function which will be called after xml loading |
||
439 | * @topic: 0 |
||
440 | */ |
||
441 | View Code Duplication | dhtmlXTreeObject.prototype.loadXML=function(file,afterCall){ |
|
442 | afterCall = afterCall || this.AJAX_callback; |
||
443 | if (this._datamode && this._datamode!="xml") return this["load"+this._datamode.toUpperCase()](file,afterCall); |
||
444 | var that=this; |
||
445 | if (!this.parsCount) this.callEvent("onXLS",[that,this._ld_id]); |
||
446 | this._ld_id=null; |
||
447 | this.xmlstate=1; |
||
448 | this.XMLLoader=new dtmlXMLLoaderObject(this._parseXMLTree,this,true,this.no_cashe); |
||
449 | |||
450 | if (afterCall) this.XMLLoader.waitCall=afterCall; |
||
451 | this.XMLLoader.loadXML(file); |
||
452 | }; |
||
453 | /** |
||
454 | * @desc: create new child node |
||
455 | * @type: private |
||
456 | * @param: parentObject - parent node object |
||
457 | * @param: itemId - new node id |
||
458 | * @param: itemText - new node text |
||
459 | * @param: itemActionHandler - function fired on node select event |
||
460 | * @param: image1 - image for node without children; |
||
461 | * @param: image2 - image for closed node; |
||
462 | * @param: image3 - image for opened node |
||
463 | * @param: optionStr - string of otions |
||
464 | * @param: childs - node childs flag (for dynamical trees) (optional) |
||
465 | * @param: beforeNode - node, after which new node will be inserted (optional) |
||
466 | * @topic: 2 |
||
467 | */ |
||
468 | dhtmlXTreeObject.prototype._attachChildNode=function(parentObject,itemId,itemText,itemActionHandler,image1,image2,image3,optionStr,childs,beforeNode,afterNode){ |
||
469 | |||
470 | if (beforeNode && beforeNode.parentObject) parentObject=beforeNode.parentObject; |
||
471 | if (((parentObject.XMLload==0)&&(this.XMLsource))&&(!this.XMLloadingWarning)) |
||
472 | { |
||
473 | parentObject.XMLload=1; |
||
474 | this._loadDynXML(parentObject.id); |
||
475 | |||
476 | } |
||
477 | |||
478 | var Count=parentObject.childsCount; |
||
479 | var Nodes=parentObject.childNodes; |
||
480 | |||
481 | |||
482 | if (afterNode && afterNode.tr.previousSibling){ |
||
483 | if (afterNode.tr.previousSibling.previousSibling){ |
||
484 | beforeNode=afterNode.tr.previousSibling.nodem; |
||
485 | } |
||
486 | else |
||
487 | optionStr=optionStr.replace("TOP","")+",TOP"; |
||
488 | } |
||
489 | |||
490 | if (beforeNode) |
||
491 | { |
||
492 | var ik,jk; |
||
493 | for (ik=0; ik<Count; ik++) |
||
494 | if (Nodes[ik]==beforeNode) |
||
495 | { |
||
496 | for (jk=Count; jk!=ik; jk--) |
||
497 | Nodes[1+jk]=Nodes[jk]; |
||
498 | break; |
||
499 | } |
||
500 | ik++; |
||
501 | Count=ik; |
||
502 | } |
||
503 | |||
504 | |||
505 | if (optionStr) { |
||
506 | var tempStr=optionStr.split(","); |
||
507 | for (var i=0; i<tempStr.length; i++) |
||
508 | { |
||
509 | switch(tempStr[i]) |
||
510 | { |
||
511 | case "TOP": if (parentObject.childsCount>0) { beforeNode=new Object; beforeNode.tr=parentObject.childNodes[0].tr.previousSibling; } |
||
512 | parentObject._has_top=true; |
||
513 | for (ik=Count; ik>0; ik--) |
||
514 | Nodes[ik]=Nodes[ik-1]; |
||
515 | Count=0; |
||
516 | break; |
||
517 | } |
||
518 | }; |
||
519 | }; |
||
520 | |||
521 | var n; |
||
522 | if (!(n=this._idpull[itemId]) || n.span!=-1){ |
||
523 | n=Nodes[Count]=new dhtmlXTreeItemObject(itemId,itemText,parentObject,this,itemActionHandler,1); |
||
524 | itemId = Nodes[Count].id; |
||
525 | parentObject.childsCount++; |
||
526 | } |
||
527 | |||
528 | if(!n.htmlNode) { |
||
529 | n.label=itemText; |
||
530 | n.htmlNode=this._createItem((this.checkBoxOff?1:0),n); |
||
531 | n.htmlNode.objBelong=n; |
||
532 | } |
||
533 | |||
534 | if(image1) n.images[0]=image1; |
||
535 | if(image2) n.images[1]=image2; |
||
536 | if(image3) n.images[2]=image3; |
||
537 | |||
538 | |||
539 | var tr=this._drawNewTr(n.htmlNode); |
||
540 | if ((this.XMLloadingWarning)||(this._hAdI)) |
||
541 | n.htmlNode.parentNode.parentNode.style.display="none"; |
||
542 | |||
543 | |||
544 | if ((beforeNode)&&beforeNode.tr&&(beforeNode.tr.nextSibling)) |
||
545 | parentObject.htmlNode.childNodes[0].insertBefore(tr,beforeNode.tr.nextSibling); |
||
546 | else |
||
547 | if (this.parsingOn==parentObject.id){ |
||
548 | this.parsedArray[this.parsedArray.length]=tr; |
||
549 | } |
||
550 | else |
||
551 | parentObject.htmlNode.childNodes[0].appendChild(tr); |
||
552 | |||
553 | |||
554 | if ((beforeNode)&&(!beforeNode.span)) beforeNode=null; |
||
555 | |||
556 | if (this.XMLsource) if ((childs)&&(childs!=0)) n.XMLload=0; else n.XMLload=1; |
||
557 | n.tr=tr; |
||
558 | tr.nodem=n; |
||
559 | |||
560 | if (parentObject.itemId==0) |
||
561 | tr.childNodes[0].className="hiddenRow"; |
||
562 | |||
563 | if ((parentObject._r_logic)||(this._frbtr)) |
||
564 | this._setSrc(n.htmlNode.childNodes[0].childNodes[0].childNodes[1].childNodes[0],this.imPath+this.radioArray[0]); |
||
565 | |||
566 | |||
567 | if (optionStr) { |
||
568 | var tempStr=optionStr.split(","); |
||
569 | |||
570 | for (var i=0; i<tempStr.length; i++) |
||
571 | { |
||
572 | switch(tempStr[i]) |
||
573 | { |
||
574 | case "SELECT": this.selectItem(itemId,false); break; |
||
575 | case "CALL": this.selectItem(itemId,true); break; |
||
576 | case "CHILD": n.XMLload=0; break; |
||
577 | case "CHECKED": |
||
578 | if (this.XMLloadingWarning) |
||
579 | this.setCheckList+=this.dlmtr+itemId; |
||
580 | else |
||
581 | this.setCheck(itemId,1); |
||
582 | break; |
||
583 | case "HCHECKED": |
||
584 | this._setCheck(n,"unsure"); |
||
585 | break; |
||
586 | case "OPEN": n.openMe=1; break; |
||
587 | } |
||
588 | }; |
||
589 | }; |
||
590 | |||
591 | if (!this.XMLloadingWarning) |
||
592 | { |
||
593 | if ((this._getOpenState(parentObject)<0)&&(!this._hAdI)) this.openItem(parentObject.id); |
||
594 | |||
595 | if (beforeNode) |
||
596 | { |
||
597 | this._correctPlus(beforeNode); |
||
598 | this._correctLine(beforeNode); |
||
599 | } |
||
600 | this._correctPlus(parentObject); |
||
601 | this._correctLine(parentObject); |
||
602 | this._correctPlus(n); |
||
603 | if (parentObject.childsCount>=2) |
||
604 | { |
||
605 | this._correctPlus(Nodes[parentObject.childsCount-2]); |
||
606 | this._correctLine(Nodes[parentObject.childsCount-2]); |
||
607 | } |
||
608 | if (parentObject.childsCount!=2) this._correctPlus(Nodes[0]); |
||
609 | |||
610 | if (this.tscheck) this._correctCheckStates(parentObject); |
||
611 | |||
612 | if (this._onradh){ |
||
613 | if (this.xmlstate==1){ |
||
614 | var old=this.onXLE; |
||
615 | this.onXLE=function(id){ this._onradh(itemId); if (old) old(id); } |
||
616 | } |
||
617 | else |
||
618 | this._onradh(itemId); |
||
619 | } |
||
620 | |||
621 | } |
||
622 | return n; |
||
623 | }; |
||
624 | |||
625 | |||
626 | |||
627 | |||
628 | /** |
||
629 | * @desc: create new node as a child to specified with parentId |
||
630 | * @type: deprecated |
||
631 | * @param: parentId - parent node id |
||
632 | * @param: itemId - new node id |
||
633 | * @param: itemText - new node text |
||
634 | * @param: itemActionHandler - function fired on node select event (optional) |
||
635 | * @param: image1 - image for node without children; (optional) |
||
636 | * @param: image2 - image for closed node; (optional) |
||
637 | * @param: image3 - image for opened node (optional) |
||
638 | * @param: optionStr - options string (optional) |
||
639 | * @param: children - node children flag (for dynamical trees) (optional) |
||
640 | * @topic: 2 |
||
641 | */ |
||
642 | dhtmlXTreeObject.prototype.insertNewItem=function(parentId,itemId,itemText,itemActionHandler,image1,image2,image3,optionStr,children){ |
||
643 | var parentObject=this._globalIdStorageFind(parentId); |
||
644 | if (!parentObject) return (-1); |
||
645 | var nodez=this._attachChildNode(parentObject,itemId,itemText,itemActionHandler,image1,image2,image3,optionStr,children); |
||
646 | if(!this._idpull[this.rootId].XMLload) |
||
647 | this._idpull[this.rootId].XMLload = 1; |
||
648 | |||
649 | return nodez; |
||
650 | }; |
||
651 | /** |
||
652 | * @desc: create new node as a child to specified with parentId |
||
653 | * @type: public |
||
654 | * @param: parentId - parent node id |
||
655 | * @param: itemId - new node id |
||
656 | * @param: itemText - new node label |
||
657 | * @param: itemActionHandler - function fired on node select event (optional) |
||
658 | * @param: image1 - image for node without children; (optional) |
||
659 | * @param: image2 - image for closed node; (optional) |
||
660 | * @param: image3 - image for opened node (optional) |
||
661 | * @param: optionStr - options string (optional) |
||
662 | * @param: children - node children flag (for dynamical trees) (optional) |
||
663 | * @topic: 2 |
||
664 | */ |
||
665 | dhtmlXTreeObject.prototype.insertNewChild=function(parentId,itemId,itemText,itemActionHandler,image1,image2,image3,optionStr,children){ |
||
666 | return this.insertNewItem(parentId,itemId,itemText,itemActionHandler,image1,image2,image3,optionStr,children); |
||
667 | } |
||
668 | /** |
||
669 | * @desc: parse xml |
||
670 | * @type: private |
||
671 | * @param: dhtmlObject - jsTree object |
||
672 | * @param: node - top XML node |
||
673 | * @param: parentId - parent node id |
||
674 | * @param: level - level of tree |
||
675 | * @topic: 2 |
||
676 | */ |
||
677 | dhtmlXTreeObject.prototype._parseXMLTree=function(a,b,c,d,xml){ |
||
678 | var p=new xmlPointer(xml.getXMLTopNode("tree")); |
||
679 | a._parse(p); |
||
680 | a._p=p; |
||
681 | } |
||
682 | |||
683 | dhtmlXTreeObject.prototype._parseItem=function(c,temp,preNode,befNode){ |
||
684 | var id; |
||
685 | if (this._srnd && (!this._idpull[id=c.get("id")] || !this._idpull[id].span)) |
||
686 | { |
||
687 | this._addItemSRND(temp.id,id,c); |
||
688 | return; |
||
689 | } |
||
690 | |||
691 | var a=c.get_all(); |
||
692 | |||
693 | if ((typeof(this.waitUpdateXML)=="object")&&(!this.waitUpdateXML[a.id])){ |
||
694 | this._parse(c,a.id,1); |
||
695 | return; |
||
696 | } |
||
697 | |||
698 | |||
699 | |||
700 | |||
701 | |||
702 | |||
703 | var zST=[]; |
||
704 | if (a.select) zST.push("SELECT"); |
||
705 | if (a.top) zST.push("TOP"); |
||
706 | if (a.call) this.nodeAskingCall=a.id; |
||
707 | if (a.checked==-1) zST.push("HCHECKED"); |
||
708 | else if (a.checked) zST.push("CHECKED"); |
||
709 | if (a.open) zST.push("OPEN"); |
||
710 | |||
711 | if (this.waitUpdateXML){ |
||
712 | if (this._globalIdStorageFind(a.id)) |
||
713 | var newNode=this.updateItem(a.id,a.text,a.im0,a.im1,a.im2,a.checked,a.child); |
||
714 | else{ |
||
715 | if (this.npl==0) zST.push("TOP"); |
||
716 | else preNode=temp.childNodes[this.npl]; |
||
717 | |||
718 | var newNode=this._attachChildNode(temp,a.id,a.text,0,a.im0,a.im1,a.im2,zST.join(","),a.child,0,preNode); |
||
719 | a.id = newNode.id; |
||
720 | preNode=null; |
||
721 | } |
||
722 | } |
||
723 | else |
||
724 | var newNode=this._attachChildNode(temp,a.id,a.text,0,a.im0,a.im1,a.im2,zST.join(","),a.child,(befNode||0),preNode); |
||
725 | if (a.tooltip) |
||
726 | newNode.span.parentNode.parentNode.title=a.tooltip; |
||
727 | |||
728 | if (a.style) |
||
729 | if (newNode.span.style.cssText) |
||
730 | newNode.span.style.cssText+=(";"+a.style); |
||
731 | else |
||
732 | newNode.span.setAttribute("style",newNode.span.getAttribute("style")+"; "+a.style); |
||
733 | |||
734 | if (a.radio) newNode._r_logic=true; |
||
735 | |||
736 | if (a.nocheckbox){ |
||
737 | var check_node=newNode.span.parentNode.previousSibling.previousSibling; |
||
738 | check_node.style.display="none"; |
||
739 | newNode.nocheckbox=true; |
||
740 | } |
||
741 | if (a.disabled){ |
||
742 | if (a.checked!=null) this._setCheck(newNode,a.checked); |
||
743 | this.disableCheckbox(newNode,1); |
||
744 | } |
||
745 | |||
746 | |||
747 | newNode._acc=a.child||0; |
||
748 | |||
749 | if (this.parserExtension) this.parserExtension._parseExtension.call(this,c,a,(temp?temp.id:0)); |
||
750 | |||
751 | this.setItemColor(newNode,a.aCol,a.sCol); |
||
752 | if (a.locked=="1") this.lockItem(newNode.id,true,true); |
||
753 | |||
754 | if ((a.imwidth)||(a.imheight)) this.setIconSize(a.imwidth,a.imheight,newNode); |
||
755 | if ((a.closeable=="0")||(a.closeable=="1")) this.setItemCloseable(newNode,a.closeable); |
||
756 | var zcall=""; |
||
757 | if (a.topoffset) this.setItemTopOffset(newNode,a.topoffset); |
||
758 | if ((!this.slowParse)||(typeof(this.waitUpdateXML)=="object")){ |
||
759 | if (c.sub_exists("item")) |
||
760 | zcall=this._parse(c,a.id,1); |
||
761 | } |
||
762 | |||
763 | if (zcall!="") this.nodeAskingCall=zcall; |
||
764 | |||
765 | |||
766 | c.each("userdata",function(u){ |
||
767 | this.setUserData(c.get("id"),u.get("name"),u.content()); |
||
768 | },this) |
||
769 | |||
770 | |||
771 | } |
||
772 | dhtmlXTreeObject.prototype._parse=function(p,parentId,level,start){ |
||
773 | if (this._srnd && !this.parentObject.offsetHeight) { |
||
774 | var self=this; |
||
775 | return window.setTimeout(function(){ |
||
776 | self._parse(p,parentId,level,start); |
||
777 | },100); |
||
778 | } |
||
779 | if (!p.exists()) return; |
||
780 | |||
781 | this.skipLock=true; //disable item locking |
||
782 | //loading flags |
||
783 | |||
784 | |||
785 | if (!parentId) { //top level |
||
786 | parentId=p.get("id"); |
||
787 | var skey = p.get("dhx_security"); |
||
788 | if (skey) |
||
789 | dhtmlx.security_key = skey; |
||
790 | |||
791 | if (p.get("radio")) |
||
792 | this.htmlNode._r_logic=true; |
||
793 | this.parsingOn=parentId; |
||
794 | this.parsedArray=new Array(); |
||
795 | this.setCheckList=""; |
||
796 | this.nodeAskingCall=""; |
||
797 | } |
||
798 | |||
799 | var temp=this._globalIdStorageFind(parentId); |
||
800 | if (!temp) return dhtmlxError.throwError("DataStructure","XML refers to not existing parent"); |
||
801 | |||
802 | this.parsCount=this.parsCount?(this.parsCount+1):1; |
||
803 | this.XMLloadingWarning=1; |
||
804 | |||
805 | if ((temp.childsCount)&&(!start)&&(!this._edsbps)&&(!temp._has_top)) |
||
806 | var preNode=0;//temp.childNodes[temp.childsCount-1]; |
||
807 | else |
||
808 | var preNode=0; |
||
809 | |||
810 | this.npl=0; |
||
811 | |||
812 | p.each("item",function(c,i){ |
||
813 | |||
814 | temp.XMLload=1; |
||
815 | |||
816 | this._parseItem(c,temp,0,preNode); |
||
817 | |||
818 | |||
819 | this.npl++; |
||
820 | |||
821 | |||
822 | |||
823 | },this,start); |
||
824 | |||
825 | |||
826 | if (!level) { |
||
827 | p.each("userdata",function(u){ |
||
828 | this.setUserData(p.get("id"),u.get("name"),u.content()); |
||
829 | },this); |
||
830 | |||
831 | temp.XMLload=1; |
||
832 | if (this.waitUpdateXML){ |
||
833 | this.waitUpdateXML=false; |
||
834 | for (var i=temp.childsCount-1; i>=0; i--) |
||
835 | if (temp.childNodes[i]._dmark) |
||
836 | this.deleteItem(temp.childNodes[i].id); |
||
837 | } |
||
838 | |||
839 | var parsedNodeTop=this._globalIdStorageFind(this.parsingOn); |
||
840 | |||
841 | for (var i=0; i<this.parsedArray.length; i++) |
||
842 | temp.htmlNode.childNodes[0].appendChild(this.parsedArray[i]); |
||
843 | this.parsedArray = []; |
||
844 | |||
845 | this.lastLoadedXMLId=parentId; |
||
846 | this.XMLloadingWarning=0; |
||
847 | |||
848 | var chArr=this.setCheckList.split(this.dlmtr); |
||
849 | for (var n=0; n<chArr.length; n++) |
||
850 | if (chArr[n]) this.setCheck(chArr[n],1); |
||
851 | |||
852 | if ((this.XMLsource)&&(this.tscheck)&&(this.smcheck)&&(temp.id!=this.rootId)){ |
||
853 | if (temp.checkstate===0) |
||
854 | this._setSubChecked(0,temp); |
||
855 | else if (temp.checkstate===1) |
||
856 | this._setSubChecked(1,temp); |
||
857 | } |
||
858 | |||
859 | this._redrawFrom(this,null,start) |
||
860 | if (p.get("order") && p.get("order")!="none") |
||
861 | this._reorderBranch(temp,p.get("order"),true); |
||
862 | |||
863 | if (this.nodeAskingCall!="") this.callEvent("onClick",[this.nodeAskingCall,this.getSelectedItemId()]); |
||
864 | if (this._branchUpdate) this._branchUpdateNext(p); |
||
865 | } |
||
866 | |||
867 | |||
868 | if (this.parsCount==1) { |
||
869 | this.parsingOn=null; |
||
870 | |||
871 | |||
872 | |||
873 | if ((!this._edsbps)||(!this._edsbpsA.length)){ |
||
874 | var that=this; |
||
875 | window.setTimeout( function(){ that.callEvent("onXLE",[that,parentId]); },1); |
||
876 | this.xmlstate=0; |
||
877 | } |
||
878 | this.skipLock=false; |
||
879 | } |
||
880 | this.parsCount--; |
||
881 | |||
882 | |||
883 | |||
884 | |||
885 | |||
886 | if (!level && this.onXLE) this.onXLE(this,parentId); |
||
887 | return this.nodeAskingCall; |
||
888 | }; |
||
889 | |||
890 | |||
891 | dhtmlXTreeObject.prototype._branchUpdateNext=function(p){ |
||
892 | p.each("item",function(c){ |
||
893 | var nid=c.get("id"); |
||
894 | if (this._idpull[nid] && (!this._idpull[nid].XMLload)) return; |
||
895 | this._branchUpdate++; |
||
896 | this.smartRefreshItem(c.get("id"),c); |
||
897 | },this) |
||
898 | this._branchUpdate--; |
||
899 | } |
||
900 | |||
901 | dhtmlXTreeObject.prototype.checkUserData=function(node,parentId){ |
||
902 | if ((node.nodeType==1)&&(node.tagName == "userdata")) |
||
903 | { |
||
904 | var name=node.getAttribute("name"); |
||
905 | if ((name)&&(node.childNodes[0])) |
||
906 | this.setUserData(parentId,name,node.childNodes[0].data); |
||
907 | } |
||
908 | } |
||
909 | |||
910 | |||
911 | |||
912 | |||
913 | /** |
||
914 | * @desc: reset tree images from selected level |
||
915 | * @type: private |
||
916 | * @param: dhtmlObject - tree |
||
917 | * @param: itemObject - current item |
||
918 | * @topic: 6 |
||
919 | */ |
||
920 | dhtmlXTreeObject.prototype._redrawFrom=function(dhtmlObject,itemObject,start,visMode){ |
||
921 | if (!itemObject) { |
||
922 | var tempx=dhtmlObject._globalIdStorageFind(dhtmlObject.lastLoadedXMLId); |
||
923 | dhtmlObject.lastLoadedXMLId=-1; |
||
924 | if (!tempx) return 0; |
||
925 | } |
||
926 | else tempx=itemObject; |
||
927 | var acc=0; |
||
928 | for (var i=(start?start-1:0); i<tempx.childsCount; i++) |
||
929 | { |
||
930 | if ((!this._branchUpdate)||(this._getOpenState(tempx)==1)) |
||
931 | if ((!itemObject)||(visMode==1)) tempx.childNodes[i].htmlNode.parentNode.parentNode.style.display=""; |
||
932 | if (tempx.childNodes[i].openMe==1) |
||
933 | { |
||
934 | this._openItem(tempx.childNodes[i]); |
||
935 | tempx.childNodes[i].openMe=0; |
||
936 | } |
||
937 | |||
938 | dhtmlObject._redrawFrom(dhtmlObject,tempx.childNodes[i]); |
||
939 | |||
940 | |||
941 | }; |
||
942 | |||
943 | if ((!tempx.unParsed)&&((tempx.XMLload)||(!this.XMLsource))) |
||
944 | tempx._acc=acc; |
||
945 | dhtmlObject._correctLine(tempx); |
||
946 | dhtmlObject._correctPlus(tempx); |
||
947 | |||
948 | }; |
||
949 | |||
950 | /** |
||
951 | * @desc: create and return main html element of tree |
||
952 | * @type: private |
||
953 | * @topic: 0 |
||
954 | */ |
||
955 | dhtmlXTreeObject.prototype._createSelf=function(){ |
||
956 | var div=document.createElement('div'); |
||
957 | div.className="containerTableStyle"; |
||
958 | div.style.width=this.width; |
||
959 | div.style.height=this.height; |
||
960 | this.parentObject.appendChild(div); |
||
961 | return div; |
||
962 | }; |
||
963 | |||
964 | /** |
||
965 | * @desc: collapse target node |
||
966 | * @type: private |
||
967 | * @param: itemObject - item object |
||
968 | * @topic: 4 |
||
969 | */ |
||
970 | dhtmlXTreeObject.prototype._xcloseAll=function(itemObject) |
||
971 | { |
||
972 | if (itemObject.unParsed) return; |
||
973 | if (this.rootId!=itemObject.id) { |
||
974 | if (!itemObject.htmlNode) return;//srnd |
||
975 | var Nodes=itemObject.htmlNode.childNodes[0].childNodes; |
||
976 | var Count=Nodes.length; |
||
977 | |||
978 | for (var i=1; i<Count; i++) |
||
979 | Nodes[i].style.display="none"; |
||
980 | |||
981 | this._correctPlus(itemObject); |
||
982 | } |
||
983 | |||
984 | for (var i=0; i<itemObject.childsCount; i++) |
||
985 | if (itemObject.childNodes[i].childsCount) |
||
986 | this._xcloseAll(itemObject.childNodes[i]); |
||
987 | }; |
||
988 | /** |
||
989 | * @desc: expand target node |
||
990 | * @type: private |
||
991 | * @param: itemObject - item object |
||
992 | * @topic: 4 |
||
993 | */ |
||
994 | dhtmlXTreeObject.prototype._xopenAll=function(itemObject) |
||
995 | { |
||
996 | this._HideShow(itemObject,2); |
||
997 | for (var i=0; i<itemObject.childsCount; i++) |
||
998 | this._xopenAll(itemObject.childNodes[i]); |
||
999 | }; |
||
1000 | /** |
||
1001 | * @desc: set correct tree-line and node images |
||
1002 | * @type: private |
||
1003 | * @param: itemObject - item object |
||
1004 | * @topic: 6 |
||
1005 | */ |
||
1006 | dhtmlXTreeObject.prototype._correctPlus=function(itemObject){ |
||
1007 | if (!itemObject.htmlNode) return; |
||
1008 | var imsrc=itemObject.htmlNode.childNodes[0].childNodes[0].childNodes[0].lastChild; |
||
1009 | var imsrc2=itemObject.htmlNode.childNodes[0].childNodes[0].childNodes[2].childNodes[0]; |
||
1010 | |||
1011 | var workArray=this.lineArray; |
||
1012 | if ((this.XMLsource)&&(!itemObject.XMLload)) |
||
1013 | { |
||
1014 | var workArray=this.plusArray; |
||
1015 | this._setSrc(imsrc2,this.iconURL+itemObject.images[2]); |
||
1016 | if (this._txtimg) return (imsrc.innerHTML="[+]"); |
||
1017 | } |
||
1018 | else |
||
1019 | if ((itemObject.childsCount)||(itemObject.unParsed)) |
||
1020 | { |
||
1021 | if ((itemObject.htmlNode.childNodes[0].childNodes[1])&&( itemObject.htmlNode.childNodes[0].childNodes[1].style.display!="none" )) |
||
1022 | { |
||
1023 | if (!itemObject.wsign) var workArray=this.minusArray; |
||
1024 | this._setSrc(imsrc2,this.iconURL+itemObject.images[1]); |
||
1025 | if (this._txtimg) return (imsrc.innerHTML="[-]"); |
||
1026 | } |
||
1027 | else |
||
1028 | { |
||
1029 | if (!itemObject.wsign) var workArray=this.plusArray; |
||
1030 | this._setSrc(imsrc2,this.iconURL+itemObject.images[2]); |
||
1031 | if (this._txtimg) return (imsrc.innerHTML="[+]"); |
||
1032 | } |
||
1033 | } |
||
1034 | else |
||
1035 | { |
||
1036 | this._setSrc(imsrc2,this.iconURL+itemObject.images[0]); |
||
1037 | } |
||
1038 | |||
1039 | |||
1040 | var tempNum=2; |
||
1041 | if (!itemObject.treeNod.treeLinesOn) this._setSrc(imsrc,this.imPath+workArray[3]); |
||
1042 | else { |
||
1043 | if (itemObject.parentObject) tempNum=this._getCountStatus(itemObject.id,itemObject.parentObject); |
||
1044 | this._setSrc(imsrc,this.imPath+workArray[tempNum]); |
||
1045 | } |
||
1046 | }; |
||
1047 | |||
1048 | /** |
||
1049 | * @desc: set correct tree-line images |
||
1050 | * @type: private |
||
1051 | * @param: itemObject - item object |
||
1052 | * @topic: 6 |
||
1053 | */ |
||
1054 | dhtmlXTreeObject.prototype._correctLine=function(itemObject){ |
||
1055 | if (!itemObject.htmlNode) return; |
||
1056 | var sNode=itemObject.parentObject; |
||
1057 | if (sNode) |
||
1058 | if ((this._getLineStatus(itemObject.id,sNode)==0)||(!this.treeLinesOn)) |
||
1059 | for(var i=1; i<=itemObject.childsCount; i++){ |
||
1060 | if (!itemObject.htmlNode.childNodes[0].childNodes[i]) break; |
||
1061 | itemObject.htmlNode.childNodes[0].childNodes[i].childNodes[0].style.backgroundImage=""; |
||
1062 | itemObject.htmlNode.childNodes[0].childNodes[i].childNodes[0].style.backgroundRepeat=""; |
||
1063 | } |
||
1064 | else |
||
1065 | for(var i=1; i<=itemObject.childsCount; i++){ |
||
1066 | if (!itemObject.htmlNode.childNodes[0].childNodes[i]) break; |
||
1067 | itemObject.htmlNode.childNodes[0].childNodes[i].childNodes[0].style.backgroundImage="url("+this.imPath+this.lineArray[5]+")"; |
||
1068 | itemObject.htmlNode.childNodes[0].childNodes[i].childNodes[0].style.backgroundRepeat="repeat-y"; |
||
1069 | } |
||
1070 | }; |
||
1071 | /** |
||
1072 | * @desc: return type of node |
||
1073 | * @type: private |
||
1074 | * @param: itemId - item id |
||
1075 | * @param: itemObject - parent node object |
||
1076 | * @topic: 6 |
||
1077 | */ |
||
1078 | dhtmlXTreeObject.prototype._getCountStatus=function(itemId,itemObject){ |
||
1079 | if (itemObject.childsCount<=1) { if (itemObject.id==this.rootId) return 4; else return 0; } |
||
1080 | |||
1081 | if (itemObject.childNodes[0].id==itemId) if (itemObject.id==this.rootId) return 2; else return 1; |
||
1082 | if (itemObject.childNodes[itemObject.childsCount-1].id==itemId) return 0; |
||
1083 | |||
1084 | return 1; |
||
1085 | }; |
||
1086 | /** |
||
1087 | * @desc: return type of node |
||
1088 | * @type: private |
||
1089 | * @param: itemId - node id |
||
1090 | * @param: itemObject - parent node object |
||
1091 | * @topic: 6 |
||
1092 | */ |
||
1093 | dhtmlXTreeObject.prototype._getLineStatus =function(itemId,itemObject){ |
||
1094 | if (itemObject.childNodes[itemObject.childsCount-1].id==itemId) return 0; |
||
1095 | return 1; |
||
1096 | } |
||
1097 | |||
1098 | /** |
||
1099 | * @desc: open/close node |
||
1100 | * @type: private |
||
1101 | * @param: itemObject - node object |
||
1102 | * @param: mode - open/close mode [1-close 2-open](optional) |
||
1103 | * @topic: 6 |
||
1104 | */ |
||
1105 | dhtmlXTreeObject.prototype._HideShow=function(itemObject,mode){ |
||
1106 | if ((this.XMLsource)&&(!itemObject.XMLload)) { |
||
1107 | if (mode==1) return; //close for not loaded node - ignore it |
||
1108 | itemObject.XMLload=1; |
||
1109 | this._loadDynXML(itemObject.id); |
||
1110 | return; }; |
||
1111 | |||
1112 | var Nodes=itemObject.htmlNode.childNodes[0].childNodes; var Count=Nodes.length; |
||
1113 | if (Count>1){ |
||
1114 | if ( ( (Nodes[1].style.display!="none") || (mode==1) ) && (mode!=2) ) { |
||
1115 | //nb:solves standard doctype prb in IE |
||
1116 | this.allTree.childNodes[0].border = "1"; |
||
1117 | this.allTree.childNodes[0].border = "0"; |
||
1118 | nodestyle="none"; |
||
1119 | } |
||
1120 | else nodestyle=""; |
||
1121 | |||
1122 | for (var i=1; i<Count; i++) |
||
1123 | Nodes[i].style.display=nodestyle; |
||
1124 | } |
||
1125 | this._correctPlus(itemObject); |
||
1126 | } |
||
1127 | |||
1128 | /** |
||
1129 | * @desc: return node state |
||
1130 | * @type: private |
||
1131 | * @param: itemObject - node object |
||
1132 | * @topic: 6 |
||
1133 | */ |
||
1134 | dhtmlXTreeObject.prototype._getOpenState=function(itemObject){ |
||
1135 | if (!itemObject.htmlNode) return 0; //srnd |
||
1136 | var z=itemObject.htmlNode.childNodes[0].childNodes; |
||
1137 | if (z.length<=1) return 0; |
||
1138 | if (z[1].style.display!="none") return 1; |
||
1139 | else return -1; |
||
1140 | } |
||
1141 | |||
1142 | |||
1143 | |||
1144 | /** |
||
1145 | * @desc: ondblclick item event handler |
||
1146 | * @type: private |
||
1147 | * @topic: 0 |
||
1148 | */ |
||
1149 | dhtmlXTreeObject.prototype.onRowClick2=function(){ |
||
1150 | var that=this.parentObject.treeNod; |
||
1151 | if (!that.callEvent("onDblClick",[this.parentObject.id,that])) return false; |
||
1152 | if ((this.parentObject.closeble)&&(this.parentObject.closeble!="0")) |
||
1153 | that._HideShow(this.parentObject); |
||
1154 | else |
||
1155 | that._HideShow(this.parentObject,2); |
||
1156 | |||
1157 | if (that.checkEvent("onOpenEnd")) |
||
1158 | if (!that.xmlstate) |
||
1159 | that.callEvent("onOpenEnd",[this.parentObject.id,that._getOpenState(this.parentObject)]); |
||
1160 | else{ |
||
1161 | that._oie_onXLE.push(that.onXLE); |
||
1162 | that.onXLE=that._epnFHe; |
||
1163 | } |
||
1164 | return false; |
||
1165 | }; |
||
1166 | /** |
||
1167 | * @desc: onclick item event handler |
||
1168 | * @type: private |
||
1169 | * @topic: 0 |
||
1170 | */ |
||
1171 | dhtmlXTreeObject.prototype.onRowClick=function(){ |
||
1172 | var that=this.parentObject.treeNod; |
||
1173 | if (!that.callEvent("onOpenStart",[this.parentObject.id,that._getOpenState(this.parentObject)])) return 0; |
||
1174 | if ((this.parentObject.closeble)&&(this.parentObject.closeble!="0")) |
||
1175 | that._HideShow(this.parentObject); |
||
1176 | else |
||
1177 | that._HideShow(this.parentObject,2); |
||
1178 | |||
1179 | |||
1180 | if (that.checkEvent("onOpenEnd")) |
||
1181 | if (!that.xmlstate) |
||
1182 | that.callEvent("onOpenEnd",[this.parentObject.id,that._getOpenState(this.parentObject)]); |
||
1183 | else{ |
||
1184 | that._oie_onXLE.push(that.onXLE); |
||
1185 | that.onXLE=that._epnFHe; |
||
1186 | } |
||
1187 | |||
1188 | }; |
||
1189 | |||
1190 | dhtmlXTreeObject.prototype._epnFHe=function(that,id,flag){ |
||
1191 | if (id!=this.rootId) |
||
1192 | this.callEvent("onOpenEnd",[id,that.getOpenState(id)]); |
||
1193 | that.onXLE=that._oie_onXLE.pop(); |
||
1194 | |||
1195 | if (!flag && !that._oie_onXLE.length) |
||
1196 | if (that.onXLE) that.onXLE(that,id); |
||
1197 | } |
||
1198 | |||
1199 | |||
1200 | |||
1201 | /** |
||
1202 | * @desc: onclick item image event handler |
||
1203 | * @type: private |
||
1204 | * @edition: Professional |
||
1205 | * @topic: 0 |
||
1206 | */ |
||
1207 | dhtmlXTreeObject.prototype.onRowClickDown=function(e){ |
||
1208 | e=e||window.event; |
||
1209 | var that=this.parentObject.treeNod; |
||
1210 | that._selectItem(this.parentObject,e); |
||
1211 | }; |
||
1212 | |||
1213 | |||
1214 | /***** |
||
1215 | SELECTION |
||
1216 | *****/ |
||
1217 | |||
1218 | /** |
||
1219 | * @desc: retun selected item id |
||
1220 | * @type: public |
||
1221 | * @return: id of selected item |
||
1222 | * @topic: 1 |
||
1223 | */ |
||
1224 | dhtmlXTreeObject.prototype.getSelectedItemId=function() |
||
1225 | { |
||
1226 | var str=new Array(); |
||
1227 | for (var i=0; i<this._selected.length; i++) str[i]=this._selected[i].id; |
||
1228 | return (str.join(this.dlmtr)); |
||
1229 | }; |
||
1230 | |||
1231 | /** |
||
1232 | * @desc: visual select item in tree |
||
1233 | * @type: private |
||
1234 | * @param: node - tree item object |
||
1235 | * @param: mode - true suppress onSelect |
||
1236 | * @edition: Professional |
||
1237 | * @topic: 0 |
||
1238 | */ |
||
1239 | dhtmlXTreeObject.prototype._selectItem=function(node,e,mode){ |
||
1240 | if (typeof mode == 'undefined') mode=false; |
||
1241 | if (!mode && this.checkEvent("onSelect")) this._onSSCFold=this.getSelectedItemId(); |
||
1242 | |||
1243 | if ((!this._amsel) || (!e) || ((!e.ctrlKey) && (!e.metaKey) && (!e.shiftKey))) { |
||
1244 | this._unselectItems() |
||
1245 | } |
||
1246 | if ((node.i_sel) && (this._amsel) && (e) && (e.ctrlKey || e.metaKey)) { |
||
1247 | this._unselectItem(node) |
||
1248 | } else { |
||
1249 | if ((!node.i_sel) && ((!this._amselS) || (this._selected.length == 0) || (this._selected[0].parentObject == node.parentObject))) { |
||
1250 | if ((this._amsel) && (e) && (e.shiftKey) && (this._selected.length != 0) && (this._selected[this._selected.length - 1].parentObject == node.parentObject)) { |
||
1251 | var f = this._getIndex(this._selected[this._selected.length - 1]); |
||
1252 | var d = this._getIndex(node); |
||
1253 | if (d < f) { |
||
1254 | var l = f; |
||
1255 | f = d; |
||
1256 | d = l |
||
1257 | } |
||
1258 | for (var g = f; g <= d; g++) { |
||
1259 | if (!node.parentObject.childNodes[g].i_sel) { |
||
1260 | this._markItem(node.parentObject.childNodes[g]) |
||
1261 | } |
||
1262 | } |
||
1263 | } else { |
||
1264 | this._markItem(node) |
||
1265 | } |
||
1266 | } |
||
1267 | } |
||
1268 | if (!mode && this.checkEvent("onSelect")) { |
||
1269 | var z=this.getSelectedItemId(); |
||
1270 | if (z!=this._onSSCFold) |
||
1271 | this.callEvent("onSelect",[z]); |
||
1272 | } |
||
1273 | } |
||
1274 | dhtmlXTreeObject.prototype._markItem=function(node){ |
||
1275 | if (node.scolor) node.span.style.color=node.scolor; |
||
1276 | node.span.className="selectedTreeRow"; |
||
1277 | node.i_sel=true; |
||
1278 | this._selected[this._selected.length]=node; |
||
1279 | } |
||
1280 | |||
1281 | /** |
||
1282 | * @desc: retun node index in children collection by Id |
||
1283 | * @type: public |
||
1284 | * @param: itemId - node id |
||
1285 | * @return: node index |
||
1286 | * @topic: 2 |
||
1287 | */ |
||
1288 | dhtmlXTreeObject.prototype.getIndexById=function(itemId){ |
||
1289 | var z=this._globalIdStorageFind(itemId); |
||
1290 | if (!z) return null; |
||
1291 | return this._getIndex(z); |
||
1292 | }; |
||
1293 | dhtmlXTreeObject.prototype._getIndex=function(w){ |
||
1294 | var z=w.parentObject; |
||
1295 | for (var i=0; i<z.childsCount; i++) |
||
1296 | if (z.childNodes[i]==w) return i; |
||
1297 | }; |
||
1298 | |||
1299 | |||
1300 | |||
1301 | |||
1302 | |||
1303 | /** |
||
1304 | * @desc: visual unselect item in tree |
||
1305 | * @type: private |
||
1306 | * @param: node - tree item object |
||
1307 | * @edition: Professional |
||
1308 | * @topic: 0 |
||
1309 | */ |
||
1310 | dhtmlXTreeObject.prototype._unselectItem=function(node){ |
||
1311 | if ((node)&&(node.i_sel)) |
||
1312 | { |
||
1313 | |||
1314 | node.span.className="standartTreeRow"; |
||
1315 | if (node.acolor) node.span.style.color=node.acolor; |
||
1316 | node.i_sel=false; |
||
1317 | for (var i=0; i<this._selected.length; i++) |
||
1318 | if (!this._selected[i].i_sel) { |
||
1319 | this._selected.splice(i,1); |
||
1320 | break; |
||
1321 | } |
||
1322 | } |
||
1323 | } |
||
1324 | |||
1325 | /** |
||
1326 | * @desc: visual unselect items in tree |
||
1327 | * @type: private |
||
1328 | * @param: node - tree item object |
||
1329 | * @edition: Professional |
||
1330 | * @topic: 0 |
||
1331 | */ |
||
1332 | dhtmlXTreeObject.prototype._unselectItems=function(){ |
||
1333 | for (var i=0; i<this._selected.length; i++){ |
||
1334 | var node=this._selected[i]; |
||
1335 | node.span.className="standartTreeRow"; |
||
1336 | if (node.acolor) node.span.style.color=node.acolor; |
||
1337 | node.i_sel=false; |
||
1338 | } |
||
1339 | this._selected=new Array(); |
||
1340 | } |
||
1341 | |||
1342 | |||
1343 | /** |
||
1344 | * @desc: select node text event handler |
||
1345 | * @type: private |
||
1346 | * @param: e - event object |
||
1347 | * @param: htmlObject - node object |
||
1348 | * @param: mode - if false - call onSelect event |
||
1349 | * @topic: 0 |
||
1350 | */ |
||
1351 | dhtmlXTreeObject.prototype.onRowSelect=function(e,htmlObject,mode){ |
||
1352 | e=e||window.event; |
||
1353 | |||
1354 | var obj=this.parentObject; |
||
1355 | if (htmlObject) obj=htmlObject.parentObject; |
||
1356 | var that=obj.treeNod; |
||
1357 | |||
1358 | var lastId=that.getSelectedItemId(); |
||
1359 | if ((!e)||(!e.skipUnSel)) |
||
1360 | that._selectItem(obj,e,mode); |
||
1361 | |||
1362 | if (!mode) { |
||
1363 | if (obj.actionHandler) obj.actionHandler(obj.id,lastId); |
||
1364 | else that.callEvent("onClick",[obj.id,lastId]); |
||
1365 | } |
||
1366 | }; |
||
1367 | |||
1368 | |||
1369 | |||
1370 | |||
1371 | |||
1372 | /** |
||
1373 | * @desc: fix checkbox state |
||
1374 | * @type: private |
||
1375 | * @topic: 0 |
||
1376 | */ |
||
1377 | dhtmlXTreeObject.prototype._correctCheckStates=function(dhtmlObject){ |
||
1378 | |||
1379 | if (!this.tscheck) return; |
||
1380 | if (!dhtmlObject) return; |
||
1381 | if (dhtmlObject.id==this.rootId) return; |
||
1382 | //calculate state |
||
1383 | var act=dhtmlObject.childNodes; |
||
1384 | var flag1=0; var flag2=0; |
||
1385 | if (dhtmlObject.childsCount==0) return; |
||
1386 | for (var i=0; i<dhtmlObject.childsCount; i++){ |
||
1387 | if (act[i].dscheck) continue; |
||
1388 | if (act[i].checkstate==0) flag1=1; |
||
1389 | else if (act[i].checkstate==1) flag2=1; |
||
1390 | else { flag1=1; flag2=1; break; } |
||
1391 | } |
||
1392 | |||
1393 | if ((flag1)&&(flag2)) this._setCheck(dhtmlObject,"unsure"); |
||
1394 | else if (flag1) this._setCheck(dhtmlObject,false); |
||
1395 | else this._setCheck(dhtmlObject,true); |
||
1396 | |||
1397 | this._correctCheckStates(dhtmlObject.parentObject); |
||
1398 | } |
||
1399 | |||
1400 | /** |
||
1401 | * @desc: checbox select action |
||
1402 | * @type: private |
||
1403 | * @topic: 0 |
||
1404 | */ |
||
1405 | dhtmlXTreeObject.prototype.onCheckBoxClick=function(e){ |
||
1406 | if (!this.treeNod.callEvent("onBeforeCheck",[this.parentObject.id,this.parentObject.checkstate])) |
||
1407 | return; |
||
1408 | |||
1409 | if (this.parentObject.dscheck) return true; |
||
1410 | if (this.treeNod.tscheck) |
||
1411 | if (this.parentObject.checkstate==1) this.treeNod._setSubChecked(false,this.parentObject); |
||
1412 | else this.treeNod._setSubChecked(true,this.parentObject); |
||
1413 | else |
||
1414 | if (this.parentObject.checkstate==1) this.treeNod._setCheck(this.parentObject,false); |
||
1415 | else this.treeNod._setCheck(this.parentObject,true); |
||
1416 | this.treeNod._correctCheckStates(this.parentObject.parentObject); |
||
1417 | |||
1418 | return this.treeNod.callEvent("onCheck",[this.parentObject.id,this.parentObject.checkstate]); |
||
1419 | }; |
||
1420 | /** |
||
1421 | * @desc: create HTML elements for tree node |
||
1422 | * @type: private |
||
1423 | * @param: acheck - enable/disable checkbox |
||
1424 | * @param: itemObject - item object |
||
1425 | * @param: mode - mode |
||
1426 | * @topic: 0 |
||
1427 | */ |
||
1428 | View Code Duplication | dhtmlXTreeObject.prototype._createItem=function(acheck,itemObject,mode){ |
|
1429 | |||
1430 | var table=document.createElement('table'); |
||
1431 | table.cellSpacing=0;table.cellPadding=0; |
||
1432 | table.border=0; |
||
1433 | |||
1434 | if(this.hfMode)table.style.tableLayout="fixed"; |
||
1435 | table.style.margin=0;table.style.padding=0; |
||
1436 | |||
1437 | var tbody=document.createElement('tbody'); |
||
1438 | var tr=document.createElement('tr'); |
||
1439 | |||
1440 | var td1=document.createElement('td'); |
||
1441 | td1.className="standartTreeImage"; |
||
1442 | |||
1443 | if(this._txtimg){ |
||
1444 | var img0=document.createElement("div"); |
||
1445 | td1.appendChild(img0); |
||
1446 | img0.className="dhx_tree_textSign"; |
||
1447 | } |
||
1448 | else |
||
1449 | { |
||
1450 | var img0=this._getImg(itemObject.id); |
||
1451 | img0.border="0"; |
||
1452 | if (img0.tagName=="IMG") img0.align="absmiddle"; |
||
1453 | td1.appendChild(img0); img0.style.padding=0; img0.style.margin=0; |
||
1454 | img0.style.width=this.def_line_img_x; img0.style.height=this.def_line_img_y; |
||
1455 | } |
||
1456 | |||
1457 | var td11=document.createElement('td'); |
||
1458 | // var inp=document.createElement("input"); inp.type="checkbox"; inp.style.width="12px"; inp.style.height="12px"; |
||
1459 | var inp=this._getImg(this.cBROf?this.rootId:itemObject.id); |
||
1460 | inp.checked=0; this._setSrc(inp,this.imPath+this.checkArray[0]); inp.style.width="16px"; inp.style.height="16px"; |
||
1461 | //can cause problems with hide/show check |
||
1462 | |||
1463 | if (!acheck) td11.style.display="none"; |
||
1464 | |||
1465 | // td11.className="standartTreeImage"; |
||
1466 | //if (acheck) |
||
1467 | td11.appendChild(inp); |
||
1468 | if ((!this.cBROf)&&(inp.tagName=="IMG")) inp.align="absmiddle"; |
||
1469 | inp.onclick=this.onCheckBoxClick; |
||
1470 | inp.treeNod=this; |
||
1471 | inp.parentObject=itemObject; |
||
1472 | if (!window._KHTMLrv) td11.width="20px"; |
||
1473 | else td11.width="16px"; |
||
1474 | |||
1475 | var td12=document.createElement('td'); |
||
1476 | td12.className="standartTreeImage"; |
||
1477 | var img=this._getImg(this.timgen?itemObject.id:this.rootId); |
||
1478 | img.onmousedown=this._preventNsDrag; img.ondragstart=this._preventNsDrag; |
||
1479 | img.border="0"; |
||
1480 | if (this._aimgs){ |
||
1481 | img.parentObject=itemObject; |
||
1482 | if (img.tagName=="IMG") img.align="absmiddle"; |
||
1483 | img.onclick=this.onRowSelect; } |
||
1484 | if (!mode) this._setSrc(img,this.iconURL+this.imageArray[0]); |
||
1485 | td12.appendChild(img); img.style.padding=0; img.style.margin=0; |
||
1486 | if (this.timgen) |
||
1487 | { |
||
1488 | td12.style.width=img.style.width=this.def_img_x; img.style.height=this.def_img_y; } |
||
1489 | else |
||
1490 | { |
||
1491 | img.style.width="0px"; img.style.height="0px"; |
||
1492 | if (_isOpera || window._KHTMLrv ) td12.style.display="none"; |
||
1493 | } |
||
1494 | |||
1495 | |||
1496 | var td2=document.createElement('td'); |
||
1497 | td2.className="standartTreeRow"; |
||
1498 | |||
1499 | itemObject.span=document.createElement('span'); |
||
1500 | itemObject.span.className="standartTreeRow"; |
||
1501 | if (this.mlitems) { |
||
1502 | itemObject.span.style.width=this.mlitems; |
||
1503 | // if (!_isIE) |
||
1504 | itemObject.span.style.display="block"; |
||
1505 | } |
||
1506 | else td2.noWrap=true; |
||
1507 | if (_isIE && _isIE>7) td2.style.width="999999px"; |
||
1508 | else if (!window._KHTMLrv) td2.style.width="100%"; |
||
1509 | |||
1510 | // itemObject.span.appendChild(document.createTextNode(itemObject.label)); |
||
1511 | itemObject.span.innerHTML=itemObject.label; |
||
1512 | td2.appendChild(itemObject.span); |
||
1513 | td2.parentObject=itemObject; td1.parentObject=itemObject; |
||
1514 | td2.onclick=this.onRowSelect; td1.onclick=this.onRowClick; td2.ondblclick=this.onRowClick2; |
||
1515 | if (this.ettip) |
||
1516 | tr.title=itemObject.label; |
||
1517 | |||
1518 | if (this.dragAndDropOff) { |
||
1519 | if (this._aimgs) { this.dragger.addDraggableItem(td12,this); td12.parentObject=itemObject; } |
||
1520 | this.dragger.addDraggableItem(td2,this); |
||
1521 | } |
||
1522 | |||
1523 | itemObject.span.style.paddingLeft="5px"; itemObject.span.style.paddingRight="5px"; td2.style.verticalAlign=""; |
||
1524 | td2.style.fontSize="10pt"; td2.style.cursor=this.style_pointer; |
||
1525 | tr.appendChild(td1); tr.appendChild(td11); tr.appendChild(td12); |
||
1526 | tr.appendChild(td2); |
||
1527 | tbody.appendChild(tr); |
||
1528 | table.appendChild(tbody); |
||
1529 | |||
1530 | if (this.ehlt || this.checkEvent("onMouseIn") || this.checkEvent("onMouseOut")){//highlighting |
||
1531 | tr.onmousemove=this._itemMouseIn; |
||
1532 | tr[(_isIE)?"onmouseleave":"onmouseout"]=this._itemMouseOut; |
||
1533 | } |
||
1534 | return table; |
||
1535 | }; |
||
1536 | |||
1537 | |||
1538 | /** |
||
1539 | * @desc: set path to images directory |
||
1540 | * @param: newPath - path to images directory (related to the page with tree or absolute http url) |
||
1541 | * @type: public |
||
1542 | * @topic: 0 |
||
1543 | */ |
||
1544 | dhtmlXTreeObject.prototype.setImagePath=function( newPath ){ this.imPath=newPath; this.iconURL=newPath; }; |
||
1545 | /** |
||
1546 | * @desc: set path to external images used as tree icons |
||
1547 | * @type: public |
||
1548 | * @param: path - url (or relative path) of images folder with closing "/" |
||
1549 | * @topic: 0,7 |
||
1550 | */ |
||
1551 | dhtmlXTreeObject.prototype.setIconPath=function(path){ |
||
1552 | this.iconURL=path; |
||
1553 | } |
||
1554 | |||
1555 | |||
1556 | |||
1557 | /** |
||
1558 | * @desc: set function called when tree node selected |
||
1559 | * @param: (function) func - event handling function |
||
1560 | * @type: deprecated |
||
1561 | * @topic: 0,7 |
||
1562 | * @event: onRightClick |
||
1563 | * @depricated: use grid.attachEvent("onRightClick",func); instead |
||
1564 | * @eventdesc: Event occurs after right mouse button was clicked. |
||
1565 | Assigning this handler can disable default context menu, and incompattible with dhtmlXMenu integration. |
||
1566 | * @eventparam: (string) ID of clicked item |
||
1567 | * @eventparam: (object) event object |
||
1568 | */ |
||
1569 | dhtmlXTreeObject.prototype.setOnRightClickHandler=function(func){ this.attachEvent("onRightClick",func); }; |
||
1570 | |||
1571 | /** |
||
1572 | * @desc: set function called when tree node clicked, also can be forced to call from API |
||
1573 | * @param: func - event handling function |
||
1574 | * @type: deprecated |
||
1575 | * @topic: 0,7 |
||
1576 | * @event: onClick |
||
1577 | * @depricated: use grid.attachEvent("onClick",func); instead |
||
1578 | * @eventdesc: Event raises immideatly after text part of item in tree was clicked, but after default onClick functionality was processed. |
||
1579 | Richt mouse button click can be catched by onRightClick event handler. |
||
1580 | * @eventparam: ID of clicked item |
||
1581 | * @eventparam: ID of previously selected item |
||
1582 | */ |
||
1583 | dhtmlXTreeObject.prototype.setOnClickHandler=function(func){ this.attachEvent("onClick",func); }; |
||
1584 | |||
1585 | /** |
||
1586 | * @desc: set function called when tree node selected or unselected, include any select change caused by any functionality |
||
1587 | * @param: func - event handling function |
||
1588 | * @type: deprecated |
||
1589 | * @topic: 0,7 |
||
1590 | * @event: onSelect |
||
1591 | * @depricated: use grid.attachEvent("onSelect",func); instead |
||
1592 | * @eventdesc: Event raises immideatly after selection in tree was changed |
||
1593 | * @eventparam: selected item ID ( list of IDs in case of multiselection) |
||
1594 | */ |
||
1595 | dhtmlXTreeObject.prototype.setOnSelectStateChange=function(func){ this.attachEvent("onSelect",func); }; |
||
1596 | |||
1597 | |||
1598 | /** |
||
1599 | * @desc: enables dynamic loading from XML |
||
1600 | * @type: public |
||
1601 | * @param: filePath - name of script returning XML; in case of virtual loading - user defined function |
||
1602 | * @topic: 0 |
||
1603 | */ |
||
1604 | dhtmlXTreeObject.prototype.setXMLAutoLoading=function(filePath){ this.XMLsource=filePath; }; |
||
1605 | |||
1606 | /** |
||
1607 | * @desc: set function called before checkbox checked/unchecked |
||
1608 | * @param: func - event handling function |
||
1609 | * @type: deprecated |
||
1610 | * @topic: 0,7 |
||
1611 | * @event: onCheck |
||
1612 | * @depricated: use tree.attachEvent("onCheck",func); instead |
||
1613 | * @eventdesc: Event raises right before item in tree was checked/unchecked. can be canceled (return false from event handler) |
||
1614 | * @eventparam: ID of item which will be checked/unchecked |
||
1615 | * @eventparam: Current checkbox state. 1 - item checked, 0 - item unchecked. |
||
1616 | * @eventreturn: true - confirm changing checked state; false - deny chaning checked state; |
||
1617 | */ |
||
1618 | dhtmlXTreeObject.prototype.setOnCheckHandler=function(func){ this.attachEvent("onCheck",func); }; |
||
1619 | |||
1620 | |||
1621 | /** |
||
1622 | * @desc: set function called before tree node opened/closed |
||
1623 | * @param: func - event handling function |
||
1624 | * @type: deprecated |
||
1625 | * @topic: 0,7 |
||
1626 | * @event: onOpen |
||
1627 | * @depricated: use grid.attachEvent("onOpenStart",func); instead |
||
1628 | * @eventdesc: Event raises immideatly after item in tree got command to open/close , and before item was opened//closed. Event also raised for unclosable nodes and nodes without open/close functionality - in that case result of function will be ignored. |
||
1629 | Event does not occur if node was opened by dhtmlXtree API. |
||
1630 | * @eventparam: ID of node which will be opened/closed |
||
1631 | * @eventparam: Current open state of tree item. 0 - item has not children, -1 - item closed, 1 - item opened. |
||
1632 | * @eventreturn: true - confirm opening/closing; false - deny opening/closing; |
||
1633 | */ |
||
1634 | dhtmlXTreeObject.prototype.setOnOpenHandler=function(func){ this.attachEvent("onOpenStart",func); }; |
||
1635 | /** |
||
1636 | * @desc: set function called before tree node opened/closed |
||
1637 | * @param: func - event handling function |
||
1638 | * @type: deprecated |
||
1639 | * @topic: 0,7 |
||
1640 | * @event: onOpenStart |
||
1641 | * @depricated: use grid.attachEvent("onOpenStart",func); instead |
||
1642 | * @eventdesc: Event raises immideatly after item in tree got command to open/close , and before item was opened//closed. Event also raised for unclosable nodes and nodes without open/close functionality - in that case result of function will be ignored. |
||
1643 | Event not raised if node opened by dhtmlXtree API. |
||
1644 | * @eventparam: ID of node which will be opened/closed |
||
1645 | * @eventparam: Current open state of tree item. 0 - item has not children, -1 - item closed, 1 - item opened. |
||
1646 | * @eventreturn: true - confirm opening/closing; false - deny opening/closing; |
||
1647 | */ |
||
1648 | dhtmlXTreeObject.prototype.setOnOpenStartHandler=function(func){ this.attachEvent("onOpenStart",func); }; |
||
1649 | |||
1650 | /** |
||
1651 | * @desc: set function called after tree node opened/closed |
||
1652 | * @param: func - event handling function |
||
1653 | * @type: deprecated |
||
1654 | * @topic: 0,7 |
||
1655 | * @event: onOpenEnd |
||
1656 | * @depricated: use grid.attachEvent("onOpenEnd",func); instead |
||
1657 | * @eventdesc: Event raises immideatly after item in tree was opened//closed. Event also raised for unclosable nodes and nodes without open/close functionality - in that case result of function will be ignored. |
||
1658 | Event not raised if node opened by dhtmlXtree API. |
||
1659 | * @eventparam: ID of node which will be opened/closed |
||
1660 | * @eventparam: Current open state of tree item. 0 - item has not children, -1 - item closed, 1 - item opened. |
||
1661 | */ |
||
1662 | dhtmlXTreeObject.prototype.setOnOpenEndHandler=function(func){ this.attachEvent("onOpenEnd",func); }; |
||
1663 | |||
1664 | /** |
||
1665 | * @desc: set function called when tree node double clicked |
||
1666 | * @param: func - event handling function |
||
1667 | * @type: public |
||
1668 | * @topic: 0,7 |
||
1669 | * @event: onDblClick |
||
1670 | * @depricated: use grid.attachEvent("onDblClick",func); instead |
||
1671 | * @eventdesc: Event raised immideatly after item in tree was doubleclicked, before default onDblClick functionality was processed. |
||
1672 | Beware using both onClick and onDblClick events, because component can generate onClick event before onDblClick event while doubleclicking item in tree. |
||
1673 | ( that behavior depend on used browser ) |
||
1674 | * @eventparam: ID of item which was doubleclicked |
||
1675 | * @eventreturn: true - confirm opening/closing; false - deny opening/closing; |
||
1676 | */ |
||
1677 | dhtmlXTreeObject.prototype.setOnDblClickHandler=function(func){ this.attachEvent("onDblClick",func); }; |
||
1678 | |||
1679 | |||
1680 | |||
1681 | |||
1682 | |||
1683 | |||
1684 | |||
1685 | |||
1686 | |||
1687 | /** |
||
1688 | * @desc: expand target node and all sub nodes |
||
1689 | * @type: public |
||
1690 | * @param: itemId - node id |
||
1691 | * @topic: 4 |
||
1692 | */ |
||
1693 | dhtmlXTreeObject.prototype.openAllItems=function(itemId) |
||
1694 | { |
||
1695 | var temp=this._globalIdStorageFind(itemId); |
||
1696 | if (!temp) return 0; |
||
1697 | this._xopenAll(temp); |
||
1698 | }; |
||
1699 | |||
1700 | /** |
||
1701 | * @desc: return open/close state |
||
1702 | * @type: public |
||
1703 | * @param: itemId - node id |
||
1704 | * @return: -1 - close, 1 - opened, 0 - node doesn't have children |
||
1705 | * @topic: 4 |
||
1706 | */ |
||
1707 | dhtmlXTreeObject.prototype.getOpenState=function(itemId){ |
||
1708 | var temp=this._globalIdStorageFind(itemId); |
||
1709 | if (!temp) return ""; |
||
1710 | return this._getOpenState(temp); |
||
1711 | }; |
||
1712 | |||
1713 | /** |
||
1714 | * @desc: collapse target node and all sub nodes |
||
1715 | * @type: public |
||
1716 | * @param: itemId - node id |
||
1717 | * @topic: 4 |
||
1718 | */ |
||
1719 | dhtmlXTreeObject.prototype.closeAllItems=function(itemId) |
||
1720 | { |
||
1721 | if (itemId===window.undefined) itemId=this.rootId; |
||
1722 | |||
1723 | var temp=this._globalIdStorageFind(itemId); |
||
1724 | if (!temp) return 0; |
||
1725 | this._xcloseAll(temp); |
||
1726 | |||
1727 | //nb:solves standard doctype prb in IE |
||
1728 | this.allTree.childNodes[0].border = "1"; |
||
1729 | this.allTree.childNodes[0].border = "0"; |
||
1730 | |||
1731 | }; |
||
1732 | |||
1733 | |||
1734 | /** |
||
1735 | * @desc: set user data for target node |
||
1736 | * @type: public |
||
1737 | * @param: itemId - target node id |
||
1738 | * @param: name - key for user data |
||
1739 | * @param: value - user data value |
||
1740 | * @topic: 5 |
||
1741 | */ |
||
1742 | dhtmlXTreeObject.prototype.setUserData=function(itemId,name,value){ |
||
1743 | var sNode=this._globalIdStorageFind(itemId,0,true); |
||
1744 | if (!sNode) return; |
||
1745 | if(name=="hint") |
||
1746 | sNode.htmlNode.childNodes[0].childNodes[0].title=value; |
||
1747 | if (typeof(sNode.userData["t_"+name])=="undefined"){ |
||
1748 | if (!sNode._userdatalist) sNode._userdatalist=name; |
||
1749 | else sNode._userdatalist+=","+name; |
||
1750 | } |
||
1751 | sNode.userData["t_"+name]=value; |
||
1752 | }; |
||
1753 | |||
1754 | /** |
||
1755 | * @desc: get user data from target node |
||
1756 | * @type: public |
||
1757 | * @param: itemId - target node id |
||
1758 | * @param: name - key for user data |
||
1759 | * @return: value of user data |
||
1760 | * @topic: 5 |
||
1761 | */ |
||
1762 | dhtmlXTreeObject.prototype.getUserData=function(itemId,name){ |
||
1763 | var sNode=this._globalIdStorageFind(itemId,0,true); |
||
1764 | if (!sNode) return; |
||
1765 | return sNode.userData["t_"+name]; |
||
1766 | }; |
||
1767 | |||
1768 | |||
1769 | |||
1770 | |||
1771 | /** |
||
1772 | * @desc: get node color (text color) |
||
1773 | * @param: itemId - id of node |
||
1774 | * @type: public |
||
1775 | * @return: color of node (empty string for default color); |
||
1776 | * @topic: 6 |
||
1777 | */ |
||
1778 | dhtmlXTreeObject.prototype.getItemColor=function(itemId) |
||
1779 | { |
||
1780 | var temp=this._globalIdStorageFind(itemId); |
||
1781 | if (!temp) return 0; |
||
1782 | |||
1783 | var res= new Object(); |
||
1784 | if (temp.acolor) res.acolor=temp.acolor; |
||
1785 | if (temp.scolor) res.scolor=temp.scolor; |
||
1786 | return res; |
||
1787 | }; |
||
1788 | /** |
||
1789 | * @desc: set node text color |
||
1790 | * @param: itemId - id of node |
||
1791 | * @param: defaultColor - node color |
||
1792 | * @param: selectedColor - selected node color |
||
1793 | * @type: public |
||
1794 | * @topic: 6 |
||
1795 | */ |
||
1796 | dhtmlXTreeObject.prototype.setItemColor=function(itemId,defaultColor,selectedColor) |
||
1797 | { |
||
1798 | if ((itemId)&&(itemId.span)) |
||
1799 | var temp=itemId; |
||
1800 | else |
||
1801 | var temp=this._globalIdStorageFind(itemId); |
||
1802 | if (!temp) return 0; |
||
1803 | else { |
||
1804 | if (temp.i_sel) |
||
1805 | { if (selectedColor) temp.span.style.color=selectedColor; } |
||
1806 | else |
||
1807 | { if (defaultColor) temp.span.style.color=defaultColor; } |
||
1808 | |||
1809 | if (selectedColor) temp.scolor=selectedColor; |
||
1810 | if (defaultColor) temp.acolor=defaultColor; |
||
1811 | } |
||
1812 | }; |
||
1813 | |||
1814 | /** |
||
1815 | * @desc: return node text |
||
1816 | * @param: itemId - id of node |
||
1817 | * @type: public |
||
1818 | * @return: text of item (with HTML formatting, if any) |
||
1819 | * @topic: 6 |
||
1820 | */ |
||
1821 | dhtmlXTreeObject.prototype.getItemText=function(itemId) |
||
1822 | { |
||
1823 | var temp=this._globalIdStorageFind(itemId); |
||
1824 | if (!temp) return 0; |
||
1825 | return(temp.htmlNode.childNodes[0].childNodes[0].childNodes[3].childNodes[0].innerHTML); |
||
1826 | }; |
||
1827 | /** |
||
1828 | * @desc: return parent item id |
||
1829 | * @param: itemId - id of node |
||
1830 | * @type: public |
||
1831 | * @return: id of parent item |
||
1832 | * @topic: 4 |
||
1833 | */ |
||
1834 | dhtmlXTreeObject.prototype.getParentId=function(itemId) |
||
1835 | { |
||
1836 | var temp=this._globalIdStorageFind(itemId); |
||
1837 | if ((!temp)||(!temp.parentObject)) return ""; |
||
1838 | return temp.parentObject.id; |
||
1839 | }; |
||
1840 | |||
1841 | |||
1842 | |||
1843 | /** |
||
1844 | * @desc: change item id |
||
1845 | * @type: public |
||
1846 | * @param: itemId - old node id |
||
1847 | * @param: newItemId - new node id |
||
1848 | * @topic: 4 |
||
1849 | */ |
||
1850 | dhtmlXTreeObject.prototype.changeItemId=function(itemId,newItemId) |
||
1851 | { |
||
1852 | if (itemId==newItemId) return; |
||
1853 | var temp=this._globalIdStorageFind(itemId); |
||
1854 | if (!temp) return 0; |
||
1855 | temp.id=newItemId; |
||
1856 | temp.span.contextMenuId=newItemId; |
||
1857 | this._idpull[newItemId]=this._idpull[itemId]; |
||
1858 | delete this._idpull[itemId]; |
||
1859 | }; |
||
1860 | |||
1861 | |||
1862 | /** |
||
1863 | * @desc: mark selected item as cut |
||
1864 | * @type: public |
||
1865 | * @topic: 2 |
||
1866 | */ |
||
1867 | dhtmlXTreeObject.prototype.doCut=function(){ |
||
1868 | if (this.nodeCut) this.clearCut(); |
||
1869 | this.nodeCut=(new Array()).concat(this._selected); |
||
1870 | for (var i=0; i<this.nodeCut.length; i++){ |
||
1871 | var tempa=this.nodeCut[i]; |
||
1872 | tempa._cimgs=new Array(); |
||
1873 | tempa._cimgs[0]=tempa.images[0]; |
||
1874 | tempa._cimgs[1]=tempa.images[1]; |
||
1875 | tempa._cimgs[2]=tempa.images[2]; |
||
1876 | tempa.images[0]=tempa.images[1]=tempa.images[2]=this.cutImage; |
||
1877 | this._correctPlus(tempa); |
||
1878 | } |
||
1879 | }; |
||
1880 | |||
1881 | /** |
||
1882 | * @desc: insert previously cut branch |
||
1883 | * @param: itemId - id of new parent node |
||
1884 | * @type: public |
||
1885 | * @topic: 2 |
||
1886 | */ |
||
1887 | dhtmlXTreeObject.prototype.doPaste=function(itemId){ |
||
1888 | var tobj=this._globalIdStorageFind(itemId); |
||
1889 | if (!tobj) return 0; |
||
1890 | for (var i=0; i<this.nodeCut.length; i++){ |
||
1891 | if (this._checkPNodes(tobj,this.nodeCut[i])) continue; |
||
1892 | this._moveNode(this.nodeCut[i],tobj); |
||
1893 | } |
||
1894 | this.clearCut(); |
||
1895 | }; |
||
1896 | |||
1897 | /** |
||
1898 | * @desc: clear cut |
||
1899 | * @type: public |
||
1900 | * @topic: 2 |
||
1901 | */ |
||
1902 | dhtmlXTreeObject.prototype.clearCut=function(){ |
||
1903 | for (var i=0; i<this.nodeCut.length; i++) |
||
1904 | { |
||
1905 | var tempa=this.nodeCut[i]; |
||
1906 | tempa.images[0]=tempa._cimgs[0]; |
||
1907 | tempa.images[1]=tempa._cimgs[1]; |
||
1908 | tempa.images[2]=tempa._cimgs[2]; |
||
1909 | this._correctPlus(tempa); |
||
1910 | } |
||
1911 | this.nodeCut=new Array(); |
||
1912 | }; |
||
1913 | |||
1914 | |||
1915 | |||
1916 | /** |
||
1917 | * @desc: move node with subnodes |
||
1918 | * @type: private |
||
1919 | * @param: itemObject - moved node object |
||
1920 | * @param: targetObject - new parent node |
||
1921 | * @topic: 2 |
||
1922 | */ |
||
1923 | dhtmlXTreeObject.prototype._moveNode=function(itemObject,targetObject){ |
||
1924 | |||
1925 | return this._moveNodeTo(itemObject,targetObject); |
||
1926 | |||
1927 | } |
||
1928 | |||
1929 | /** |
||
1930 | * @desc: fix order of nodes in collection |
||
1931 | * @type: private |
||
1932 | * @param: target - parent item node |
||
1933 | * @param: zParent - before node |
||
1934 | * @edition: Professional |
||
1935 | * @topic: 2 |
||
1936 | */ |
||
1937 | |||
1938 | dhtmlXTreeObject.prototype._fixNodesCollection=function(target,zParent){ |
||
1939 | var flag=0; var icount=0; |
||
1940 | var Nodes=target.childNodes; |
||
1941 | var Count=target.childsCount-1; |
||
1942 | |||
1943 | if (zParent==Nodes[Count]) return; |
||
1944 | for (var i=0; i<Count; i++) |
||
1945 | if (Nodes[i]==Nodes[Count]) { Nodes[i]=Nodes[i+1]; Nodes[i+1]=Nodes[Count]; } |
||
1946 | |||
1947 | // Count=target.childsCount; |
||
1948 | for (var i=0; i<Count+1; i++) |
||
1949 | { |
||
1950 | if (flag) { |
||
1951 | var temp=Nodes[i]; |
||
1952 | Nodes[i]=flag; |
||
1953 | flag=temp; |
||
1954 | } |
||
1955 | else |
||
1956 | if (Nodes[i]==zParent) { flag=Nodes[i]; Nodes[i]=Nodes[Count]; } |
||
1957 | } |
||
1958 | }; |
||
1959 | |||
1960 | /** |
||
1961 | * @desc: recreate branch |
||
1962 | * @type: private |
||
1963 | * @param: itemObject - moved node object |
||
1964 | * @param: targetObject - new parent node |
||
1965 | * @param: level - top level flag |
||
1966 | * @param: beforeNode - node for sibling mode |
||
1967 | * @mode: mode - DragAndDrop mode (0 - as child, 1 as sibling) |
||
1968 | * @edition: Professional |
||
1969 | * @topic: 2 |
||
1970 | */ |
||
1971 | dhtmlXTreeObject.prototype._recreateBranch=function(itemObject,targetObject,beforeNode,level){ |
||
1972 | var i; var st=""; |
||
1973 | if (beforeNode){ |
||
1974 | for (i=0; i<targetObject.childsCount; i++) |
||
1975 | if (targetObject.childNodes[i]==beforeNode) break; |
||
1976 | |||
1977 | if (i!=0) |
||
1978 | beforeNode=targetObject.childNodes[i-1]; |
||
1979 | else{ |
||
1980 | st="TOP"; |
||
1981 | beforeNode=""; |
||
1982 | } |
||
1983 | } |
||
1984 | |||
1985 | var t2=this._onradh; this._onradh=null; |
||
1986 | var newNode=this._attachChildNode(targetObject,itemObject.id,itemObject.label,0,itemObject.images[0],itemObject.images[1],itemObject.images[2],st,0,beforeNode); |
||
1987 | |||
1988 | //copy user data |
||
1989 | newNode._userdatalist=itemObject._userdatalist; |
||
1990 | newNode.userData=itemObject.userData.clone(); |
||
1991 | if(itemObject._attrs){ |
||
1992 | newNode._attrs={}; |
||
1993 | for(var attr in itemObject._attrs) |
||
1994 | newNode._attrs[attr] = itemObject._attrs[attr]; |
||
1995 | } |
||
1996 | |||
1997 | newNode.XMLload=itemObject.XMLload; |
||
1998 | if (t2){ |
||
1999 | this._onradh=t2; this._onradh(newNode.id); } |
||
2000 | |||
2001 | |||
2002 | for (var i=0; i<itemObject.childsCount; i++) |
||
2003 | this._recreateBranch(itemObject.childNodes[i],newNode,0,1); |
||
2004 | |||
2005 | |||
2006 | return newNode; |
||
2007 | } |
||
2008 | |||
2009 | /** |
||
2010 | * @desc: move single node |
||
2011 | * @type: private |
||
2012 | * @param: itemObject - moved node object |
||
2013 | * @param: targetObject - new parent node |
||
2014 | * @mode: mode - DragAndDrop mode (0 - as child, 1 as sibling) |
||
2015 | * @topic: 2 |
||
2016 | */ |
||
2017 | dhtmlXTreeObject.prototype._moveNodeTo=function(itemObject,targetObject,beforeNode){ |
||
2018 | //return; |
||
2019 | if (itemObject.treeNod._nonTrivialNode) |
||
2020 | return itemObject.treeNod._nonTrivialNode(this,targetObject,beforeNode,itemObject); |
||
2021 | |||
2022 | if (this._checkPNodes(targetObject,itemObject)) |
||
2023 | return false; |
||
2024 | |||
2025 | if (targetObject.mytype) |
||
2026 | var framesMove=(itemObject.treeNod.lWin!=targetObject.lWin); |
||
2027 | else |
||
2028 | var framesMove=(itemObject.treeNod.lWin!=targetObject.treeNod.lWin); |
||
2029 | |||
2030 | if (!this.callEvent("onDrag",[itemObject.id,targetObject.id,(beforeNode?beforeNode.id:null),itemObject.treeNod,targetObject.treeNod])) return false; |
||
2031 | if ((targetObject.XMLload==0)&&(this.XMLsource)) |
||
2032 | { |
||
2033 | targetObject.XMLload=1; |
||
2034 | this._loadDynXML(targetObject.id); |
||
2035 | } |
||
2036 | this.openItem(targetObject.id); |
||
2037 | |||
2038 | var oldTree=itemObject.treeNod; |
||
2039 | var c=itemObject.parentObject.childsCount; |
||
2040 | var z=itemObject.parentObject; |
||
2041 | |||
2042 | |||
2043 | if ((framesMove)||(oldTree.dpcpy)) {//interframe drag flag |
||
2044 | var _otiid=itemObject.id; |
||
2045 | itemObject=this._recreateBranch(itemObject,targetObject,beforeNode); |
||
2046 | if (!oldTree.dpcpy) oldTree.deleteItem(_otiid); |
||
2047 | } |
||
2048 | else |
||
2049 | { |
||
2050 | |||
2051 | var Count=targetObject.childsCount; var Nodes=targetObject.childNodes; |
||
2052 | if (Count==0) targetObject._open=true; |
||
2053 | oldTree._unselectItem(itemObject); |
||
2054 | Nodes[Count]=itemObject; |
||
2055 | itemObject.treeNod=targetObject.treeNod; |
||
2056 | targetObject.childsCount++; |
||
2057 | |||
2058 | var tr=this._drawNewTr(Nodes[Count].htmlNode); |
||
2059 | |||
2060 | if (!beforeNode) |
||
2061 | { |
||
2062 | targetObject.htmlNode.childNodes[0].appendChild(tr); |
||
2063 | if (this.dadmode==1) this._fixNodesCollection(targetObject,beforeNode); |
||
2064 | } |
||
2065 | else |
||
2066 | { |
||
2067 | targetObject.htmlNode.childNodes[0].insertBefore(tr,beforeNode.tr); |
||
2068 | this._fixNodesCollection(targetObject,beforeNode); |
||
2069 | Nodes=targetObject.childNodes; |
||
2070 | } |
||
2071 | |||
2072 | |||
2073 | } |
||
2074 | |||
2075 | if ((!oldTree.dpcpy)&&(!framesMove)) { |
||
2076 | var zir=itemObject.tr; |
||
2077 | |||
2078 | if ((document.all)&&(navigator.appVersion.search(/MSIE\ 5\.0/gi)!=-1)) |
||
2079 | { |
||
2080 | window.setTimeout(function() { zir.parentNode.removeChild(zir); } , 250 ); |
||
2081 | } |
||
2082 | else //if (zir.parentNode) zir.parentNode.removeChild(zir,true); |
||
2083 | |||
2084 | itemObject.parentObject.htmlNode.childNodes[0].removeChild(itemObject.tr); |
||
2085 | |||
2086 | //itemObject.tr.removeNode(true); |
||
2087 | if ((!beforeNode)||(targetObject!=itemObject.parentObject)){ |
||
2088 | for (var i=0; i<z.childsCount; i++){ |
||
2089 | if (z.childNodes[i].id==itemObject.id) { |
||
2090 | z.childNodes[i]=0; |
||
2091 | break; }}} |
||
2092 | else z.childNodes[z.childsCount-1]=0; |
||
2093 | |||
2094 | oldTree._compressChildList(z.childsCount,z.childNodes); |
||
2095 | z.childsCount--; |
||
2096 | } |
||
2097 | |||
2098 | |||
2099 | if ((!framesMove)&&(!oldTree.dpcpy)) { |
||
2100 | itemObject.tr=tr; |
||
2101 | tr.nodem=itemObject; |
||
2102 | itemObject.parentObject=targetObject; |
||
2103 | |||
2104 | if (oldTree!=targetObject.treeNod) { |
||
2105 | if(itemObject.treeNod._registerBranch(itemObject,oldTree)) return; this._clearStyles(itemObject); this._redrawFrom(this,itemObject.parentObject); |
||
2106 | if(this._onradh) this._onradh(itemObject.id); |
||
2107 | }; |
||
2108 | |||
2109 | this._correctPlus(targetObject); |
||
2110 | this._correctLine(targetObject); |
||
2111 | |||
2112 | this._correctLine(itemObject); |
||
2113 | this._correctPlus(itemObject); |
||
2114 | |||
2115 | //fix target siblings |
||
2116 | if (beforeNode) |
||
2117 | { |
||
2118 | |||
2119 | this._correctPlus(beforeNode); |
||
2120 | //this._correctLine(beforeNode); |
||
2121 | } |
||
2122 | else |
||
2123 | if (targetObject.childsCount>=2) |
||
2124 | { |
||
2125 | |||
2126 | this._correctPlus(Nodes[targetObject.childsCount-2]); |
||
2127 | this._correctLine(Nodes[targetObject.childsCount-2]); |
||
2128 | } |
||
2129 | |||
2130 | this._correctPlus(Nodes[targetObject.childsCount-1]); |
||
2131 | //this._correctLine(Nodes[targetObject.childsCount-1]); |
||
2132 | |||
2133 | |||
2134 | if (this.tscheck) this._correctCheckStates(targetObject); |
||
2135 | if (oldTree.tscheck) oldTree._correctCheckStates(z); |
||
2136 | |||
2137 | } |
||
2138 | |||
2139 | //fix source parent |
||
2140 | |||
2141 | if (c>1) { oldTree._correctPlus(z.childNodes[c-2]); |
||
2142 | oldTree._correctLine(z.childNodes[c-2]); |
||
2143 | } |
||
2144 | |||
2145 | |||
2146 | // if (z.childsCount==0) |
||
2147 | oldTree._correctPlus(z); |
||
2148 | oldTree._correctLine(z); |
||
2149 | |||
2150 | |||
2151 | this.callEvent("onDrop",[itemObject.id,targetObject.id,(beforeNode?beforeNode.id:null),oldTree,targetObject.treeNod]); |
||
2152 | return itemObject.id; |
||
2153 | }; |
||
2154 | |||
2155 | |||
2156 | |||
2157 | /** |
||
2158 | * @desc: recursive set default styles for node |
||
2159 | * @type: private |
||
2160 | * @param: itemObject - target node object |
||
2161 | * @topic: 6 |
||
2162 | */ |
||
2163 | dhtmlXTreeObject.prototype._clearStyles=function(itemObject){ |
||
2164 | if (!itemObject.htmlNode) return; //some weird case in SRND mode |
||
2165 | var td1=itemObject.htmlNode.childNodes[0].childNodes[0].childNodes[1]; |
||
2166 | var td3=td1.nextSibling.nextSibling; |
||
2167 | |||
2168 | itemObject.span.innerHTML=itemObject.label; |
||
2169 | itemObject.i_sel=false; |
||
2170 | |||
2171 | if (itemObject._aimgs) |
||
2172 | this.dragger.removeDraggableItem(td1.nextSibling); |
||
2173 | |||
2174 | if (this.checkBoxOff) { |
||
2175 | td1.childNodes[0].style.display=""; |
||
2176 | td1.childNodes[0].onclick=this.onCheckBoxClick; |
||
2177 | this._setSrc(td1.childNodes[0],this.imPath+this.checkArray[itemObject.checkstate]); |
||
2178 | } |
||
2179 | else td1.childNodes[0].style.display="none"; |
||
2180 | td1.childNodes[0].treeNod=this; |
||
2181 | |||
2182 | this.dragger.removeDraggableItem(td3); |
||
2183 | if (this.dragAndDropOff) this.dragger.addDraggableItem(td3,this); |
||
2184 | if (this._aimgs) this.dragger.addDraggableItem(td1.nextSibling,this); |
||
2185 | |||
2186 | td3.childNodes[0].className="standartTreeRow"; |
||
2187 | td3.onclick=this.onRowSelect; td3.ondblclick=this.onRowClick2; |
||
2188 | td1.previousSibling.onclick=this.onRowClick; |
||
2189 | |||
2190 | this._correctLine(itemObject); |
||
2191 | this._correctPlus(itemObject); |
||
2192 | for (var i=0; i<itemObject.childsCount; i++) this._clearStyles(itemObject.childNodes[i]); |
||
2193 | |||
2194 | }; |
||
2195 | /** |
||
2196 | * @desc: register node and all children nodes |
||
2197 | * @type: private |
||
2198 | * @param: itemObject - node object |
||
2199 | * @topic: 2 |
||
2200 | */ |
||
2201 | dhtmlXTreeObject.prototype._registerBranch=function(itemObject,oldTree){ |
||
2202 | if (oldTree) oldTree._globalIdStorageSub(itemObject.id); |
||
2203 | itemObject.id=this._globalIdStorageAdd(itemObject.id,itemObject); |
||
2204 | itemObject.treeNod=this; |
||
2205 | for (var i=0; i<itemObject.childsCount; i++) |
||
2206 | this._registerBranch(itemObject.childNodes[i],oldTree); |
||
2207 | return 0; |
||
2208 | }; |
||
2209 | |||
2210 | |||
2211 | /** |
||
2212 | * @desc: enable three state checkboxes |
||
2213 | * @beforeInit: 1 |
||
2214 | * @param: mode - 1 - on, 0 - off; |
||
2215 | * @type: public |
||
2216 | * @topic: 0 |
||
2217 | */ |
||
2218 | dhtmlXTreeObject.prototype.enableThreeStateCheckboxes=function(mode) { this.tscheck=convertStringToBoolean(mode); }; |
||
2219 | |||
2220 | |||
2221 | /** |
||
2222 | * @desc: set function called when mouse is over tree node |
||
2223 | * @param: func - event handling function |
||
2224 | * @type: deprecated |
||
2225 | * @topic: 0,7 |
||
2226 | * @event: onMouseIn |
||
2227 | * @depricated: use grid.attachEvent("onMouseIn",func); instead |
||
2228 | * @eventdesc: Event raised immideatly after mouse started moving over item |
||
2229 | * @eventparam: ID of item |
||
2230 | */ |
||
2231 | dhtmlXTreeObject.prototype.setOnMouseInHandler=function(func){ |
||
2232 | this.ehlt=true; |
||
2233 | this.attachEvent("onMouseIn",func); |
||
2234 | }; |
||
2235 | |||
2236 | /** |
||
2237 | * @desc: set function called when mouse is out of tree node |
||
2238 | * @param: func - event handling function |
||
2239 | * @type: deprecated |
||
2240 | * @topic: 0,7 |
||
2241 | * @event: onMouseOut |
||
2242 | * @depricated: use grid.attachEvent("onMouseOut",func); instead |
||
2243 | * @eventdesc: Event raised immideatly after mouse moved out of item |
||
2244 | * @eventparam: ID of clicked item |
||
2245 | */ |
||
2246 | dhtmlXTreeObject.prototype.setOnMouseOutHandler=function(func){ |
||
2247 | this.ehlt=true; |
||
2248 | this.attachEvent("onMouseOut",func); |
||
2249 | }; |
||
2250 | |||
2251 | |||
2252 | |||
2253 | |||
2254 | |||
2255 | |||
2256 | |||
2257 | |||
2258 | |||
2259 | /** |
||
2260 | * @desc: enable tree images |
||
2261 | * @beforeInit: 1 |
||
2262 | * @param: mode - 1 - on, 0 - off; |
||
2263 | * @type: public |
||
2264 | * @topic: 0 |
||
2265 | */ |
||
2266 | dhtmlXTreeObject.prototype.enableTreeImages=function(mode) { this.timgen=convertStringToBoolean(mode); }; |
||
2267 | |||
2268 | |||
2269 | |||
2270 | /** |
||
2271 | * @desc: enable mode with fixed tables (looks better, but has no horisontal scrollbar) |
||
2272 | * @beforeInit: 1 |
||
2273 | * @param: mode - 1 - on, 0 - off; |
||
2274 | * @type: private |
||
2275 | * @topic: 0 |
||
2276 | */ |
||
2277 | dhtmlXTreeObject.prototype.enableFixedMode=function(mode) { this.hfMode=convertStringToBoolean(mode); }; |
||
2278 | |||
2279 | /** |
||
2280 | * @desc: show/hide checkboxes (all checkboxes in tree) |
||
2281 | * @type: public |
||
2282 | * @param: mode - true/false |
||
2283 | * @param: hidden - if set to true, checkboxes not rendered but can be shown by showItemCheckbox |
||
2284 | * @topic: 0 |
||
2285 | */ |
||
2286 | dhtmlXTreeObject.prototype.enableCheckBoxes=function(mode, hidden){ this.checkBoxOff=convertStringToBoolean(mode); this.cBROf=(!(this.checkBoxOff||convertStringToBoolean(hidden))); |
||
2287 | }; |
||
2288 | |||
2289 | /** |
||
2290 | * @desc: enable/disable multiple selection |
||
2291 | * @param: mode - true/false |
||
2292 | * @param: strict - true/false |
||
2293 | */ |
||
2294 | dhtmlXTreeObject.prototype.enableMultiselection = function(mode, strict) { |
||
2295 | this._amsel = convertStringToBoolean(mode); |
||
2296 | this._amselS = convertStringToBoolean(strict); |
||
2297 | }; |
||
2298 | /** |
||
2299 | * @desc: set default images for nodes (must be called before XML loading) |
||
2300 | * @type: public |
||
2301 | * @param: a0 - image for node without children; |
||
2302 | * @param: a1 - image for closed node; |
||
2303 | * @param: a2 - image for opened node |
||
2304 | * @topic: 6 |
||
2305 | */ |
||
2306 | dhtmlXTreeObject.prototype.setStdImages=function(image1,image2,image3){ |
||
2307 | this.imageArray[0]=image1; this.imageArray[1]=image2; this.imageArray[2]=image3;}; |
||
2308 | |||
2309 | /** |
||
2310 | * @desc: enable/disable tree lines (parent-child threads) |
||
2311 | * @type: public |
||
2312 | * @param: mode - enable/disable tree lines |
||
2313 | * @topic: 6 |
||
2314 | */ |
||
2315 | dhtmlXTreeObject.prototype.enableTreeLines=function(mode){ |
||
2316 | this.treeLinesOn=convertStringToBoolean(mode); |
||
2317 | } |
||
2318 | |||
2319 | /** |
||
2320 | * @desc: set images used for parent-child threads drawing (lines, plus, minus) |
||
2321 | * @type: public |
||
2322 | * @param: arrayName - name of array: plus, minus |
||
2323 | * @param: image1 - line crossed image |
||
2324 | * @param: image2 - image with top line |
||
2325 | * @param: image3 - image with bottom line |
||
2326 | * @param: image4 - image without line |
||
2327 | * @param: image5 - single root image |
||
2328 | * @topic: 6 |
||
2329 | */ |
||
2330 | View Code Duplication | dhtmlXTreeObject.prototype.setImageArrays=function(arrayName,image1,image2,image3,image4,image5){ |
|
2331 | switch(arrayName){ |
||
2332 | case "plus": this.plusArray[0]=image1; this.plusArray[1]=image2; this.plusArray[2]=image3; this.plusArray[3]=image4; this.plusArray[4]=image5; break; |
||
2333 | case "minus": this.minusArray[0]=image1; this.minusArray[1]=image2; this.minusArray[2]=image3; this.minusArray[3]=image4; this.minusArray[4]=image5; break; |
||
2334 | } |
||
2335 | }; |
||
2336 | |||
2337 | /** |
||
2338 | * @desc: expand node |
||
2339 | * @param: itemId - id of node |
||
2340 | * @type: public |
||
2341 | * @topic: 4 |
||
2342 | */ |
||
2343 | dhtmlXTreeObject.prototype.openItem=function(itemId){ |
||
2344 | this.skipLock = true; |
||
2345 | var temp=this._globalIdStorageFind(itemId); |
||
2346 | if (!temp) return 0; |
||
2347 | else return this._openItem(temp); |
||
2348 | this.skipLock = false; |
||
2349 | }; |
||
2350 | |||
2351 | /** |
||
2352 | * @desc: expand node |
||
2353 | * @param: item - tree node object |
||
2354 | * @type: private |
||
2355 | * @editing: pro |
||
2356 | * @topic: 4 |
||
2357 | */ |
||
2358 | View Code Duplication | dhtmlXTreeObject.prototype._openItem=function(item){ |
|
2359 | var state=this._getOpenState(item); |
||
2360 | if ((state<0)||(((this.XMLsource)&&(!item.XMLload)))){ |
||
2361 | if (!this.callEvent("onOpenStart",[item.id,state])) return 0; |
||
2362 | this._HideShow(item,2); |
||
2363 | if (this.checkEvent("onOpenEnd")){ |
||
2364 | if (this.onXLE==this._epnFHe) this._epnFHe(this,item.id,true); |
||
2365 | if (!this.xmlstate || !this.XMLsource) |
||
2366 | this.callEvent("onOpenEnd",[item.id,this._getOpenState(item)]); |
||
2367 | else{ |
||
2368 | this._oie_onXLE.push(this.onXLE); |
||
2369 | this.onXLE=this._epnFHe; |
||
2370 | } |
||
2371 | } |
||
2372 | } else if (this._srnd) this._HideShow(item,2); |
||
2373 | if (item.parentObject && !this._skip_open_parent) this._openItem(item.parentObject); |
||
2374 | }; |
||
2375 | |||
2376 | /** |
||
2377 | * @desc: collapse node |
||
2378 | * @param: itemId - id of node |
||
2379 | * @type: public |
||
2380 | * @topic: 4 |
||
2381 | */ |
||
2382 | dhtmlXTreeObject.prototype.closeItem=function(itemId){ |
||
2383 | if (this.rootId==itemId) return 0; |
||
2384 | this.skipLock = true; |
||
2385 | var temp=this._globalIdStorageFind(itemId); |
||
2386 | if (!temp) return 0; |
||
2387 | if (temp.closeble) |
||
2388 | this._HideShow(temp,1); |
||
2389 | this.skipLock = false; |
||
2390 | }; |
||
2391 | |||
2392 | |||
2393 | |||
2394 | |||
2395 | |||
2396 | |||
2397 | |||
2398 | |||
2399 | |||
2400 | |||
2401 | |||
2402 | |||
2403 | |||
2404 | |||
2405 | |||
2406 | |||
2407 | |||
2408 | |||
2409 | |||
2410 | |||
2411 | |||
2412 | |||
2413 | |||
2414 | |||
2415 | |||
2416 | |||
2417 | /** |
||
2418 | * @desc: get node level (position in hierarchy) |
||
2419 | * @param: itemId - id of node |
||
2420 | * @type: public |
||
2421 | * @return: node level (0 if no such item in hierarchy - probably super root) |
||
2422 | * @topic: 4 |
||
2423 | */ |
||
2424 | dhtmlXTreeObject.prototype.getLevel=function(itemId){ |
||
2425 | var temp=this._globalIdStorageFind(itemId); |
||
2426 | if (!temp) return 0; |
||
2427 | return this._getNodeLevel(temp,0); |
||
2428 | }; |
||
2429 | |||
2430 | |||
2431 | |||
2432 | /** |
||
2433 | * @desc: prevent node from closing |
||
2434 | * @param: itemId - id of node |
||
2435 | * @param: flag - if 0 - node can't be closed, else node can be closed |
||
2436 | * @type: public |
||
2437 | * @topic: 4 |
||
2438 | */ |
||
2439 | dhtmlXTreeObject.prototype.setItemCloseable=function(itemId,flag) |
||
2440 | { |
||
2441 | flag=convertStringToBoolean(flag); |
||
2442 | if ((itemId)&&(itemId.span)) |
||
2443 | var temp=itemId; |
||
2444 | else |
||
2445 | var temp=this._globalIdStorageFind(itemId); |
||
2446 | if (!temp) return 0; |
||
2447 | temp.closeble=flag; |
||
2448 | }; |
||
2449 | |||
2450 | /** |
||
2451 | * @desc: recursive function used for node level calculation |
||
2452 | * @param: itemObject - pointer to node object |
||
2453 | * @param: count - counter of levels |
||
2454 | * @type: private |
||
2455 | * @topic: 4 |
||
2456 | */ |
||
2457 | dhtmlXTreeObject.prototype._getNodeLevel=function(itemObject,count){ |
||
2458 | if (itemObject.parentObject) return this._getNodeLevel(itemObject.parentObject,count+1); |
||
2459 | return(count); |
||
2460 | }; |
||
2461 | |||
2462 | /** |
||
2463 | * @desc: return number of children |
||
2464 | * @param: itemId - id of node |
||
2465 | * @type: public |
||
2466 | * @return: number of child items for loaded branches; true - for not loaded branches |
||
2467 | * @topic: 4 |
||
2468 | */ |
||
2469 | dhtmlXTreeObject.prototype.hasChildren=function(itemId){ |
||
2470 | var temp=this._globalIdStorageFind(itemId); |
||
2471 | if (!temp) return 0; |
||
2472 | else |
||
2473 | { |
||
2474 | if ( (this.XMLsource)&&(!temp.XMLload) ) return true; |
||
2475 | else |
||
2476 | return temp.childsCount; |
||
2477 | }; |
||
2478 | }; |
||
2479 | |||
2480 | |||
2481 | /** |
||
2482 | * @desc: get number of leafs (nodes without children) |
||
2483 | * @param: itemNode - node object |
||
2484 | * @type: private |
||
2485 | * @edition: Professional |
||
2486 | * @topic: 4 |
||
2487 | */ |
||
2488 | dhtmlXTreeObject.prototype._getLeafCount=function(itemNode){ |
||
2489 | var a=0; |
||
2490 | for (var b=0; b<itemNode.childsCount; b++) |
||
2491 | if (itemNode.childNodes[b].childsCount==0) a++; |
||
2492 | return a; |
||
2493 | } |
||
2494 | |||
2495 | |||
2496 | /** |
||
2497 | * @desc: set new node text (HTML allowed) |
||
2498 | * @param: itemId - id of node |
||
2499 | * @param: newLabel - node text |
||
2500 | * @param: newTooltip - (optional)tooltip for the node |
||
2501 | * @type: public |
||
2502 | * @topic: 6 |
||
2503 | */ |
||
2504 | dhtmlXTreeObject.prototype.setItemText=function(itemId,newLabel,newTooltip) |
||
2505 | { |
||
2506 | var temp=this._globalIdStorageFind(itemId); |
||
2507 | if (!temp) return 0; |
||
2508 | temp.label=newLabel; |
||
2509 | temp.span.innerHTML=newLabel; |
||
2510 | |||
2511 | temp.span.parentNode.parentNode.title=newTooltip||""; |
||
2512 | }; |
||
2513 | |||
2514 | /** |
||
2515 | * @desc: get item's tooltip |
||
2516 | * @param: itemId - id of node |
||
2517 | * @type: public |
||
2518 | * @topic: 6 |
||
2519 | */ |
||
2520 | dhtmlXTreeObject.prototype.getItemTooltip=function(itemId){ |
||
2521 | var temp=this._globalIdStorageFind(itemId); |
||
2522 | if (!temp) return ""; |
||
2523 | return (temp.span.parentNode.parentNode._dhx_title||temp.span.parentNode.parentNode.title||""); |
||
2524 | }; |
||
2525 | |||
2526 | /** |
||
2527 | * @desc: refresh tree branch from xml (XML with child nodes rerequested from server) |
||
2528 | * @param: itemId - id of node, if not defined tree super root used. |
||
2529 | * @type: public |
||
2530 | * @topic: 6 |
||
2531 | */ |
||
2532 | dhtmlXTreeObject.prototype.refreshItem=function(itemId){ |
||
2533 | if (!itemId) itemId=this.rootId; |
||
2534 | var temp=this._globalIdStorageFind(itemId); |
||
2535 | this.deleteChildItems(itemId); |
||
2536 | this._loadDynXML(itemId); |
||
2537 | }; |
||
2538 | |||
2539 | /** |
||
2540 | * @desc: set item images |
||
2541 | * @param: itemId - id of node |
||
2542 | * @param: image1 - node without children icon |
||
2543 | * @param: image2 - closed node icon |
||
2544 | * @param: image3 - open node icon |
||
2545 | * @type: public |
||
2546 | * @topic: 6 |
||
2547 | */ |
||
2548 | dhtmlXTreeObject.prototype.setItemImage2=function(itemId, image1,image2,image3){ |
||
2549 | var temp=this._globalIdStorageFind(itemId); |
||
2550 | if (!temp) return 0; |
||
2551 | temp.images[1]=image2; |
||
2552 | temp.images[2]=image3; |
||
2553 | temp.images[0]=image1; |
||
2554 | this._correctPlus(temp); |
||
2555 | }; |
||
2556 | /** |
||
2557 | * @desc: set item icons (mostly usefull for childless nodes) |
||
2558 | * @param: itemId - id of node |
||
2559 | * @param: image1 - node without children icon or closed node icon (if image2 specified) |
||
2560 | * @param: image2 - open node icon (optional) |
||
2561 | * @type: public |
||
2562 | * @topic: 6 |
||
2563 | */ |
||
2564 | dhtmlXTreeObject.prototype.setItemImage=function(itemId,image1,image2) |
||
2565 | { |
||
2566 | var temp=this._globalIdStorageFind(itemId); |
||
2567 | if (!temp) return 0; |
||
2568 | if (image2) |
||
2569 | { |
||
2570 | temp.images[1]=image1; |
||
2571 | temp.images[2]=image2; |
||
2572 | } |
||
2573 | else temp.images[0]=image1; |
||
2574 | this._correctPlus(temp); |
||
2575 | }; |
||
2576 | |||
2577 | |||
2578 | /** |
||
2579 | * @desc: Returns the list of all subitems Ids from the next level of tree, separated by commas. |
||
2580 | * @param: itemId - id of node |
||
2581 | * @type: public |
||
2582 | * @return: list of all subitems from the next level of tree, separated by commas. |
||
2583 | * @topic: 6 |
||
2584 | */ |
||
2585 | dhtmlXTreeObject.prototype.getSubItems =function(itemId) |
||
2586 | { |
||
2587 | var temp=this._globalIdStorageFind(itemId,0,1); |
||
2588 | if (!temp) return 0; |
||
2589 | |||
2590 | var z=""; |
||
2591 | for (i=0; i<temp.childsCount; i++){ |
||
2592 | if (!z) z= ""+temp.childNodes[i].id; |
||
2593 | else z+=this.dlmtr+temp.childNodes[i].id; |
||
2594 | |||
2595 | } |
||
2596 | |||
2597 | return z; |
||
2598 | }; |
||
2599 | |||
2600 | |||
2601 | |||
2602 | |||
2603 | /** |
||
2604 | * @desc: Returns the list of all sub items from all next levels of tree, separated by commas. |
||
2605 | * @param: itemId - id of node |
||
2606 | * @edition: Professional |
||
2607 | * @type: private |
||
2608 | * @topic: 6 |
||
2609 | */ |
||
2610 | View Code Duplication | dhtmlXTreeObject.prototype._getAllScraggyItems =function(node) |
|
2611 | { |
||
2612 | var z=""; |
||
2613 | for (var i=0; i<node.childsCount; i++) |
||
2614 | { |
||
2615 | if ((node.childNodes[i].unParsed)||(node.childNodes[i].childsCount>0)) |
||
2616 | { |
||
2617 | if (node.childNodes[i].unParsed) |
||
2618 | var zb=this._getAllScraggyItemsXML(node.childNodes[i].unParsed,1); |
||
2619 | else |
||
2620 | var zb=this._getAllScraggyItems(node.childNodes[i]) |
||
2621 | |||
2622 | if (zb) |
||
2623 | if (z) z+=this.dlmtr+zb; |
||
2624 | else z=zb; |
||
2625 | } |
||
2626 | else |
||
2627 | if (!z) z=""+node.childNodes[i].id; |
||
2628 | else z+=this.dlmtr+node.childNodes[i].id; |
||
2629 | } |
||
2630 | return z; |
||
2631 | }; |
||
2632 | |||
2633 | |||
2634 | |||
2635 | |||
2636 | |||
2637 | /** |
||
2638 | * @desc: Returns the list of all children items from all next levels of tree, separated by commas. |
||
2639 | * @param: itemId - id of node |
||
2640 | * @type: private |
||
2641 | * @edition: Professional |
||
2642 | * @topic: 6 |
||
2643 | */ |
||
2644 | |||
2645 | View Code Duplication | dhtmlXTreeObject.prototype._getAllFatItems =function(node) |
|
2646 | { |
||
2647 | var z=""; |
||
2648 | for (var i=0; i<node.childsCount; i++) |
||
2649 | { |
||
2650 | if ((node.childNodes[i].unParsed)||(node.childNodes[i].childsCount>0)) |
||
2651 | { |
||
2652 | if (!z) z=""+node.childNodes[i].id; |
||
2653 | else z+=this.dlmtr+node.childNodes[i].id; |
||
2654 | |||
2655 | if (node.childNodes[i].unParsed) |
||
2656 | var zb=this._getAllFatItemsXML(node.childNodes[i].unParsed,1); |
||
2657 | else |
||
2658 | var zb=this._getAllFatItems(node.childNodes[i]) |
||
2659 | |||
2660 | if (zb) z+=this.dlmtr+zb; |
||
2661 | } |
||
2662 | } |
||
2663 | return z; |
||
2664 | }; |
||
2665 | |||
2666 | |||
2667 | /** |
||
2668 | * @desc: Returns the list of all children items from all next levels of tree, separated by commas. |
||
2669 | * @param: itemId - id of node |
||
2670 | * @type: private |
||
2671 | * @topic: 6 |
||
2672 | */ |
||
2673 | dhtmlXTreeObject.prototype._getAllSubItems =function(itemId,z,node) |
||
2674 | { |
||
2675 | if (node) temp=node; |
||
2676 | else { |
||
2677 | var temp=this._globalIdStorageFind(itemId); |
||
2678 | }; |
||
2679 | if (!temp) return 0; |
||
2680 | |||
2681 | z=""; |
||
2682 | for (var i=0; i<temp.childsCount; i++) |
||
2683 | { |
||
2684 | if (!z) z=""+temp.childNodes[i].id; |
||
2685 | else z+=this.dlmtr+temp.childNodes[i].id; |
||
2686 | var zb=this._getAllSubItems(0,z,temp.childNodes[i]) |
||
2687 | |||
2688 | if (zb) z+=this.dlmtr+zb; |
||
2689 | } |
||
2690 | |||
2691 | |||
2692 | return z; |
||
2693 | }; |
||
2694 | |||
2695 | |||
2696 | |||
2697 | |||
2698 | |||
2699 | /** |
||
2700 | * @desc: select node ( and optionaly fire onselect event) |
||
2701 | * @type: public |
||
2702 | * @param: itemId - node id |
||
2703 | * @param: mode - If true, script function for selected node will be called. |
||
2704 | * @param: preserve - preserve earlier selected nodes |
||
2705 | * @topic: 1 |
||
2706 | */ |
||
2707 | dhtmlXTreeObject.prototype.selectItem=function(itemId,mode,preserve){ |
||
2708 | mode=convertStringToBoolean(mode); |
||
2709 | var temp=this._globalIdStorageFind(itemId); |
||
2710 | if ((!temp)||(!temp.parentObject)) return 0; |
||
2711 | |||
2712 | if (this.XMLloadingWarning) |
||
2713 | temp.parentObject.openMe=1; |
||
2714 | else |
||
2715 | this._openItem(temp.parentObject); |
||
2716 | |||
2717 | //temp.onRowSelect(0,temp.htmlNode.childNodes[0].childNodes[0].childNodes[3],mode); |
||
2718 | var ze=null; |
||
2719 | if (preserve) { |
||
2720 | ze=new Object; ze.ctrlKey=true; |
||
2721 | if (temp.i_sel) ze.skipUnSel=true; |
||
2722 | } |
||
2723 | if (mode) |
||
2724 | this.onRowSelect(ze,temp.htmlNode.childNodes[0].childNodes[0].childNodes[3],false); |
||
2725 | else |
||
2726 | this.onRowSelect(ze,temp.htmlNode.childNodes[0].childNodes[0].childNodes[3],true); |
||
2727 | }; |
||
2728 | |||
2729 | /** |
||
2730 | * @desc: retun selected node text |
||
2731 | * @type: public |
||
2732 | * @return: text of selected node (or list of all selected nodes text if more than one selected) |
||
2733 | * @topic: 1 |
||
2734 | */ |
||
2735 | dhtmlXTreeObject.prototype.getSelectedItemText=function() |
||
2736 | { |
||
2737 | var str=new Array(); |
||
2738 | for (var i=0; i<this._selected.length; i++) str[i]=this._selected[i].span.innerHTML; |
||
2739 | return (str.join(this.dlmtr)); |
||
2740 | }; |
||
2741 | |||
2742 | |||
2743 | |||
2744 | |||
2745 | /** |
||
2746 | * @desc: correct childNode list after node deleting |
||
2747 | * @type: private |
||
2748 | * @param: Count - childNodes collection length |
||
2749 | * @param: Nodes - childNodes collection |
||
2750 | * @topic: 4 |
||
2751 | */ |
||
2752 | dhtmlXTreeObject.prototype._compressChildList=function(Count,Nodes) |
||
2753 | { |
||
2754 | Count--; |
||
2755 | for (var i=0; i<Count; i++) |
||
2756 | { |
||
2757 | if (Nodes[i]==0) { Nodes[i]=Nodes[i+1]; Nodes[i+1]=0;} |
||
2758 | }; |
||
2759 | }; |
||
2760 | /** |
||
2761 | * @desc: delete node |
||
2762 | * @type: private |
||
2763 | * @param: itemId - target node id |
||
2764 | * @param: htmlObject - target node object |
||
2765 | * @param: skip - node unregistration mode (optional, used by private methods) |
||
2766 | * @topic: 2 |
||
2767 | */ |
||
2768 | dhtmlXTreeObject.prototype._deleteNode=function(itemId,htmlObject,skip){ |
||
2769 | if ((!htmlObject)||(!htmlObject.parentObject)) return 0; |
||
2770 | var tempos=0; var tempos2=0; |
||
2771 | if (htmlObject.tr.nextSibling) tempos=htmlObject.tr.nextSibling.nodem; |
||
2772 | if (htmlObject.tr.previousSibling) tempos2=htmlObject.tr.previousSibling.nodem; |
||
2773 | |||
2774 | var sN=htmlObject.parentObject; |
||
2775 | var Count=sN.childsCount; |
||
2776 | var Nodes=sN.childNodes; |
||
2777 | for (var i=0; i<Count; i++) |
||
2778 | { |
||
2779 | if (Nodes[i].id==itemId) { |
||
2780 | if (!skip) sN.htmlNode.childNodes[0].removeChild(Nodes[i].tr); |
||
2781 | Nodes[i]=0; |
||
2782 | break; |
||
2783 | } |
||
2784 | } |
||
2785 | this._compressChildList(Count,Nodes); |
||
2786 | if (!skip) { |
||
2787 | sN.childsCount--; |
||
2788 | } |
||
2789 | |||
2790 | if (tempos) { |
||
2791 | this._correctPlus(tempos); |
||
2792 | this._correctLine(tempos); |
||
2793 | } |
||
2794 | if (tempos2) { |
||
2795 | this._correctPlus(tempos2); |
||
2796 | this._correctLine(tempos2); |
||
2797 | } |
||
2798 | if (this.tscheck) this._correctCheckStates(sN); |
||
2799 | |||
2800 | if (!skip) { |
||
2801 | this._globalIdStorageRecSub(htmlObject); |
||
2802 | } |
||
2803 | }; |
||
2804 | /** |
||
2805 | * @desc: set state of node's checkbox |
||
2806 | * @type: public |
||
2807 | * @param: itemId - target node id |
||
2808 | * @param: state - checkbox state (0/1/"unsure") |
||
2809 | * @topic: 5 |
||
2810 | */ |
||
2811 | dhtmlXTreeObject.prototype.setCheck=function(itemId,state){ |
||
2812 | var sNode=this._globalIdStorageFind(itemId,0,1); |
||
2813 | if (!sNode) return; |
||
2814 | |||
2815 | if (state==="unsure") |
||
2816 | this._setCheck(sNode,state); |
||
2817 | else |
||
2818 | { |
||
2819 | state=convertStringToBoolean(state); |
||
2820 | if ((this.tscheck)&&(this.smcheck)) this._setSubChecked(state,sNode); |
||
2821 | else this._setCheck(sNode,state); |
||
2822 | } |
||
2823 | if (this.smcheck) |
||
2824 | this._correctCheckStates(sNode.parentObject); |
||
2825 | }; |
||
2826 | |||
2827 | dhtmlXTreeObject.prototype._setCheck=function(sNode,state){ |
||
2828 | if (!sNode) return; |
||
2829 | if (((sNode.parentObject._r_logic)||(this._frbtr))&&(state)) |
||
2830 | if (this._frbtrs){ |
||
2831 | if (this._frbtrL) this.setCheck(this._frbtrL.id,0); |
||
2832 | this._frbtrL=sNode; |
||
2833 | } else |
||
2834 | for (var i=0; i<sNode.parentObject.childsCount; i++) |
||
2835 | this._setCheck(sNode.parentObject.childNodes[i],0); |
||
2836 | |||
2837 | var z=sNode.htmlNode.childNodes[0].childNodes[0].childNodes[1].childNodes[0]; |
||
2838 | |||
2839 | if (state=="unsure") sNode.checkstate=2; |
||
2840 | else if (state) sNode.checkstate=1; else sNode.checkstate=0; |
||
2841 | if (sNode.dscheck) sNode.checkstate=sNode.dscheck; |
||
2842 | this._setSrc(z,this.imPath+((sNode.parentObject._r_logic||this._frbtr)?this.radioArray:this.checkArray)[sNode.checkstate]); |
||
2843 | }; |
||
2844 | |||
2845 | /** |
||
2846 | * @desc: change state of node's checkbox and all children checkboxes |
||
2847 | * @type: public |
||
2848 | * @param: itemId - target node id |
||
2849 | * @param: state - checkbox state |
||
2850 | * @topic: 5 |
||
2851 | */ |
||
2852 | dhtmlXTreeObject.prototype.setSubChecked=function(itemId,state){ |
||
2853 | var sNode=this._globalIdStorageFind(itemId); |
||
2854 | this._setSubChecked(state,sNode); |
||
2855 | this._correctCheckStates(sNode.parentObject); |
||
2856 | } |
||
2857 | |||
2858 | |||
2859 | |||
2860 | /** |
||
2861 | * @desc: change state of node's checkbox and all childnodes checkboxes |
||
2862 | * @type: private |
||
2863 | * @param: itemId - target node id |
||
2864 | * @param: state - checkbox state |
||
2865 | * @param: sNode - target node object (optional, used by private methods) |
||
2866 | * @topic: 5 |
||
2867 | */ |
||
2868 | dhtmlXTreeObject.prototype._setSubChecked=function(state,sNode){ |
||
2869 | state=convertStringToBoolean(state); |
||
2870 | if (!sNode) return; |
||
2871 | if (((sNode.parentObject._r_logic)||(this._frbtr))&&(state)) |
||
2872 | for (var i=0; i<sNode.parentObject.childsCount; i++) |
||
2873 | this._setSubChecked(0,sNode.parentObject.childNodes[i]); |
||
2874 | |||
2875 | |||
2876 | if (sNode._r_logic||this._frbtr) |
||
2877 | this._setSubChecked(state,sNode.childNodes[0]); |
||
2878 | else |
||
2879 | for (var i=0; i<sNode.childsCount; i++) |
||
2880 | { |
||
2881 | this._setSubChecked(state,sNode.childNodes[i]); |
||
2882 | }; |
||
2883 | var z=sNode.htmlNode.childNodes[0].childNodes[0].childNodes[1].childNodes[0]; |
||
2884 | |||
2885 | if (state) sNode.checkstate=1; |
||
2886 | else sNode.checkstate=0; |
||
2887 | if (sNode.dscheck) sNode.checkstate=sNode.dscheck; |
||
2888 | |||
2889 | |||
2890 | |||
2891 | this._setSrc(z,this.imPath+((sNode.parentObject._r_logic||this._frbtr)?this.radioArray:this.checkArray)[sNode.checkstate]); |
||
2892 | }; |
||
2893 | |||
2894 | /** |
||
2895 | * @desc: get state of nodes's checkbox |
||
2896 | * @type: public |
||
2897 | * @param: itemId - target node id |
||
2898 | * @return: node state (0 - unchecked,1 - checked, 2 - third state) |
||
2899 | * @topic: 5 |
||
2900 | */ |
||
2901 | dhtmlXTreeObject.prototype.isItemChecked=function(itemId){ |
||
2902 | var sNode=this._globalIdStorageFind(itemId); |
||
2903 | if (!sNode) return; |
||
2904 | return sNode.checkstate; |
||
2905 | }; |
||
2906 | |||
2907 | |||
2908 | |||
2909 | |||
2910 | |||
2911 | |||
2912 | |||
2913 | /** |
||
2914 | * @desc: delete all children of node |
||
2915 | * @type: public |
||
2916 | * @param: itemId - node id |
||
2917 | * @topic: 2 |
||
2918 | */ |
||
2919 | dhtmlXTreeObject.prototype.deleteChildItems=function(itemId) |
||
2920 | { |
||
2921 | var sNode=this._globalIdStorageFind(itemId); |
||
2922 | if (!sNode) return; |
||
2923 | var j=sNode.childsCount; |
||
2924 | for (var i=0; i<j; i++) |
||
2925 | { |
||
2926 | this._deleteNode(sNode.childNodes[0].id,sNode.childNodes[0]); |
||
2927 | }; |
||
2928 | }; |
||
2929 | |||
2930 | /** |
||
2931 | * @desc: delete node |
||
2932 | * @type: public |
||
2933 | * @param: itemId - node id |
||
2934 | * @param: selectParent - If true parent of deleted item get selection, else no selected items leaving in tree. |
||
2935 | * @topic: 2 |
||
2936 | */ |
||
2937 | dhtmlXTreeObject.prototype.deleteItem=function(itemId,selectParent){ |
||
2938 | if ((!this._onrdlh)||(this._onrdlh(itemId))){ |
||
2939 | var z=this._deleteItem(itemId,selectParent); |
||
2940 | |||
2941 | } |
||
2942 | |||
2943 | //nb:solves standard doctype prb in IE |
||
2944 | this.allTree.childNodes[0].border = "1"; |
||
2945 | this.allTree.childNodes[0].border = "0"; |
||
2946 | } |
||
2947 | /** |
||
2948 | * @desc: delete node |
||
2949 | * @type: private |
||
2950 | * @param: id - node id |
||
2951 | * @param: selectParent - If true parent of deleted item get selection, else no selected items leaving in tree. |
||
2952 | * @param: skip - unregistering mode (optional, used by private methods) |
||
2953 | * @topic: 2 |
||
2954 | */ |
||
2955 | dhtmlXTreeObject.prototype._deleteItem=function(itemId,selectParent,skip){ |
||
2956 | selectParent=convertStringToBoolean(selectParent); |
||
2957 | var sNode=this._globalIdStorageFind(itemId); |
||
2958 | if (!sNode) return; |
||
2959 | var pid=this.getParentId(itemId); |
||
2960 | |||
2961 | var zTemp=sNode.parentObject; |
||
2962 | this._deleteNode(itemId,sNode,skip); |
||
2963 | if(this._editCell&&this._editCell.id==itemId) |
||
2964 | this._editCell = null; |
||
2965 | this._correctPlus(zTemp); |
||
2966 | this._correctLine(zTemp); |
||
2967 | |||
2968 | if ((selectParent)&&(pid!=this.rootId)) this.selectItem(pid,1); |
||
2969 | return zTemp; |
||
2970 | }; |
||
2971 | |||
2972 | /** |
||
2973 | * @desc: uregister all child nodes of target node |
||
2974 | * @type: private |
||
2975 | * @param: itemObject - node object |
||
2976 | * @topic: 3 |
||
2977 | */ |
||
2978 | dhtmlXTreeObject.prototype._globalIdStorageRecSub=function(itemObject){ |
||
2979 | for(var i=0; i<itemObject.childsCount; i++) |
||
2980 | { |
||
2981 | this._globalIdStorageRecSub(itemObject.childNodes[i]); |
||
2982 | this._globalIdStorageSub(itemObject.childNodes[i].id); |
||
2983 | }; |
||
2984 | this._globalIdStorageSub(itemObject.id); |
||
2985 | |||
2986 | /*anti memory leaking*/ |
||
2987 | var z=itemObject; |
||
2988 | // var par=z.span.parentNode.parentNode.childNodes; |
||
2989 | // par[0].parentObject=null; |
||
2990 | // par[1].childNodes[0].parentObject=null; |
||
2991 | // par[2].childNodes[0].parentObject=null; |
||
2992 | // par[2].childNodes[0].treeNod=null; |
||
2993 | // par[2].parentObject=null; |
||
2994 | // par[3].parentObject=null; |
||
2995 | z.span=null; |
||
2996 | z.tr.nodem=null; |
||
2997 | z.tr=null; |
||
2998 | z.htmlNode=null; |
||
2999 | }; |
||
3000 | |||
3001 | /** |
||
3002 | * @desc: create new node next to specified |
||
3003 | * @type: public |
||
3004 | * @param: itemId - node id |
||
3005 | * @param: newItemId - new node id |
||
3006 | * @param: itemText - new node text |
||
3007 | * @param: itemActionHandler - function fired on node select event (optional) |
||
3008 | * @param: image1 - image for node without children; (optional) |
||
3009 | * @param: image2 - image for closed node; (optional) |
||
3010 | * @param: image3 - image for opened node (optional) |
||
3011 | * @param: optionStr - options string (optional) |
||
3012 | * @param: children - node children flag (for dynamical trees) (optional) |
||
3013 | * @topic: 2 |
||
3014 | */ |
||
3015 | dhtmlXTreeObject.prototype.insertNewNext=function(itemId,newItemId,itemText,itemActionHandler,image1,image2,image3,optionStr,children){ |
||
3016 | var sNode=this._globalIdStorageFind(itemId); |
||
3017 | if ((!sNode)||(!sNode.parentObject)) return (0); |
||
3018 | |||
3019 | var nodez=this._attachChildNode(0,newItemId,itemText,itemActionHandler,image1,image2,image3,optionStr,children,sNode); |
||
3020 | |||
3021 | return nodez; |
||
3022 | }; |
||
3023 | |||
3024 | |||
3025 | |||
3026 | /** |
||
3027 | * @desc: retun node id by index |
||
3028 | * @type: public |
||
3029 | * @param: itemId - parent node id |
||
3030 | * @param: index - index of node, 0 based |
||
3031 | * @return: node id |
||
3032 | * @topic: 1 |
||
3033 | */ |
||
3034 | dhtmlXTreeObject.prototype.getItemIdByIndex=function(itemId,index){ |
||
3035 | var z=this._globalIdStorageFind(itemId); |
||
3036 | if ((!z)||(index>=z.childsCount)) return null; |
||
3037 | return z.childNodes[index].id; |
||
3038 | }; |
||
3039 | |||
3040 | /** |
||
3041 | * @desc: retun child node id by index |
||
3042 | * @type: public |
||
3043 | * @param: itemId - parent node id |
||
3044 | * @param: index - index of child node |
||
3045 | * @return: node id |
||
3046 | * @topic: 1 |
||
3047 | */ |
||
3048 | dhtmlXTreeObject.prototype.getChildItemIdByIndex=function(itemId,index){ |
||
3049 | var z=this._globalIdStorageFind(itemId); |
||
3050 | if ((!z)||(index>=z.childsCount)) return null; |
||
3051 | return z.childNodes[index].id; |
||
3052 | }; |
||
3053 | |||
3054 | |||
3055 | |||
3056 | |||
3057 | |||
3058 | /** |
||
3059 | * @desc: set function called when drag-and-drop event occured |
||
3060 | * @param: aFunc - event handling function |
||
3061 | * @type: deprecated |
||
3062 | * @topic: 0,7 |
||
3063 | * @event: onDrag |
||
3064 | * @depricated: use grid.attachEvent("onDrag",func); instead |
||
3065 | * @eventdesc: Event occured after item was dragged and droped on another item, but before item moving processed. |
||
3066 | Event also raised while programmatic moving nodes. |
||
3067 | * @eventparam: ID of source item |
||
3068 | * @eventparam: ID of target item |
||
3069 | * @eventparam: if node droped as sibling then contain id of item before whitch source node will be inserted |
||
3070 | * @eventparam: source Tree object |
||
3071 | * @eventparam: target Tree object |
||
3072 | * @eventreturn: true - confirm drag-and-drop; false - deny drag-and-drop; |
||
3073 | */ |
||
3074 | dhtmlXTreeObject.prototype.setDragHandler=function(func){ this.attachEvent("onDrag",func); }; |
||
3075 | |||
3076 | /** |
||
3077 | * @desc: clear selection from node |
||
3078 | * @param: htmlNode - pointer to node object |
||
3079 | * @type: private |
||
3080 | * @topic: 1 |
||
3081 | */ |
||
3082 | dhtmlXTreeObject.prototype._clearMove=function(){ |
||
3083 | if (this._lastMark){ |
||
3084 | this._lastMark.className=this._lastMark.className.replace(/dragAndDropRow/g,""); |
||
3085 | this._lastMark=null; |
||
3086 | } |
||
3087 | |||
3088 | this.allTree.className=this.allTree.className.replace(" selectionBox",""); |
||
3089 | }; |
||
3090 | |||
3091 | /** |
||
3092 | * @desc: enable/disable drag-and-drop |
||
3093 | * @type: public |
||
3094 | * @param: mode - enabled/disabled [ can be true/false/temporary_disabled - last value mean that tree can be D-n-D can be switched to true later ] |
||
3095 | * @param: rmode - enabled/disabled drag and drop on super root |
||
3096 | * @topic: 0 |
||
3097 | */ |
||
3098 | dhtmlXTreeObject.prototype.enableDragAndDrop=function(mode,rmode){ |
||
3099 | if (mode=="temporary_disabled"){ |
||
3100 | this.dADTempOff=false; |
||
3101 | mode=true; } |
||
3102 | else |
||
3103 | this.dADTempOff=true; |
||
3104 | |||
3105 | this.dragAndDropOff=convertStringToBoolean(mode); |
||
3106 | if (this.dragAndDropOff) this.dragger.addDragLanding(this.allTree,this); |
||
3107 | if (arguments.length>1) |
||
3108 | this._ddronr=(!convertStringToBoolean(rmode)); |
||
3109 | }; |
||
3110 | |||
3111 | /** |
||
3112 | * @desc: set selection on node |
||
3113 | * @param: node - pointer to node object |
||
3114 | * @type: private |
||
3115 | * @topic: 1 |
||
3116 | */ |
||
3117 | dhtmlXTreeObject.prototype._setMove=function(htmlNode,x,y){ |
||
3118 | if (htmlNode.parentObject.span) { |
||
3119 | //window.status=x; |
||
3120 | var a1=getAbsoluteTop(htmlNode); |
||
3121 | var a2=getAbsoluteTop(this.allTree)-this.allTree.scrollTop; |
||
3122 | |||
3123 | this.dadmodec=this.dadmode;//this.dadmode; |
||
3124 | this.dadmodefix=0; |
||
3125 | |||
3126 | |||
3127 | var zN=htmlNode.parentObject.span; |
||
3128 | zN.className+=" dragAndDropRow"; |
||
3129 | this._lastMark=zN; |
||
3130 | |||
3131 | this._autoScroll(null,a1,a2); |
||
3132 | |||
3133 | } |
||
3134 | }; |
||
3135 | |||
3136 | View Code Duplication | dhtmlXTreeObject.prototype._autoScroll=function(node,a1,a2){ |
|
3137 | if (this.autoScroll) |
||
3138 | { |
||
3139 | if (node){ |
||
3140 | a1=getAbsoluteTop(node); |
||
3141 | a2=getAbsoluteTop(this.allTree)-this.allTree.scrollTop; |
||
3142 | } |
||
3143 | //scroll down |
||
3144 | if ( (a1-a2-parseInt(this.allTree.scrollTop))>(parseInt(this.allTree.offsetHeight)-50) ) |
||
3145 | this.allTree.scrollTop=parseInt(this.allTree.scrollTop)+20; |
||
3146 | //scroll top |
||
3147 | if ( (a1-a2)<(parseInt(this.allTree.scrollTop)+30) ) |
||
3148 | this.allTree.scrollTop=parseInt(this.allTree.scrollTop)-20; |
||
3149 | } |
||
3150 | } |
||
3151 | |||
3152 | /** |
||
3153 | * @desc: create html element for dragging |
||
3154 | * @type: private |
||
3155 | * @param: htmlObject - html node object |
||
3156 | * @topic: 1 |
||
3157 | */ |
||
3158 | dhtmlXTreeObject.prototype._createDragNode=function(htmlObject,e){ |
||
3159 | if (!this.dADTempOff) return null; |
||
3160 | |||
3161 | var obj=htmlObject.parentObject; |
||
3162 | if (!this.callEvent("onBeforeDrag",[obj.id, e])) return null; |
||
3163 | if (!obj.i_sel){ |
||
3164 | |||
3165 | this._selectItem(obj,e); |
||
3166 | } |
||
3167 | |||
3168 | var dragSpan=document.createElement('div'); |
||
3169 | |||
3170 | var text=new Array(); |
||
3171 | if (this._itim_dg) |
||
3172 | for (var i=0; i<this._selected.length; i++) |
||
3173 | text[i]="<table cellspacing='0' cellpadding='0'><tr><td><img width='18px' height='18px' src='"+this._getSrc(this._selected[i].span.parentNode.previousSibling.childNodes[0])+"'></td><td>"+this._selected[i].span.innerHTML+"</td></tr></table>"; |
||
3174 | else |
||
3175 | text=this.getSelectedItemText().split(this.dlmtr); |
||
3176 | |||
3177 | dragSpan.innerHTML=text.join(""); |
||
3178 | dragSpan.style.position="absolute"; |
||
3179 | dragSpan.className="dragSpanDiv"; |
||
3180 | this._dragged=(new Array()).concat(this._selected); |
||
3181 | return dragSpan; |
||
3182 | } |
||
3183 | |||
3184 | |||
3185 | |||
3186 | /** |
||
3187 | * @desc: focus item in tree |
||
3188 | * @type: private |
||
3189 | * @param: item - node object |
||
3190 | * @edition: Professional |
||
3191 | * @topic: 0 |
||
3192 | */ |
||
3193 | dhtmlXTreeObject.prototype._focusNode=function(item){ |
||
3194 | var z=getAbsoluteTop(item.htmlNode)-getAbsoluteTop(this.allTree); |
||
3195 | if ((z>(this.allTree.offsetHeight-30)) || (z<0)) |
||
3196 | this.allTree.scrollTop=z+this.allTree.scrollTop; |
||
3197 | }; |
||
3198 | |||
3199 | |||
3200 | |||
3201 | |||
3202 | |||
3203 | |||
3204 | |||
3205 | |||
3206 | |||
3207 | |||
3208 | |||
3209 | |||
3210 | |||
3211 | ///DragAndDrop |
||
3212 | |||
3213 | dhtmlXTreeObject.prototype._preventNsDrag=function(e){ |
||
3214 | if ((e)&&(e.preventDefault)) { e.preventDefault(); return false; } |
||
3215 | return false; |
||
3216 | } |
||
3217 | |||
3218 | dhtmlXTreeObject.prototype._drag=function(sourceHtmlObject,dhtmlObject,targetHtmlObject){ |
||
3219 | if (this._autoOpenTimer) clearTimeout(this._autoOpenTimer); |
||
3220 | |||
3221 | if (!targetHtmlObject.parentObject){ |
||
3222 | targetHtmlObject=this.htmlNode.htmlNode.childNodes[0].childNodes[0].childNodes[1].childNodes[0]; |
||
3223 | this.dadmodec=0; |
||
3224 | } |
||
3225 | |||
3226 | this._clearMove(); |
||
3227 | var z=sourceHtmlObject.parentObject.treeNod; |
||
3228 | if ((z)&&(z._clearMove)) z._clearMove(""); |
||
3229 | |||
3230 | if ((!this.dragMove)||(this.dragMove())) |
||
3231 | { |
||
3232 | if ((!z)||(!z._clearMove)||(!z._dragged)) var col=new Array(sourceHtmlObject.parentObject); |
||
3233 | else var col=z._dragged; |
||
3234 | var trg=targetHtmlObject.parentObject; |
||
3235 | |||
3236 | for (var i=0; i<col.length; i++){ |
||
3237 | var newID=this._moveNode(col[i],trg); |
||
3238 | if ((this.dadmodec)&&(newID!==false)) trg=this._globalIdStorageFind(newID,true,true); |
||
3239 | if ((newID)&&(!this._sADnD)) this.selectItem(newID,0,1); |
||
3240 | } |
||
3241 | |||
3242 | } |
||
3243 | if (z) z._dragged=new Array(); |
||
3244 | |||
3245 | |||
3246 | } |
||
3247 | |||
3248 | dhtmlXTreeObject.prototype._dragIn=function(htmlObject,shtmlObject,x,y){ |
||
3249 | |||
3250 | if (!this.dADTempOff) return 0; |
||
3251 | var fobj=shtmlObject.parentObject; |
||
3252 | var tobj=htmlObject.parentObject; |
||
3253 | if ((!tobj)&&(this._ddronr)) return; |
||
3254 | if (!this.callEvent("onDragIn",[fobj.id,tobj?tobj.id:null,fobj.treeNod,this])){ |
||
3255 | if (tobj) this._autoScroll(htmlObject); |
||
3256 | return 0; |
||
3257 | } |
||
3258 | |||
3259 | |||
3260 | if (!tobj) |
||
3261 | this.allTree.className+=" selectionBox"; |
||
3262 | else |
||
3263 | { |
||
3264 | if (fobj.childNodes==null){ |
||
3265 | this._setMove(htmlObject,x,y); |
||
3266 | return htmlObject; |
||
3267 | } |
||
3268 | |||
3269 | var stree=fobj.treeNod; |
||
3270 | for (var i=0; i<stree._dragged.length; i++) |
||
3271 | if (this._checkPNodes(tobj,stree._dragged[i])){ |
||
3272 | this._autoScroll(htmlObject); |
||
3273 | return 0; |
||
3274 | } |
||
3275 | |||
3276 | this._setMove(htmlObject,x,y); |
||
3277 | if (this._getOpenState(tobj)<=0){ |
||
3278 | this._autoOpenId=tobj.id; |
||
3279 | this._autoOpenTimer=window.setTimeout(new callerFunction(this._autoOpenItem,this),1000); |
||
3280 | } |
||
3281 | } |
||
3282 | |||
3283 | return htmlObject; |
||
3284 | |||
3285 | } |
||
3286 | dhtmlXTreeObject.prototype._autoOpenItem=function(e,treeObject){ |
||
3287 | treeObject.openItem(treeObject._autoOpenId); |
||
3288 | }; |
||
3289 | dhtmlXTreeObject.prototype._dragOut=function(htmlObject){ |
||
3290 | this._clearMove(); |
||
3291 | if (this._autoOpenTimer) clearTimeout(this._autoOpenTimer); |
||
3292 | } |
||
3293 | |||
3294 | |||
3295 | |||
3296 | |||
3297 | |||
3298 | //#complex_move:01112006{ |
||
3299 | |||
3300 | /** |
||
3301 | * @desc: move item (inside of tree) |
||
3302 | * @type: public |
||
3303 | * @param: itemId - item Id |
||
3304 | * @param: mode - moving mode (left,up,down,item_child,item_sibling,item_sibling_next,up_strict,down_strict) |
||
3305 | * @param: targetId - target Node in item_child and item_sibling mode |
||
3306 | * @param: targetTree - used for moving between trees (optional) |
||
3307 | * @return: node id |
||
3308 | * @topic: 2 |
||
3309 | */ |
||
3310 | dhtmlXTreeObject.prototype.moveItem=function(itemId,mode,targetId,targetTree) |
||
3311 | { |
||
3312 | var sNode=this._globalIdStorageFind(itemId); |
||
3313 | if (!sNode) return (0); |
||
3314 | var resultId = null; |
||
3315 | switch(mode){ |
||
3316 | case "right": |
||
3317 | alert('Not supported yet'); |
||
3318 | break; |
||
3319 | case "item_child": |
||
3320 | var tNode=(targetTree||this)._globalIdStorageFind(targetId); |
||
3321 | if (!tNode) return (0); |
||
3322 | resultId = (targetTree||this)._moveNodeTo(sNode,tNode,0); |
||
3323 | break; |
||
3324 | case "item_sibling": |
||
3325 | var tNode=(targetTree||this)._globalIdStorageFind(targetId); |
||
3326 | if (!tNode) return (0); |
||
3327 | resultId = (targetTree||this)._moveNodeTo(sNode,tNode.parentObject,tNode); |
||
3328 | break; |
||
3329 | case "item_sibling_next": |
||
3330 | var tNode=(targetTree||this)._globalIdStorageFind(targetId); |
||
3331 | if (!tNode) return (0); |
||
3332 | if ((tNode.tr)&&(tNode.tr.nextSibling)&&(tNode.tr.nextSibling.nodem)) |
||
3333 | resultId = (targetTree||this)._moveNodeTo(sNode,tNode.parentObject,tNode.tr.nextSibling.nodem); |
||
3334 | else |
||
3335 | resultId = (targetTree||this)._moveNodeTo(sNode,tNode.parentObject); |
||
3336 | break; |
||
3337 | case "left": |
||
3338 | if (sNode.parentObject.parentObject) |
||
3339 | resultId = this._moveNodeTo(sNode,sNode.parentObject.parentObject,sNode.parentObject); |
||
3340 | break; |
||
3341 | case "up": |
||
3342 | var z=this._getPrevNode(sNode); |
||
3343 | if ((z==-1)||(!z.parentObject)) return null; |
||
3344 | resultId = this._moveNodeTo(sNode,z.parentObject,z); |
||
3345 | break; |
||
3346 | case "up_strict": |
||
3347 | var z=this._getIndex(sNode); |
||
3348 | if (z!=0) |
||
3349 | resultId = this._moveNodeTo(sNode,sNode.parentObject,sNode.parentObject.childNodes[z-1]); |
||
3350 | break; |
||
3351 | case "down_strict": |
||
3352 | var z=this._getIndex(sNode); |
||
3353 | var count=sNode.parentObject.childsCount-2; |
||
3354 | if (z==count) |
||
3355 | resultId = this._moveNodeTo(sNode,sNode.parentObject); |
||
3356 | else if (z<count) |
||
3357 | resultId = this._moveNodeTo(sNode,sNode.parentObject,sNode.parentObject.childNodes[z+2]); |
||
3358 | break; |
||
3359 | case "down": |
||
3360 | var z=this._getNextNode(this._lastChild(sNode)); |
||
3361 | if ((z==-1)||(!z.parentObject)) return; |
||
3362 | if (z.parentObject==sNode.parentObject) |
||
3363 | var z=this._getNextNode(z); |
||
3364 | if (z==-1){ |
||
3365 | resultId = this._moveNodeTo(sNode,sNode.parentObject); |
||
3366 | } |
||
3367 | else{ |
||
3368 | if ((z==-1)||(!z.parentObject)) return; |
||
3369 | resultId = this._moveNodeTo(sNode,z.parentObject,z); |
||
3370 | } |
||
3371 | break; |
||
3372 | } |
||
3373 | if (_isIE && _isIE<8){ |
||
3374 | this.allTree.childNodes[0].border = "1"; |
||
3375 | this.allTree.childNodes[0].border = "0"; |
||
3376 | } |
||
3377 | return resultId; |
||
3378 | } |
||
3379 | |||
3380 | |||
3381 | //#} |
||
3382 | |||
3383 | |||
3384 | |||
3385 | |||
3386 | |||
3387 | |||
3388 | |||
3389 | /** |
||
3390 | * @desc: load xml for tree branch |
||
3391 | * @param: id - id of parent node |
||
3392 | * @param: src - path to xml, optional |
||
3393 | * @type: private |
||
3394 | * @topic: 1 |
||
3395 | */ |
||
3396 | dhtmlXTreeObject.prototype._loadDynXML=function(id,src) { |
||
3397 | src=src||this.XMLsource; |
||
3398 | var sn=(new Date()).valueOf(); |
||
3399 | this._ld_id=id; |
||
3400 | |||
3401 | this.loadXML(src+getUrlSymbol(src)+"uid="+sn+"&id="+this._escape(id)); |
||
3402 | }; |
||
3403 | |||
3404 | |||
3405 | |||
3406 | |||
3407 | |||
3408 | |||
3409 | |||
3410 | /** |
||
3411 | * @desc: check possibility of drag-and-drop |
||
3412 | * @type: private |
||
3413 | * @param: itemId - draged node id |
||
3414 | * @param: htmlObject - droped node object |
||
3415 | * @param: shtmlObject - sourse node object |
||
3416 | * @topic: 6 |
||
3417 | */ |
||
3418 | dhtmlXTreeObject.prototype._checkPNodes=function(item1,item2){ |
||
3419 | if (this._dcheckf) return false; |
||
3420 | if (item2==item1) return 1 |
||
3421 | if (item1.parentObject) return this._checkPNodes(item1.parentObject,item2); else return 0; |
||
3422 | }; |
||
3423 | dhtmlXTreeObject.prototype.disableDropCheck = function(mode){ |
||
3424 | this._dcheckf = convertStringToBoolean(mode); |
||
3425 | }; |
||
3426 | |||
3427 | |||
3428 | |||
3429 | |||
3430 | |||
3431 | |||
3432 | |||
3433 | |||
3434 | |||
3435 | /** |
||
3436 | * @desc: prevent caching in IE by adding random value to URL string |
||
3437 | * @param: mode - enable/disable random value ( disabled by default ) |
||
3438 | * @type: public |
||
3439 | * @topic: 0 |
||
3440 | */ |
||
3441 | dhtmlXTreeObject.prototype.preventIECaching=function(mode){ |
||
3442 | this.no_cashe = convertStringToBoolean(mode); |
||
3443 | this.XMLLoader.rSeed=this.no_cashe; |
||
3444 | } |
||
3445 | dhtmlXTreeObject.prototype.preventIECashing=dhtmlXTreeObject.prototype.preventIECaching; |
||
3446 | |||
3447 | |||
3448 | |||
3449 | |||
3450 | |||
3451 | /** |
||
3452 | * @desc: disable checkbox |
||
3453 | * @param: itemId - Id of tree item |
||
3454 | * @param: mode - 1 - on, 0 - off; |
||
3455 | * @type: public |
||
3456 | * @topic: 5 |
||
3457 | */ |
||
3458 | dhtmlXTreeObject.prototype.disableCheckbox=function(itemId,mode) { |
||
3459 | if (typeof(itemId)!="object") |
||
3460 | var sNode=this._globalIdStorageFind(itemId,0,1); |
||
3461 | else |
||
3462 | var sNode=itemId; |
||
3463 | if (!sNode) return; |
||
3464 | sNode.dscheck=convertStringToBoolean(mode)?(((sNode.checkstate||0)%3)+3):((sNode.checkstate>2)?(sNode.checkstate-3):sNode.checkstate); |
||
3465 | this._setCheck(sNode); |
||
3466 | if (sNode.dscheck<3) sNode.dscheck=false; |
||
3467 | }; |
||
3468 | |||
3469 | |||
3470 | |||
3471 | |||
3472 | /** |
||
3473 | * @desc: set escaping mode (used for escaping ID in requests) |
||
3474 | * @param: mode - escaping mode ("utf8" for UTF escaping) |
||
3475 | * @type: public |
||
3476 | * @topic: 0 |
||
3477 | */ |
||
3478 | dhtmlXTreeObject.prototype.setEscapingMode=function(mode){ |
||
3479 | this.utfesc=mode; |
||
3480 | } |
||
3481 | |||
3482 | |||
3483 | /** |
||
3484 | * @desc: enable item highlighting (item text highlited on mouseover) |
||
3485 | * @beforeInit: 1 |
||
3486 | * @param: mode - 1 - on, 0 - off; |
||
3487 | * @type: public |
||
3488 | * @topic: 0 |
||
3489 | */ |
||
3490 | dhtmlXTreeObject.prototype.enableHighlighting=function(mode) { this.ehlt=true; this.ehlta=convertStringToBoolean(mode); }; |
||
3491 | |||
3492 | /** |
||
3493 | * @desc: called on mouse out |
||
3494 | * @type: private |
||
3495 | * @topic: 0 |
||
3496 | */ |
||
3497 | dhtmlXTreeObject.prototype._itemMouseOut=function(){ |
||
3498 | var that=this.childNodes[3].parentObject; |
||
3499 | var tree=that.treeNod; |
||
3500 | tree.callEvent("onMouseOut",[that.id]); |
||
3501 | if (that.id==tree._l_onMSI) tree._l_onMSI=null; |
||
3502 | if (!tree.ehlta) return; |
||
3503 | that.span.className=that.span.className.replace("_lor",""); |
||
3504 | } |
||
3505 | /** |
||
3506 | * @desc: called on mouse in |
||
3507 | * @type: private |
||
3508 | * @topic: 0 |
||
3509 | */ |
||
3510 | dhtmlXTreeObject.prototype._itemMouseIn=function(){ |
||
3511 | var that=this.childNodes[3].parentObject; |
||
3512 | var tree=that.treeNod; |
||
3513 | |||
3514 | if (tree._l_onMSI!=that.id) tree.callEvent("onMouseIn",[that.id]); |
||
3515 | tree._l_onMSI=that.id; |
||
3516 | if (!tree.ehlta) return; |
||
3517 | that.span.className=that.span.className.replace("_lor",""); |
||
3518 | that.span.className=that.span.className.replace(/((standart|selected)TreeRow)/,"$1_lor"); |
||
3519 | } |
||
3520 | |||
3521 | /** |
||
3522 | * @desc: enable active images (clickable and dragable). By default only text part of the node is active |
||
3523 | * @beforeInit: 1 |
||
3524 | * @param: mode - 1 - on, 0 - off; |
||
3525 | * @type: public |
||
3526 | * @topic: 0 |
||
3527 | */ |
||
3528 | dhtmlXTreeObject.prototype.enableActiveImages=function(mode){this._aimgs=convertStringToBoolean(mode); }; |
||
3529 | |||
3530 | /** |
||
3531 | * @desc: focus item in tree (scroll to it if necessary) |
||
3532 | * @type: public |
||
3533 | * @param: itemId - item Id |
||
3534 | * @topic: 0 |
||
3535 | */ |
||
3536 | dhtmlXTreeObject.prototype.focusItem=function(itemId){ |
||
3537 | var sNode=this._globalIdStorageFind(itemId); |
||
3538 | if (!sNode) return (0); |
||
3539 | this._focusNode(sNode); |
||
3540 | }; |
||
3541 | |||
3542 | |||
3543 | /** |
||
3544 | * @desc: Returns the list of all children from all next levels of tree, separated by default delimiter. |
||
3545 | * @param: itemId - id of node |
||
3546 | * @type: public |
||
3547 | * @return: list of all children items from all next levels of tree, separated by default delimiter |
||
3548 | * @topic: 6 |
||
3549 | */ |
||
3550 | dhtmlXTreeObject.prototype.getAllSubItems =function(itemId){ |
||
3551 | return this._getAllSubItems(itemId); |
||
3552 | } |
||
3553 | |||
3554 | /** |
||
3555 | * @desc: Returns the list of all items which doesn't have child nodes. |
||
3556 | * @type: public |
||
3557 | * @return: list of all items which doesn't have child nodes. |
||
3558 | * @topic: 6 |
||
3559 | */ |
||
3560 | dhtmlXTreeObject.prototype.getAllChildless =function(){ |
||
3561 | return this._getAllScraggyItems(this.htmlNode); |
||
3562 | } |
||
3563 | dhtmlXTreeObject.prototype.getAllLeafs=dhtmlXTreeObject.prototype.getAllChildless; |
||
3564 | |||
3565 | |||
3566 | /** |
||
3567 | * @desc: Returns the list of all children from all next levels of tree, separated by default delimiter. |
||
3568 | * @param: itemId - id of node |
||
3569 | * @edition: Professional |
||
3570 | * @type: private |
||
3571 | * @topic: 6 |
||
3572 | */ |
||
3573 | View Code Duplication | dhtmlXTreeObject.prototype._getAllScraggyItems =function(node) |
|
3574 | { |
||
3575 | var z=""; |
||
3576 | for (var i=0; i<node.childsCount; i++) |
||
3577 | { |
||
3578 | if ((node.childNodes[i].unParsed)||(node.childNodes[i].childsCount>0)) |
||
3579 | { |
||
3580 | if (node.childNodes[i].unParsed) |
||
3581 | var zb=this._getAllScraggyItemsXML(node.childNodes[i].unParsed,1); |
||
3582 | else |
||
3583 | var zb=this._getAllScraggyItems(node.childNodes[i]) |
||
3584 | |||
3585 | if (zb) |
||
3586 | if (z) z+=this.dlmtr+zb; |
||
3587 | else z=zb; |
||
3588 | } |
||
3589 | else |
||
3590 | if (!z) z=""+node.childNodes[i].id; |
||
3591 | else z+=this.dlmtr+node.childNodes[i].id; |
||
3592 | } |
||
3593 | return z; |
||
3594 | }; |
||
3595 | |||
3596 | |||
3597 | |||
3598 | |||
3599 | |||
3600 | /** |
||
3601 | * @desc: Returns the list of all children from all next levels of tree, separated by default delimiter. |
||
3602 | * @param: itemId - id of node |
||
3603 | * @type: private |
||
3604 | * @edition: Professional |
||
3605 | * @topic: 6 |
||
3606 | */ |
||
3607 | View Code Duplication | dhtmlXTreeObject.prototype._getAllFatItems =function(node) |
|
3608 | { |
||
3609 | var z=""; |
||
3610 | for (var i=0; i<node.childsCount; i++) |
||
3611 | { |
||
3612 | if ((node.childNodes[i].unParsed)||(node.childNodes[i].childsCount>0)) |
||
3613 | { |
||
3614 | if (!z) z=""+node.childNodes[i].id; |
||
3615 | else z+=this.dlmtr+node.childNodes[i].id; |
||
3616 | |||
3617 | if (node.childNodes[i].unParsed) |
||
3618 | var zb=this._getAllFatItemsXML(node.childNodes[i].unParsed,1); |
||
3619 | else |
||
3620 | var zb=this._getAllFatItems(node.childNodes[i]) |
||
3621 | |||
3622 | if (zb) z+=this.dlmtr+zb; |
||
3623 | } |
||
3624 | } |
||
3625 | return z; |
||
3626 | }; |
||
3627 | |||
3628 | /** |
||
3629 | * @desc: Returns the list of all items which have child nodes, separated by default delimiter. |
||
3630 | * @type: public |
||
3631 | * @return: list of all items which has child nodes, separated by default delimiter. |
||
3632 | * @topic: 6 |
||
3633 | */ |
||
3634 | dhtmlXTreeObject.prototype.getAllItemsWithKids =function(){ |
||
3635 | return this._getAllFatItems(this.htmlNode); |
||
3636 | } |
||
3637 | dhtmlXTreeObject.prototype.getAllFatItems=dhtmlXTreeObject.prototype.getAllItemsWithKids; |
||
3638 | |||
3639 | |||
3640 | |||
3641 | /** |
||
3642 | * @desc: return list of identificators of nodes with checked checkboxes, separated by default delimiter |
||
3643 | * @type: public |
||
3644 | * @return: list of ID of items with checked checkboxes, separated by default delimiter |
||
3645 | * @topic: 5 |
||
3646 | */ |
||
3647 | dhtmlXTreeObject.prototype.getAllChecked=function(){ |
||
3648 | return this._getAllChecked("","",1); |
||
3649 | } |
||
3650 | /** |
||
3651 | * @desc: return list of identificators of nodes with unchecked checkboxes, separated by default delimiter |
||
3652 | * @type: public |
||
3653 | * @return: list of ID of items with unchecked checkboxes, separated by default delimiter |
||
3654 | * @topic: 5 |
||
3655 | */ |
||
3656 | dhtmlXTreeObject.prototype.getAllUnchecked=function(itemId){ |
||
3657 | if (itemId) |
||
3658 | itemId=this._globalIdStorageFind(itemId); |
||
3659 | return this._getAllChecked(itemId,"",0); |
||
3660 | } |
||
3661 | |||
3662 | |||
3663 | /** |
||
3664 | * @desc: return list of identificators of nodes with third state checkboxes, separated by default delimiter |
||
3665 | * @type: public |
||
3666 | * @return: list of ID of items with third state checkboxes, separated by default delimiter |
||
3667 | * @topic: 5 |
||
3668 | */ |
||
3669 | dhtmlXTreeObject.prototype.getAllPartiallyChecked=function(){ |
||
3670 | return this._getAllChecked("","",2); |
||
3671 | } |
||
3672 | |||
3673 | |||
3674 | /** |
||
3675 | * @desc: return list of identificators of nodes with checked and third state checkboxes, separated by default delimiter |
||
3676 | * @type: public |
||
3677 | * @return: list of ID of items with checked and third state checkboxes, separated by default delimiter |
||
3678 | * @topic: 5 |
||
3679 | */ |
||
3680 | dhtmlXTreeObject.prototype.getAllCheckedBranches=function(){ |
||
3681 | var temp = [this._getAllChecked("","",1)]; |
||
3682 | var second = this._getAllChecked("","",2); |
||
3683 | if (second) temp.push(second); |
||
3684 | return temp.join(this.dlmtr); |
||
3685 | } |
||
3686 | |||
3687 | /** |
||
3688 | * @desc: return list of identificators of nodes with checked checkboxes |
||
3689 | * @type: private |
||
3690 | * @param: node - node object (optional, used by private methods) |
||
3691 | * @param: list - initial identificators list (optional, used by private methods) |
||
3692 | * @topic: 5 |
||
3693 | */ |
||
3694 | dhtmlXTreeObject.prototype._getAllChecked=function(htmlNode,list,mode){ |
||
3695 | if (!htmlNode) htmlNode=this.htmlNode; |
||
3696 | |||
3697 | if (htmlNode.checkstate==mode) |
||
3698 | if (!htmlNode.nocheckbox) { if (list) list+=this.dlmtr+htmlNode.id; else list=""+htmlNode.id; } |
||
3699 | var j=htmlNode.childsCount; |
||
3700 | for (var i=0; i<j; i++) |
||
3701 | { |
||
3702 | list=this._getAllChecked(htmlNode.childNodes[i],list,mode); |
||
3703 | }; |
||
3704 | |||
3705 | |||
3706 | if (list) return list; else return ""; |
||
3707 | }; |
||
3708 | |||
3709 | /** |
||
3710 | * @desc: set individual item style |
||
3711 | * @type: public |
||
3712 | * @param: itemId - node id |
||
3713 | * @param: styleString - valid CSS string |
||
3714 | * @param: resetCss - reset current style : 0/1 |
||
3715 | * @topic: 2 |
||
3716 | */ |
||
3717 | dhtmlXTreeObject.prototype.setItemStyle=function(itemId,style_string,resetCss){ |
||
3718 | var resetCss= resetCss|| false; |
||
3719 | var temp=this._globalIdStorageFind(itemId); |
||
3720 | if (!temp) return 0; |
||
3721 | if (!temp.span.style.cssText) |
||
3722 | temp.span.setAttribute("style",temp.span.getAttribute("style")+"; "+style_string); |
||
3723 | else |
||
3724 | temp.span.style.cssText = resetCss? style_string : temp.span.style.cssText+";"+style_string; |
||
3725 | } |
||
3726 | |||
3727 | /** |
||
3728 | * @desc: enable draging item image with item text |
||
3729 | * @type: public |
||
3730 | * @param: mode - true/false |
||
3731 | * @topic: 1 |
||
3732 | */ |
||
3733 | dhtmlXTreeObject.prototype.enableImageDrag=function(mode){ |
||
3734 | this._itim_dg=convertStringToBoolean(mode); |
||
3735 | } |
||
3736 | |||
3737 | /** |
||
3738 | * @desc: set function called when tree item draged over another item |
||
3739 | * @param: func - event handling function |
||
3740 | * @type: depricated |
||
3741 | * @edition: Professional |
||
3742 | * @topic: 4 |
||
3743 | * @event: onDragIn |
||
3744 | * @depricated: use grid.attachEvent("onDragIn",func); instead |
||
3745 | * @eventdesc: Event raised when item draged other other dropable target |
||
3746 | * @eventparam: ID draged item |
||
3747 | * @eventparam: ID potencial drop landing |
||
3748 | * @eventparam: source object |
||
3749 | * @eventparam: target object |
||
3750 | * @eventreturn: true - allow drop; false - deny drop; |
||
3751 | */ |
||
3752 | dhtmlXTreeObject.prototype.setOnDragIn=function(func){ |
||
3753 | this.attachEvent("onDragIn",func); |
||
3754 | }; |
||
3755 | |||
3756 | /** |
||
3757 | * @desc: enable/disable auto scrolling while drag-and-drop |
||
3758 | * @type: public |
||
3759 | * @param: mode - enabled/disabled |
||
3760 | * @topic: 0 |
||
3761 | */ |
||
3762 | dhtmlXTreeObject.prototype.enableDragAndDropScrolling=function(mode){ this.autoScroll=convertStringToBoolean(mode); }; |
||
3763 | |||
3764 | |||
3765 | dhtmlXTreeObject.prototype.setSkin=function(name){ |
||
3766 | var tmp = this.parentObject.className.replace(/dhxtree_[^ ]*/gi,""); |
||
3767 | this.parentObject.className= tmp+" dhxtree_"+name; |
||
3768 | if (name == "dhx_terrace") |
||
3769 | this.enableTreeLines(false); |
||
3770 | }; |
||
3771 | |||
3772 | //tree |
||
3773 | View Code Duplication | (function(){ |
|
3774 | |||
3775 | dhtmlx.extend_api("dhtmlXTreeObject",{ |
||
3776 | _init:function(obj){ |
||
3777 | return [obj.parent,(obj.width||"100%"),(obj.height||"100%"),(obj.root_id||0)]; |
||
3778 | }, |
||
3779 | auto_save_selection:"enableAutoSavingSelected", |
||
3780 | auto_tooltip:"enableAutoTooltips", |
||
3781 | checkbox:"enableCheckBoxes", |
||
3782 | checkbox_3_state:"enableThreeStateCheckboxes", |
||
3783 | checkbox_smart:"enableSmartCheckboxes", |
||
3784 | context_menu:"enableContextMenu", |
||
3785 | distributed_parsing:"enableDistributedParsing", |
||
3786 | drag:"enableDragAndDrop", |
||
3787 | drag_copy:"enableMercyDrag", |
||
3788 | drag_image:"enableImageDrag", |
||
3789 | drag_scroll:"enableDragAndDropScrolling", |
||
3790 | editor:"enableItemEditor", |
||
3791 | hover:"enableHighlighting", |
||
3792 | images:"enableTreeImages", |
||
3793 | image_fix:"enableIEImageFix", |
||
3794 | image_path:"setImagePath", |
||
3795 | lines:"enableTreeLines", |
||
3796 | loading_item:"enableLoadingItem", |
||
3797 | multiline:"enableMultiLineItems", |
||
3798 | multiselect:"enableMultiselection", |
||
3799 | navigation:"enableKeyboardNavigation", |
||
3800 | radio:"enableRadioButtons", |
||
3801 | radio_single:"enableSingleRadioMode", |
||
3802 | rtl:"enableRTL", |
||
3803 | search:"enableKeySearch", |
||
3804 | smart_parsing:"enableSmartXMLParsing", |
||
3805 | smart_rendering:"enableSmartRendering", |
||
3806 | text_icons:"enableTextSigns", |
||
3807 | xml:"loadXML", |
||
3808 | skin:"setSkin" |
||
3809 | },{}); |
||
3810 | |||
3811 | })(); |
||
3812 | |||
3813 | dhtmlXTreeObject.prototype._dp_init=function(dp){ |
||
3814 | dp.attachEvent("insertCallback", function(upd, id, parent) { |
||
3815 | var data = this._loader.doXPath(".//item",upd); |
||
3816 | var text = data[0].getAttribute('text'); |
||
3817 | this.obj.insertNewItem(parent, id, text, 0, 0, 0, 0, "CHILD"); |
||
3818 | }); |
||
3819 | |||
3820 | dp.attachEvent("updateCallback", function(upd, id, parent) { |
||
3821 | var data = this._loader.doXPath(".//item",upd); |
||
3822 | var text = data[0].getAttribute('text'); |
||
3823 | this.obj.setItemText(id, text); |
||
3824 | if (this.obj.getParentId(id) != parent) { |
||
3825 | this.obj.moveItem(id, 'item_child', parent); |
||
3826 | } |
||
3827 | this.setUpdated(id, true, 'updated'); |
||
3828 | }); |
||
3829 | |||
3830 | dp.attachEvent("deleteCallback", function(upd, id, parent) { |
||
3831 | this.obj.setUserData(id, this.action_param, "true_deleted"); |
||
3832 | this.obj.deleteItem(id, false); |
||
3833 | }); |
||
3834 | |||
3835 | dp._methods=["setItemStyle","","changeItemId","deleteItem"]; |
||
3836 | this.attachEvent("onEdit",function(state,id){ |
||
3837 | if (state==3) |
||
3838 | dp.setUpdated(id,true) |
||
3839 | return true; |
||
3840 | }); |
||
3841 | this.attachEvent("onDrop",function(id,id_2,id_3,tree_1,tree_2){ |
||
3842 | if (tree_1==tree_2) |
||
3843 | dp.setUpdated(id,true); |
||
3844 | }); |
||
3845 | this._onrdlh=function(rowId){ |
||
3846 | var z=dp.getState(rowId); |
||
3847 | if (z=="inserted") { dp.set_invalid(rowId,false); dp.setUpdated(rowId,false); return true; } |
||
3848 | if (z=="true_deleted") { dp.setUpdated(rowId,false); return true; } |
||
3849 | |||
3850 | dp.setUpdated(rowId,true,"deleted") |
||
3851 | return false; |
||
3852 | }; |
||
3853 | this._onradh=function(rowId){ |
||
3854 | dp.setUpdated(rowId,true,"inserted") |
||
3855 | }; |
||
3856 | dp._getRowData=function(rowId){ |
||
3857 | var data = {}; |
||
3858 | var z=this.obj._globalIdStorageFind(rowId); |
||
3859 | var z2=z.parentObject; |
||
3860 | |||
3861 | var i=0; |
||
3862 | for (i=0; i<z2.childsCount; i++) |
||
3863 | if (z2.childNodes[i]==z) break; |
||
3864 | |||
3865 | data["tr_id"] = z.id; |
||
3866 | data["tr_pid"] = z2.id; |
||
3867 | data["tr_order"] = i; |
||
3868 | data["tr_text"] = z.span.innerHTML; |
||
3869 | |||
3870 | z2=(z._userdatalist||"").split(","); |
||
3871 | for (i=0; i<z2.length; i++) |
||
3872 | data[z2[i]]=z.userData["t_"+z2[i]]; |
||
3873 | |||
3874 | return data; |
||
3875 | }; |
||
3876 | }; |
||
3877 | |||
3878 | //(c)dhtmlx ltd. www.dhtmlx.com |
||