1
<html><head><title>TreeNode.js</title><link rel="stylesheet" type="text/css" href="../resources/style.css" media="screen"/></head><body><h1>TreeNode.js</h1><pre class="highlighted"><code><i>/**
2
* @class Ext.tree.TreeNode
3
* @extends Ext.data.Node
4
* @cfg {String} text The text <b>for</b> this node
5
* @cfg {Boolean} expanded true to start the node expanded
6
* @cfg {Boolean} allowDrag False to make <b>this</b> node undraggable <b>if</b> {@link #draggable} = true (defaults to true)
7
* @cfg {Boolean} allowDrop False <b>if</b> this node cannot have child nodes dropped on it (defaults to true)
8
* @cfg {Boolean} disabled true to start the node disabled
9
* @cfg {String} icon The path to an icon <b>for</b> the node. The preferred way to <b>do</b> this
10
* is to use the cls or iconCls attributes and add the icon via a CSS background image.
11
* @cfg {String} cls A css class to be added to the node
12
* @cfg {String} iconCls A css class to be added to the nodes icon element <b>for</b> applying css background images
13
* @cfg {String} href URL of the link used <b>for</b> the node (defaults to #)
14
* @cfg {String} hrefTarget target frame <b>for</b> the link
15
* @cfg {Boolean} hidden True to render hidden. (Defaults to false).
16
* @cfg {String} qtip An Ext QuickTip <b>for</b> the node
17
* @cfg {Boolean} expandable If set to true, the node will always show a plus/minus icon, even when empty
18
* @cfg {String} qtipCfg An Ext QuickTip config <b>for</b> the node (used instead of qtip)
19
* @cfg {Boolean} singleClickExpand True <b>for</b> single click expand on <b>this</b> node
20
* @cfg {Function} uiProvider A UI <b>class</b> to use <b>for</b> this node (defaults to Ext.tree.TreeNodeUI)
21
* @cfg {Boolean} checked True to render a checked checkbox <b>for</b> this node, false to render an unchecked checkbox
22
* (defaults to undefined <b>with</b> no checkbox rendered)
23
* @cfg {Boolean} draggable True to make <b>this</b> node draggable (defaults to false)
24
* @cfg {Boolean} isTarget False to not allow <b>this</b> node to act as a drop target (defaults to true)
25
* @cfg {Boolean} allowChildren False to not allow <b>this</b> node to have child nodes (defaults to true)
26
* @cfg {Boolean} editable False to not allow <b>this</b> node to be edited by an (@link Ext.tree.TreeEditor} (defaults to true)
28
* @param {Object/String} attributes The attributes/config <b>for</b> the node or just a string <b>with</b> the text <b>for</b> the node
30
Ext.tree.TreeNode = <b>function</b>(attributes){
31
attributes = attributes || {};
32
<b>if</b>(typeof attributes == "string"){
33
attributes = {text: attributes};
35
<b>this</b>.childrenRendered = false;
36
<b>this</b>.rendered = false;
37
Ext.tree.TreeNode.superclass.constructor.call(<b>this</b>, attributes);
38
<b>this</b>.expanded = attributes.expanded === true;
39
<b>this</b>.isTarget = attributes.isTarget !== false;
40
<b>this</b>.draggable = attributes.draggable !== false && attributes.allowDrag !== false;
41
<b>this</b>.allowChildren = attributes.allowChildren !== false && attributes.allowDrop !== false;
44
* Read-only. The text <b>for</b> this node. To change it use setText().
47
<b>this</b>.text = attributes.text;
49
* True <b>if</b> this node is disabled.
52
<b>this</b>.disabled = attributes.disabled === true;
54
* True <b>if</b> this node is hidden.
57
<b>this</b>.hidden = attributes.hidden === true;
59
<b>this</b>.addEvents(
62
* Fires when the text <b>for</b> this node is changed
63
* @param {Node} <b>this</b> This node
64
* @param {String} text The <b>new</b> text
65
* @param {String} oldText The old text
67
"textchange",
70
* Fires before <b>this</b> node is expanded, <b>return</b> false to cancel.
71
* @param {Node} <b>this</b> This node
72
* @param {Boolean} deep
73
* @param {Boolean} anim
75
"beforeexpand",
77
* @event beforecollapse
78
* Fires before <b>this</b> node is collapsed, <b>return</b> false to cancel.
79
* @param {Node} <b>this</b> This node
80
* @param {Boolean} deep
81
* @param {Boolean} anim
83
"beforecollapse",
86
* Fires when <b>this</b> node is expanded
87
* @param {Node} <b>this</b> This node
91
* @event disabledchange
92
* Fires when the disabled status of <b>this</b> node changes
93
* @param {Node} <b>this</b> This node
94
* @param {Boolean} disabled
96
"disabledchange",
99
* Fires when <b>this</b> node is collapsed
100
* @param {Node} <b>this</b> This node
102
"collapse",
105
* Fires before click processing. Return false to cancel the <b>default</b> action.
106
* @param {Node} <b>this</b> This node
107
* @param {Ext.EventObject} e The event object
109
"beforeclick",
112
* Fires when <b>this</b> node is clicked
113
* @param {Node} <b>this</b> This node
114
* @param {Ext.EventObject} e The event object
119
* Fires when a node <b>with</b> a checkbox's checked property changes
120
* @param {Node} <b>this</b> This node
121
* @param {Boolean} checked
123
"checkchange",
126
* Fires when <b>this</b> node is double clicked
127
* @param {Node} <b>this</b> This node
128
* @param {Ext.EventObject} e The event object
130
"dblclick",
133
* Fires when <b>this</b> node is right clicked
134
* @param {Node} <b>this</b> This node
135
* @param {Ext.EventObject} e The event object
137
"contextmenu",
139
* @event beforechildrenrendered
140
* Fires right before the child nodes <b>for</b> this node are rendered
141
* @param {Node} <b>this</b> This node
143
"beforechildrenrendered"
146
<b>var</b> uiClass = <b>this</b>.attributes.uiProvider || <b>this</b>.defaultUI || Ext.tree.TreeNodeUI;
149
* Read-only. The UI <b>for</b> this node
152
<b>this</b>.ui = <b>new</b> uiClass(<b>this</b>);
154
Ext.extend(Ext.tree.TreeNode, Ext.data.Node, {
155
preventHScroll: true,
157
* Returns true <b>if</b> this node is expanded
158
* @<b>return</b> {Boolean}
160
isExpanded : <b>function</b>(){
161
<b>return</b> this.expanded;
165
* Returns the UI object <b>for</b> this node.
166
* @<b>return</b> {TreeNodeUI} The object which is providing the user interface <b>for</b> this tree
167
* node. Unless otherwise specified <b>in</b> the {@link #uiProvider}, <b>this</b> will be an instance
168
* of {@link Ext.tree.TreeNodeUI}
170
getUI : <b>function</b>(){
171
<b>return</b> this.ui;
174
getLoader : <b>function</b>(){
176
<b>return</b> this.loader || ((owner = <b>this</b>.getOwnerTree()) && owner.loader ? owner.loader : <b>new</b> Ext.tree.TreeLoader());
179
<i>// private override</i>
180
setFirstChild : <b>function</b>(node){
181
<b>var</b> of = <b>this</b>.firstChild;
182
Ext.tree.TreeNode.superclass.setFirstChild.call(<b>this</b>, node);
183
<b>if</b>(this.childrenRendered && of && node != of){
184
of.renderIndent(true, true);
186
<b>if</b>(this.rendered){
187
<b>this</b>.renderIndent(true, true);
191
<i>// private override</i>
192
setLastChild : <b>function</b>(node){
193
<b>var</b> ol = <b>this</b>.lastChild;
194
Ext.tree.TreeNode.superclass.setLastChild.call(<b>this</b>, node);
195
<b>if</b>(this.childrenRendered && ol && node != ol){
196
ol.renderIndent(true, true);
198
<b>if</b>(this.rendered){
199
<b>this</b>.renderIndent(true, true);
203
<i>// these methods are overridden to provide lazy rendering support</i>
204
<i>// private override</i>
205
appendChild : <b>function</b>(n){
206
<b>if</b>(!n.render && !Ext.isArray(n)){
207
n = <b>this</b>.getLoader().createNode(n);
209
<b>var</b> node = Ext.tree.TreeNode.superclass.appendChild.call(<b>this</b>, n);
210
<b>if</b>(node && <b>this</b>.childrenRendered){
213
<b>this</b>.ui.updateExpandIcon();
217
<i>// private override</i>
218
removeChild : <b>function</b>(node){
219
<b>this</b>.ownerTree.getSelectionModel().unselect(node);
220
Ext.tree.TreeNode.superclass.removeChild.apply(<b>this</b>, arguments);
221
<i>// <b>if</b> it's been rendered remove dom node</i>
222
<b>if</b>(this.childrenRendered){
225
<b>if</b>(this.childNodes.length < 1){
226
<b>this</b>.collapse(false, false);
228
<b>this</b>.ui.updateExpandIcon();
230
<b>if</b>(!<b>this</b>.firstChild && !<b>this</b>.isHiddenRoot()) {
231
<b>this</b>.childrenRendered = false;
236
<i>// private override</i>
237
insertBefore : <b>function</b>(node, refNode){
238
<b>if</b>(!node.render){
239
node = <b>this</b>.getLoader().createNode(node);
241
<b>var</b> newNode = Ext.tree.TreeNode.superclass.insertBefore.apply(<b>this</b>, arguments);
242
<b>if</b>(newNode && refNode && <b>this</b>.childrenRendered){
245
<b>this</b>.ui.updateExpandIcon();
246
<b>return</b> newNode;
250
* Sets the text <b>for</b> this node
251
* @param {String} text
253
setText : <b>function</b>(text){
254
<b>var</b> oldText = <b>this</b>.text;
255
<b>this</b>.text = text;
256
<b>this</b>.attributes.text = text;
257
<b>if</b>(this.rendered){ <i>// event without subscribing</i>
258
<b>this</b>.ui.onTextChange(<b>this</b>, text, oldText);
260
<b>this</b>.fireEvent("textchange", <b>this</b>, text, oldText);
264
* Triggers selection of <b>this</b> node
266
select : <b>function</b>(){
267
<b>this</b>.getOwnerTree().getSelectionModel().select(<b>this</b>);
271
* Triggers deselection of <b>this</b> node
273
unselect : <b>function</b>(){
274
<b>this</b>.getOwnerTree().getSelectionModel().unselect(<b>this</b>);
278
* Returns true <b>if</b> this node is selected
279
* @<b>return</b> {Boolean}
281
isSelected : <b>function</b>(){
282
<b>return</b> this.getOwnerTree().getSelectionModel().isSelected(<b>this</b>);
286
* Expand <b>this</b> node.
287
* @param {Boolean} deep (optional) True to expand all children as well
288
* @param {Boolean} anim (optional) false to cancel the <b>default</b> animation
289
* @param {Function} callback (optional) A callback to be called when
290
* expanding <b>this</b> node completes (does not wait <b>for</b> deep expand to complete).
291
* Called <b>with</b> 1 parameter, <b>this</b> node.
293
expand : <b>function</b>(deep, anim, callback){
294
<b>if</b>(!<b>this</b>.expanded){
295
<b>if</b>(this.fireEvent("beforeexpand", <b>this</b>, deep, anim) === false){
298
<b>if</b>(!<b>this</b>.childrenRendered){
299
<b>this</b>.renderChildren();
301
<b>this</b>.expanded = true;
302
<b>if</b>(!<b>this</b>.isHiddenRoot() && (<b>this</b>.getOwnerTree().animate && anim !== false) || anim){
303
<b>this</b>.ui.animExpand(<b>function</b>(){
304
<b>this</b>.fireEvent("expand", <b>this</b>);
305
<b>if</b>(typeof callback == "<b>function</b>"){
306
callback(<b>this</b>);
308
<b>if</b>(deep === true){
309
<b>this</b>.expandChildNodes(true);
311
}.createDelegate(<b>this</b>));
314
<b>this</b>.ui.expand();
315
<b>this</b>.fireEvent("expand", <b>this</b>);
316
<b>if</b>(typeof callback == "<b>function</b>"){
317
callback(<b>this</b>);
321
<b>if</b>(typeof callback == "<b>function</b>"){
322
callback(<b>this</b>);
325
<b>if</b>(deep === true){
326
<b>this</b>.expandChildNodes(true);
330
isHiddenRoot : <b>function</b>(){
331
<b>return</b> this.isRoot && !<b>this</b>.getOwnerTree().rootVisible;
335
* Collapse <b>this</b> node.
336
* @param {Boolean} deep (optional) True to collapse all children as well
337
* @param {Boolean} anim (optional) false to cancel the <b>default</b> animation
339
collapse : <b>function</b>(deep, anim){
340
<b>if</b>(this.expanded && !<b>this</b>.isHiddenRoot()){
341
<b>if</b>(this.fireEvent("beforecollapse", <b>this</b>, deep, anim) === false){
344
<b>this</b>.expanded = false;
345
<b>if</b>((<b>this</b>.getOwnerTree().animate && anim !== false) || anim){
346
<b>this</b>.ui.animCollapse(<b>function</b>(){
347
<b>this</b>.fireEvent("collapse", <b>this</b>);
348
<b>if</b>(deep === true){
349
<b>this</b>.collapseChildNodes(true);
351
}.createDelegate(<b>this</b>));
354
<b>this</b>.ui.collapse();
355
<b>this</b>.fireEvent("collapse", <b>this</b>);
358
<b>if</b>(deep === true){
359
<b>var</b> cs = <b>this</b>.childNodes;
360
<b>for</b>(var i = 0, len = cs.length; i < len; i++) {
361
cs[i].collapse(true, false);
367
delayedExpand : <b>function</b>(delay){
368
<b>if</b>(!<b>this</b>.expandProcId){
369
<b>this</b>.expandProcId = <b>this</b>.expand.defer(delay, <b>this</b>);
374
cancelExpand : <b>function</b>(){
375
<b>if</b>(this.expandProcId){
376
clearTimeout(<b>this</b>.expandProcId);
378
<b>this</b>.expandProcId = false;
382
* Toggles expanded/collapsed state of the node
384
toggle : <b>function</b>(){
385
<b>if</b>(this.expanded){
386
<b>this</b>.collapse();
388
<b>this</b>.expand();
393
* Ensures all parent nodes are expanded, and <b>if</b> necessary, scrolls
394
* the node into view.
395
* @param {Function} callback (optional) A <b>function</b> to call when the node has been made visible.
397
ensureVisible : <b>function</b>(callback){
398
<b>var</b> tree = <b>this</b>.getOwnerTree();
399
tree.expandPath(<b>this</b>.parentNode ? <b>this</b>.parentNode.getPath() : <b>this</b>.getPath(), false, <b>function</b>(){
400
<b>var</b> node = tree.getNodeById(<b>this</b>.id); <i>// Somehow <b>if</b> we don't <b>do</b> this, we lose changes that happened to node <b>in</b> the meantime</i>
401
tree.getTreeEl().scrollChildIntoView(node.ui.anchor);
402
Ext.callback(callback);
403
}.createDelegate(<b>this</b>));
407
* Expand all child nodes
408
* @param {Boolean} deep (optional) true <b>if</b> the child nodes should also expand their child nodes
410
expandChildNodes : <b>function</b>(deep){
411
<b>var</b> cs = <b>this</b>.childNodes;
412
<b>for</b>(var i = 0, len = cs.length; i < len; i++) {
418
* Collapse all child nodes
419
* @param {Boolean} deep (optional) true <b>if</b> the child nodes should also collapse their child nodes
421
collapseChildNodes : <b>function</b>(deep){
422
<b>var</b> cs = <b>this</b>.childNodes;
423
<b>for</b>(var i = 0, len = cs.length; i < len; i++) {
424
cs[i].collapse(deep);
429
* Disables <b>this</b> node
431
disable : <b>function</b>(){
432
<b>this</b>.disabled = true;
433
<b>this</b>.unselect();
434
<b>if</b>(this.rendered && <b>this</b>.ui.onDisableChange){ <i>// event without subscribing</i>
435
<b>this</b>.ui.onDisableChange(<b>this</b>, true);
437
<b>this</b>.fireEvent("disabledchange", <b>this</b>, true);
441
* Enables <b>this</b> node
443
enable : <b>function</b>(){
444
<b>this</b>.disabled = false;
445
<b>if</b>(this.rendered && <b>this</b>.ui.onDisableChange){ <i>// event without subscribing</i>
446
<b>this</b>.ui.onDisableChange(<b>this</b>, false);
448
<b>this</b>.fireEvent("disabledchange", <b>this</b>, false);
452
renderChildren : <b>function</b>(suppressEvent){
453
<b>if</b>(suppressEvent !== false){
454
<b>this</b>.fireEvent("beforechildrenrendered", <b>this</b>);
456
<b>var</b> cs = <b>this</b>.childNodes;
457
<b>for</b>(var i = 0, len = cs.length; i < len; i++){
460
<b>this</b>.childrenRendered = true;
464
sort : <b>function</b>(fn, scope){
465
Ext.tree.TreeNode.superclass.sort.apply(<b>this</b>, arguments);
466
<b>if</b>(this.childrenRendered){
467
<b>var</b> cs = <b>this</b>.childNodes;
468
<b>for</b>(var i = 0, len = cs.length; i < len; i++){
475
render : <b>function</b>(bulkRender){
476
<b>this</b>.ui.render(bulkRender);
477
<b>if</b>(!<b>this</b>.rendered){
478
<i>// make sure it is registered</i>
479
<b>this</b>.getOwnerTree().registerNode(<b>this</b>);
480
<b>this</b>.rendered = true;
481
<b>if</b>(this.expanded){
482
<b>this</b>.expanded = false;
483
<b>this</b>.expand(false, false);
489
renderIndent : <b>function</b>(deep, refresh){
491
<b>this</b>.ui.childIndent = null;
493
<b>this</b>.ui.renderIndent();
494
<b>if</b>(deep === true && <b>this</b>.childrenRendered){
495
<b>var</b> cs = <b>this</b>.childNodes;
496
<b>for</b>(var i = 0, len = cs.length; i < len; i++){
497
cs[i].renderIndent(true, refresh);
502
beginUpdate : <b>function</b>(){
503
<b>this</b>.childrenRendered = false;
506
endUpdate : <b>function</b>(){
507
<b>if</b>(this.expanded && <b>this</b>.rendered){
508
<b>this</b>.renderChildren();
512
destroy : <b>function</b>(){
513
<b>if</b>(this.childNodes){
514
<b>for</b>(var i = 0,l = <b>this</b>.childNodes.length; i < l; i++){
515
<b>this</b>.childNodes[i].destroy();
517
<b>this</b>.childNodes = null;
519
<b>if</b>(this.ui.destroy){
520
<b>this</b>.ui.destroy();
525
Ext.tree.TreePanel.nodeTypes.node = Ext.tree.TreeNode;</code></pre><hr><div style="font-size:10px;text-align:center;color:gray;">Ext - Copyright © 2006-2007 Ext JS, LLC<br />All rights reserved.</div>
b'\\ No newline at end of file'