3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
\r
4 <title>The source code</title>
\r
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
8 <body onload="prettyPrint();">
\r
9 <pre class="prettyprint lang-js"><div id="cls-Ext.tree.TreeNode"></div>/**
\r
10 * @class Ext.tree.TreeNode
\r
11 * @extends Ext.data.Node
\r
12 * @cfg {String} text The text for this node
\r
13 * @cfg {Boolean} expanded true to start the node expanded
\r
14 * @cfg {Boolean} allowDrag False to make this node undraggable if {@link #draggable} = true (defaults to true)
\r
15 * @cfg {Boolean} allowDrop False if this node cannot have child nodes dropped on it (defaults to true)
\r
16 * @cfg {Boolean} disabled true to start the node disabled
\r
17 * @cfg {String} icon The path to an icon for the node. The preferred way to do this
\r
18 * is to use the cls or iconCls attributes and add the icon via a CSS background image.
\r
19 * @cfg {String} cls A css class to be added to the node
\r
20 * @cfg {String} iconCls A css class to be added to the nodes icon element for applying css background images
\r
21 * @cfg {String} href URL of the link used for the node (defaults to #)
\r
22 * @cfg {String} hrefTarget target frame for the link
\r
23 * @cfg {Boolean} hidden True to render hidden. (Defaults to false).
\r
24 * @cfg {String} qtip An Ext QuickTip for the node
\r
25 * @cfg {Boolean} expandable If set to true, the node will always show a plus/minus icon, even when empty
\r
26 * @cfg {String} qtipCfg An Ext QuickTip config for the node (used instead of qtip)
\r
27 * @cfg {Boolean} singleClickExpand True for single click expand on this node
\r
28 * @cfg {Function} uiProvider A UI <b>class</b> to use for this node (defaults to Ext.tree.TreeNodeUI)
\r
29 * @cfg {Boolean} checked True to render a checked checkbox for this node, false to render an unchecked checkbox
\r
30 * (defaults to undefined with no checkbox rendered)
\r
31 * @cfg {Boolean} draggable True to make this node draggable (defaults to false)
\r
32 * @cfg {Boolean} isTarget False to not allow this node to act as a drop target (defaults to true)
\r
33 * @cfg {Boolean} allowChildren False to not allow this node to have child nodes (defaults to true)
\r
34 * @cfg {Boolean} editable False to not allow this node to be edited by an {@link Ext.tree.TreeEditor} (defaults to true)
\r
36 * @param {Object/String} attributes The attributes/config for the node or just a string with the text for the node
\r
38 Ext.tree.TreeNode = function(attributes){
\r
39 attributes = attributes || {};
\r
40 if(Ext.isString(attributes)){
\r
41 attributes = {text: attributes};
\r
43 this.childrenRendered = false;
\r
44 this.rendered = false;
\r
45 Ext.tree.TreeNode.superclass.constructor.call(this, attributes);
\r
46 this.expanded = attributes.expanded === true;
\r
47 this.isTarget = attributes.isTarget !== false;
\r
48 this.draggable = attributes.draggable !== false && attributes.allowDrag !== false;
\r
49 this.allowChildren = attributes.allowChildren !== false && attributes.allowDrop !== false;
\r
52 * Read-only. The text for this node. To change it use <code>{@link #setText}</code>.
\r
55 this.text = attributes.text;
\r
57 * True if this node is disabled.
\r
60 this.disabled = attributes.disabled === true;
\r
62 * True if this node is hidden.
\r
65 this.hidden = attributes.hidden === true;
\r
70 * Fires when the text for this node is changed
\r
71 * @param {Node} this This node
\r
72 * @param {String} text The new text
\r
73 * @param {String} oldText The old text
\r
77 * @event beforeexpand
\r
78 * Fires before this node is expanded, return false to cancel.
\r
79 * @param {Node} this This node
\r
80 * @param {Boolean} deep
\r
81 * @param {Boolean} anim
\r
85 * @event beforecollapse
\r
86 * Fires before this node is collapsed, return false to cancel.
\r
87 * @param {Node} this This node
\r
88 * @param {Boolean} deep
\r
89 * @param {Boolean} anim
\r
94 * Fires when this node is expanded
\r
95 * @param {Node} this This node
\r
99 * @event disabledchange
\r
100 * Fires when the disabled status of this node changes
\r
101 * @param {Node} this This node
\r
102 * @param {Boolean} disabled
\r
107 * Fires when this node is collapsed
\r
108 * @param {Node} this This node
\r
112 * @event beforeclick
\r
113 * Fires before click processing. Return false to cancel the default action.
\r
114 * @param {Node} this This node
\r
115 * @param {Ext.EventObject} e The event object
\r
120 * Fires when this node is clicked
\r
121 * @param {Node} this This node
\r
122 * @param {Ext.EventObject} e The event object
\r
126 * @event checkchange
\r
127 * Fires when a node with a checkbox's checked property changes
\r
128 * @param {Node} this This node
\r
129 * @param {Boolean} checked
\r
133 * @event beforedblclick
\r
134 * Fires before double click processing. Return false to cancel the default action.
\r
135 * @param {Node} this This node
\r
136 * @param {Ext.EventObject} e The event object
\r
141 * Fires when this node is double clicked
\r
142 * @param {Node} this This node
\r
143 * @param {Ext.EventObject} e The event object
\r
147 * @event contextmenu
\r
148 * Fires when this node is right clicked
\r
149 * @param {Node} this This node
\r
150 * @param {Ext.EventObject} e The event object
\r
154 * @event beforechildrenrendered
\r
155 * Fires right before the child nodes for this node are rendered
\r
156 * @param {Node} this This node
\r
158 'beforechildrenrendered'
\r
161 var uiClass = this.attributes.uiProvider || this.defaultUI || Ext.tree.TreeNodeUI;
\r
164 * Read-only. The UI for this node
\r
167 this.ui = new uiClass(this);
\r
169 Ext.extend(Ext.tree.TreeNode, Ext.data.Node, {
\r
170 preventHScroll : true,
\r
172 * Returns true if this node is expanded
\r
173 * @return {Boolean}
\r
175 isExpanded : function(){
\r
176 return this.expanded;
\r
180 * Returns the UI object for this node.
\r
181 * @return {TreeNodeUI} The object which is providing the user interface for this tree
\r
182 * node. Unless otherwise specified in the {@link #uiProvider}, this will be an instance
\r
183 * of {@link Ext.tree.TreeNodeUI}
\r
185 getUI : function(){
\r
189 getLoader : function(){
\r
191 return this.loader || ((owner = this.getOwnerTree()) && owner.loader ? owner.loader : (this.loader = new Ext.tree.TreeLoader()));
\r
194 // private override
\r
195 setFirstChild : function(node){
\r
196 var of = this.firstChild;
\r
197 Ext.tree.TreeNode.superclass.setFirstChild.call(this, node);
\r
198 if(this.childrenRendered && of && node != of){
\r
199 of.renderIndent(true, true);
\r
202 this.renderIndent(true, true);
\r
206 // private override
\r
207 setLastChild : function(node){
\r
208 var ol = this.lastChild;
\r
209 Ext.tree.TreeNode.superclass.setLastChild.call(this, node);
\r
210 if(this.childrenRendered && ol && node != ol){
\r
211 ol.renderIndent(true, true);
\r
214 this.renderIndent(true, true);
\r
218 // these methods are overridden to provide lazy rendering support
\r
219 // private override
\r
220 appendChild : function(n){
\r
221 if(!n.render && !Ext.isArray(n)){
\r
222 n = this.getLoader().createNode(n);
\r
224 var node = Ext.tree.TreeNode.superclass.appendChild.call(this, n);
\r
225 if(node && this.childrenRendered){
\r
228 this.ui.updateExpandIcon();
\r
232 // private override
\r
233 removeChild : function(node, destroy){
\r
234 this.ownerTree.getSelectionModel().unselect(node);
\r
235 Ext.tree.TreeNode.superclass.removeChild.apply(this, arguments);
\r
236 // if it's been rendered remove dom node
\r
237 if(node.ui.rendered){
\r
240 if(this.childNodes.length < 1){
\r
241 this.collapse(false, false);
\r
243 this.ui.updateExpandIcon();
\r
245 if(!this.firstChild && !this.isHiddenRoot()) {
\r
246 this.childrenRendered = false;
\r
251 // private override
\r
252 insertBefore : function(node, refNode){
\r
254 node = this.getLoader().createNode(node);
\r
256 var newNode = Ext.tree.TreeNode.superclass.insertBefore.call(this, node, refNode);
\r
257 if(newNode && refNode && this.childrenRendered){
\r
260 this.ui.updateExpandIcon();
\r
265 * Sets the text for this node
\r
266 * @param {String} text
\r
268 setText : function(text){
\r
269 var oldText = this.text;
\r
270 this.text = this.attributes.text = text;
\r
271 if(this.rendered){ // event without subscribing
\r
272 this.ui.onTextChange(this, text, oldText);
\r
274 this.fireEvent('textchange', this, text, oldText);
\r
278 * Triggers selection of this node
\r
280 select : function(){
\r
281 var t = this.getOwnerTree();
\r
283 t.getSelectionModel().select(this);
\r
288 * Triggers deselection of this node
\r
289 * @param {Boolean} silent (optional) True to stop selection change events from firing.
\r
291 unselect : function(silent){
\r
292 var t = this.getOwnerTree();
\r
294 t.getSelectionModel().unselect(this, silent);
\r
299 * Returns true if this node is selected
\r
300 * @return {Boolean}
\r
302 isSelected : function(){
\r
303 var t = this.getOwnerTree();
\r
304 return t ? t.getSelectionModel().isSelected(this) : false;
\r
308 * Expand this node.
\r
309 * @param {Boolean} deep (optional) True to expand all children as well
\r
310 * @param {Boolean} anim (optional) false to cancel the default animation
\r
311 * @param {Function} callback (optional) A callback to be called when
\r
312 * expanding this node completes (does not wait for deep expand to complete).
\r
313 * Called with 1 parameter, this node.
\r
314 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to this TreeNode.
\r
316 expand : function(deep, anim, callback, scope){
\r
317 if(!this.expanded){
\r
318 if(this.fireEvent('beforeexpand', this, deep, anim) === false){
\r
321 if(!this.childrenRendered){
\r
322 this.renderChildren();
\r
324 this.expanded = true;
\r
325 if(!this.isHiddenRoot() && (this.getOwnerTree().animate && anim !== false) || anim){
\r
326 this.ui.animExpand(function(){
\r
327 this.fireEvent('expand', this);
\r
328 this.runCallback(callback, scope || this, [this]);
\r
330 this.expandChildNodes(true);
\r
332 }.createDelegate(this));
\r
336 this.fireEvent('expand', this);
\r
337 this.runCallback(callback, scope || this, [this]);
\r
340 this.runCallback(callback, scope || this, [this]);
\r
343 this.expandChildNodes(true);
\r
347 runCallback : function(cb, scope, args){
\r
348 if(Ext.isFunction(cb)){
\r
349 cb.apply(scope, args);
\r
353 isHiddenRoot : function(){
\r
354 return this.isRoot && !this.getOwnerTree().rootVisible;
\r
358 * Collapse this node.
\r
359 * @param {Boolean} deep (optional) True to collapse all children as well
\r
360 * @param {Boolean} anim (optional) false to cancel the default animation
\r
361 * @param {Function} callback (optional) A callback to be called when
\r
362 * expanding this node completes (does not wait for deep expand to complete).
\r
363 * Called with 1 parameter, this node.
\r
364 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to this TreeNode.
\r
366 collapse : function(deep, anim, callback, scope){
\r
367 if(this.expanded && !this.isHiddenRoot()){
\r
368 if(this.fireEvent('beforecollapse', this, deep, anim) === false){
\r
371 this.expanded = false;
\r
372 if((this.getOwnerTree().animate && anim !== false) || anim){
\r
373 this.ui.animCollapse(function(){
\r
374 this.fireEvent('collapse', this);
\r
375 this.runCallback(callback, scope || this, [this]);
\r
377 this.collapseChildNodes(true);
\r
379 }.createDelegate(this));
\r
382 this.ui.collapse();
\r
383 this.fireEvent('collapse', this);
\r
384 this.runCallback(callback, scope || this, [this]);
\r
386 }else if(!this.expanded){
\r
387 this.runCallback(callback, scope || this, [this]);
\r
390 var cs = this.childNodes;
\r
391 for(var i = 0, len = cs.length; i < len; i++) {
\r
392 cs[i].collapse(true, false);
\r
398 delayedExpand : function(delay){
\r
399 if(!this.expandProcId){
\r
400 this.expandProcId = this.expand.defer(delay, this);
\r
405 cancelExpand : function(){
\r
406 if(this.expandProcId){
\r
407 clearTimeout(this.expandProcId);
\r
409 this.expandProcId = false;
\r
413 * Toggles expanded/collapsed state of the node
\r
415 toggle : function(){
\r
424 * Ensures all parent nodes are expanded, and if necessary, scrolls
\r
425 * the node into view.
\r
426 * @param {Function} callback (optional) A function to call when the node has been made visible.
\r
427 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to this TreeNode.
\r
429 ensureVisible : function(callback, scope){
\r
430 var tree = this.getOwnerTree();
\r
431 tree.expandPath(this.parentNode ? this.parentNode.getPath() : this.getPath(), false, function(){
\r
432 var node = tree.getNodeById(this.id); // Somehow if we don't do this, we lose changes that happened to node in the meantime
\r
433 tree.getTreeEl().scrollChildIntoView(node.ui.anchor);
\r
434 this.runCallback(callback, scope || this, [this]);
\r
435 }.createDelegate(this));
\r
439 * Expand all child nodes
\r
440 * @param {Boolean} deep (optional) true if the child nodes should also expand their child nodes
\r
442 expandChildNodes : function(deep){
\r
443 var cs = this.childNodes;
\r
444 for(var i = 0, len = cs.length; i < len; i++) {
\r
445 cs[i].expand(deep);
\r
450 * Collapse all child nodes
\r
451 * @param {Boolean} deep (optional) true if the child nodes should also collapse their child nodes
\r
453 collapseChildNodes : function(deep){
\r
454 var cs = this.childNodes;
\r
455 for(var i = 0, len = cs.length; i < len; i++) {
\r
456 cs[i].collapse(deep);
\r
461 * Disables this node
\r
463 disable : function(){
\r
464 this.disabled = true;
\r
466 if(this.rendered && this.ui.onDisableChange){ // event without subscribing
\r
467 this.ui.onDisableChange(this, true);
\r
469 this.fireEvent('disabledchange', this, true);
\r
473 * Enables this node
\r
475 enable : function(){
\r
476 this.disabled = false;
\r
477 if(this.rendered && this.ui.onDisableChange){ // event without subscribing
\r
478 this.ui.onDisableChange(this, false);
\r
480 this.fireEvent('disabledchange', this, false);
\r
484 renderChildren : function(suppressEvent){
\r
485 if(suppressEvent !== false){
\r
486 this.fireEvent('beforechildrenrendered', this);
\r
488 var cs = this.childNodes;
\r
489 for(var i = 0, len = cs.length; i < len; i++){
\r
490 cs[i].render(true);
\r
492 this.childrenRendered = true;
\r
496 sort : function(fn, scope){
\r
497 Ext.tree.TreeNode.superclass.sort.apply(this, arguments);
\r
498 if(this.childrenRendered){
\r
499 var cs = this.childNodes;
\r
500 for(var i = 0, len = cs.length; i < len; i++){
\r
501 cs[i].render(true);
\r
507 render : function(bulkRender){
\r
508 this.ui.render(bulkRender);
\r
509 if(!this.rendered){
\r
510 // make sure it is registered
\r
511 this.getOwnerTree().registerNode(this);
\r
512 this.rendered = true;
\r
514 this.expanded = false;
\r
515 this.expand(false, false);
\r
521 renderIndent : function(deep, refresh){
\r
523 this.ui.childIndent = null;
\r
525 this.ui.renderIndent();
\r
526 if(deep === true && this.childrenRendered){
\r
527 var cs = this.childNodes;
\r
528 for(var i = 0, len = cs.length; i < len; i++){
\r
529 cs[i].renderIndent(true, refresh);
\r
534 beginUpdate : function(){
\r
535 this.childrenRendered = false;
\r
538 endUpdate : function(){
\r
539 if(this.expanded && this.rendered){
\r
540 this.renderChildren();
\r
544 destroy : function(){
\r
545 this.unselect(true);
\r
546 Ext.tree.TreeNode.superclass.destroy.call(this);
\r
547 Ext.destroy(this.ui, this.loader);
\r
548 this.ui = this.loader = null;
\r
552 onIdChange : function(id){
\r
553 this.ui.onIdChange(id);
\r
557 Ext.tree.TreePanel.nodeTypes.node = Ext.tree.TreeNode;</pre>
\r