3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js"><div id="cls-Ext.tree.TreeNode"></div>/**
\r
9 * @class Ext.tree.TreeNode
\r
10 * @extends Ext.data.Node
\r
11 * @cfg {String} text The text for this node
\r
12 * @cfg {Boolean} expanded true to start the node expanded
\r
13 * @cfg {Boolean} allowDrag False to make this node undraggable if {@link #draggable} = true (defaults to true)
\r
14 * @cfg {Boolean} allowDrop False if this node cannot have child nodes dropped on it (defaults to true)
\r
15 * @cfg {Boolean} disabled true to start the node disabled
\r
16 * @cfg {String} icon The path to an icon for the node. The preferred way to do this
\r
17 * is to use the cls or iconCls attributes and add the icon via a CSS background image.
\r
18 * @cfg {String} cls A css class to be added to the node
\r
19 * @cfg {String} iconCls A css class to be added to the nodes icon element for applying css background images
\r
20 * @cfg {String} href URL of the link used for the node (defaults to #)
\r
21 * @cfg {String} hrefTarget target frame for the link
\r
22 * @cfg {Boolean} hidden True to render hidden. (Defaults to false).
\r
23 * @cfg {String} qtip An Ext QuickTip for the node
\r
24 * @cfg {Boolean} expandable If set to true, the node will always show a plus/minus icon, even when empty
\r
25 * @cfg {String} qtipCfg An Ext QuickTip config for the node (used instead of qtip)
\r
26 * @cfg {Boolean} singleClickExpand True for single click expand on this node
\r
27 * @cfg {Function} uiProvider A UI <b>class</b> to use for this node (defaults to Ext.tree.TreeNodeUI)
\r
28 * @cfg {Boolean} checked True to render a checked checkbox for this node, false to render an unchecked checkbox
\r
29 * (defaults to undefined with no checkbox rendered)
\r
30 * @cfg {Boolean} draggable True to make this node draggable (defaults to false)
\r
31 * @cfg {Boolean} isTarget False to not allow this node to act as a drop target (defaults to true)
\r
32 * @cfg {Boolean} allowChildren False to not allow this node to have child nodes (defaults to true)
\r
33 * @cfg {Boolean} editable False to not allow this node to be edited by an (@link Ext.tree.TreeEditor} (defaults to true)
\r
35 * @param {Object/String} attributes The attributes/config for the node or just a string with the text for the node
\r
37 Ext.tree.TreeNode = function(attributes){
\r
38 attributes = attributes || {};
\r
39 if(typeof attributes == "string"){
\r
40 attributes = {text: attributes};
\r
42 this.childrenRendered = false;
\r
43 this.rendered = false;
\r
44 Ext.tree.TreeNode.superclass.constructor.call(this, attributes);
\r
45 this.expanded = attributes.expanded === true;
\r
46 this.isTarget = attributes.isTarget !== false;
\r
47 this.draggable = attributes.draggable !== false && attributes.allowDrag !== false;
\r
48 this.allowChildren = attributes.allowChildren !== false && attributes.allowDrop !== false;
\r
51 * Read-only. The text for this node. To change it use setText().
\r
54 this.text = attributes.text;
\r
56 * True if this node is disabled.
\r
59 this.disabled = attributes.disabled === true;
\r
61 * True if this node is hidden.
\r
64 this.hidden = attributes.hidden === true;
\r
69 * Fires when the text for this node is changed
\r
70 * @param {Node} this This node
\r
71 * @param {String} text The new text
\r
72 * @param {String} oldText The old text
\r
76 * @event beforeexpand
\r
77 * Fires before this node is expanded, return false to cancel.
\r
78 * @param {Node} this This node
\r
79 * @param {Boolean} deep
\r
80 * @param {Boolean} anim
\r
84 * @event beforecollapse
\r
85 * Fires before this node is collapsed, return false to cancel.
\r
86 * @param {Node} this This node
\r
87 * @param {Boolean} deep
\r
88 * @param {Boolean} anim
\r
93 * Fires when this node is expanded
\r
94 * @param {Node} this This node
\r
98 * @event disabledchange
\r
99 * Fires when the disabled status of this node changes
\r
100 * @param {Node} this This node
\r
101 * @param {Boolean} disabled
\r
106 * Fires when this node is collapsed
\r
107 * @param {Node} this This node
\r
111 * @event beforeclick
\r
112 * Fires before click processing. Return false to cancel the default action.
\r
113 * @param {Node} this This node
\r
114 * @param {Ext.EventObject} e The event object
\r
119 * Fires when this node is clicked
\r
120 * @param {Node} this This node
\r
121 * @param {Ext.EventObject} e The event object
\r
125 * @event checkchange
\r
126 * Fires when a node with a checkbox's checked property changes
\r
127 * @param {Node} this This node
\r
128 * @param {Boolean} checked
\r
133 * Fires when this node is double clicked
\r
134 * @param {Node} this This node
\r
135 * @param {Ext.EventObject} e The event object
\r
139 * @event contextmenu
\r
140 * Fires when this node is right clicked
\r
141 * @param {Node} this This node
\r
142 * @param {Ext.EventObject} e The event object
\r
146 * @event beforechildrenrendered
\r
147 * Fires right before the child nodes for this node are rendered
\r
148 * @param {Node} this This node
\r
150 "beforechildrenrendered"
\r
153 var uiClass = this.attributes.uiProvider || this.defaultUI || Ext.tree.TreeNodeUI;
\r
156 * Read-only. The UI for this node
\r
159 this.ui = new uiClass(this);
\r
161 Ext.extend(Ext.tree.TreeNode, Ext.data.Node, {
\r
162 preventHScroll: true,
\r
164 * Returns true if this node is expanded
\r
165 * @return {Boolean}
\r
167 isExpanded : function(){
\r
168 return this.expanded;
\r
172 * Returns the UI object for this node.
\r
173 * @return {TreeNodeUI} The object which is providing the user interface for this tree
\r
174 * node. Unless otherwise specified in the {@link #uiProvider}, this will be an instance
\r
175 * of {@link Ext.tree.TreeNodeUI}
\r
177 getUI : function(){
\r
181 getLoader : function(){
\r
183 return this.loader || ((owner = this.getOwnerTree()) && owner.loader ? owner.loader : new Ext.tree.TreeLoader());
\r
186 // private override
\r
187 setFirstChild : function(node){
\r
188 var of = this.firstChild;
\r
189 Ext.tree.TreeNode.superclass.setFirstChild.call(this, node);
\r
190 if(this.childrenRendered && of && node != of){
\r
191 of.renderIndent(true, true);
\r
194 this.renderIndent(true, true);
\r
198 // private override
\r
199 setLastChild : function(node){
\r
200 var ol = this.lastChild;
\r
201 Ext.tree.TreeNode.superclass.setLastChild.call(this, node);
\r
202 if(this.childrenRendered && ol && node != ol){
\r
203 ol.renderIndent(true, true);
\r
206 this.renderIndent(true, true);
\r
210 // these methods are overridden to provide lazy rendering support
\r
211 // private override
\r
212 appendChild : function(n){
\r
213 if(!n.render && !Ext.isArray(n)){
\r
214 n = this.getLoader().createNode(n);
\r
216 var node = Ext.tree.TreeNode.superclass.appendChild.call(this, n);
\r
217 if(node && this.childrenRendered){
\r
220 this.ui.updateExpandIcon();
\r
224 // private override
\r
225 removeChild : function(node){
\r
226 this.ownerTree.getSelectionModel().unselect(node);
\r
227 Ext.tree.TreeNode.superclass.removeChild.apply(this, arguments);
\r
228 // if it's been rendered remove dom node
\r
229 if(this.childrenRendered){
\r
232 if(this.childNodes.length < 1){
\r
233 this.collapse(false, false);
\r
235 this.ui.updateExpandIcon();
\r
237 if(!this.firstChild && !this.isHiddenRoot()) {
\r
238 this.childrenRendered = false;
\r
243 // private override
\r
244 insertBefore : function(node, refNode){
\r
246 node = this.getLoader().createNode(node);
\r
248 var newNode = Ext.tree.TreeNode.superclass.insertBefore.call(this, node, refNode);
\r
249 if(newNode && refNode && this.childrenRendered){
\r
252 this.ui.updateExpandIcon();
\r
257 * Sets the text for this node
\r
258 * @param {String} text
\r
260 setText : function(text){
\r
261 var oldText = this.text;
\r
263 this.attributes.text = text;
\r
264 if(this.rendered){ // event without subscribing
\r
265 this.ui.onTextChange(this, text, oldText);
\r
267 this.fireEvent("textchange", this, text, oldText);
\r
271 * Triggers selection of this node
\r
273 select : function(){
\r
274 this.getOwnerTree().getSelectionModel().select(this);
\r
278 * Triggers deselection of this node
\r
280 unselect : function(){
\r
281 this.getOwnerTree().getSelectionModel().unselect(this);
\r
285 * Returns true if this node is selected
\r
286 * @return {Boolean}
\r
288 isSelected : function(){
\r
289 return this.getOwnerTree().getSelectionModel().isSelected(this);
\r
293 * Expand this node.
\r
294 * @param {Boolean} deep (optional) True to expand all children as well
\r
295 * @param {Boolean} anim (optional) false to cancel the default animation
\r
296 * @param {Function} callback (optional) A callback to be called when
\r
297 * expanding this node completes (does not wait for deep expand to complete).
\r
298 * Called with 1 parameter, this node.
\r
299 * @param {Object} scope (optional) The scope in which to execute the callback.
\r
301 expand : function(deep, anim, callback, scope){
\r
302 if(!this.expanded){
\r
303 if(this.fireEvent("beforeexpand", this, deep, anim) === false){
\r
306 if(!this.childrenRendered){
\r
307 this.renderChildren();
\r
309 this.expanded = true;
\r
310 if(!this.isHiddenRoot() && (this.getOwnerTree().animate && anim !== false) || anim){
\r
311 this.ui.animExpand(function(){
\r
312 this.fireEvent("expand", this);
\r
313 this.runCallback(callback, scope || this, [this]);
\r
315 this.expandChildNodes(true);
\r
317 }.createDelegate(this));
\r
321 this.fireEvent("expand", this);
\r
322 this.runCallback(callback, scope || this, [this]);
\r
325 this.runCallback(callback, scope || this, [this]);
\r
328 this.expandChildNodes(true);
\r
332 runCallback: function(cb, scope, args){
\r
333 if(Ext.isFunction(cb)){
\r
334 cb.apply(scope, args);
\r
338 isHiddenRoot : function(){
\r
339 return this.isRoot && !this.getOwnerTree().rootVisible;
\r
343 * Collapse this node.
\r
344 * @param {Boolean} deep (optional) True to collapse all children as well
\r
345 * @param {Boolean} anim (optional) false to cancel the default animation
\r
346 * @param {Function} callback (optional) A callback to be called when
\r
347 * expanding this node completes (does not wait for deep expand to complete).
\r
348 * Called with 1 parameter, this node.
\r
349 * @param {Object} scope (optional) The scope in which to execute the callback.
\r
351 collapse : function(deep, anim, callback, scope){
\r
352 if(this.expanded && !this.isHiddenRoot()){
\r
353 if(this.fireEvent("beforecollapse", this, deep, anim) === false){
\r
356 this.expanded = false;
\r
357 if((this.getOwnerTree().animate && anim !== false) || anim){
\r
358 this.ui.animCollapse(function(){
\r
359 this.fireEvent("collapse", this);
\r
360 this.runCallback(callback, scope || this, [this]);
\r
362 this.collapseChildNodes(true);
\r
364 }.createDelegate(this));
\r
367 this.ui.collapse();
\r
368 this.fireEvent("collapse", this);
\r
369 this.runCallback(callback, scope || this, [this]);
\r
371 }else if(!this.expanded){
\r
372 this.runCallback(callback, scope || this, [this]);
\r
375 var cs = this.childNodes;
\r
376 for(var i = 0, len = cs.length; i < len; i++) {
\r
377 cs[i].collapse(true, false);
\r
383 delayedExpand : function(delay){
\r
384 if(!this.expandProcId){
\r
385 this.expandProcId = this.expand.defer(delay, this);
\r
390 cancelExpand : function(){
\r
391 if(this.expandProcId){
\r
392 clearTimeout(this.expandProcId);
\r
394 this.expandProcId = false;
\r
398 * Toggles expanded/collapsed state of the node
\r
400 toggle : function(){
\r
409 * Ensures all parent nodes are expanded, and if necessary, scrolls
\r
410 * the node into view.
\r
411 * @param {Function} callback (optional) A function to call when the node has been made visible.
\r
412 * @param {Object} scope (optional) The scope in which to execute the callback.
\r
414 ensureVisible : function(callback, scope){
\r
415 var tree = this.getOwnerTree();
\r
416 tree.expandPath(this.parentNode ? this.parentNode.getPath() : this.getPath(), false, function(){
\r
417 var node = tree.getNodeById(this.id); // Somehow if we don't do this, we lose changes that happened to node in the meantime
\r
418 tree.getTreeEl().scrollChildIntoView(node.ui.anchor);
\r
419 this.runCallback(callback, scope || this, [this]);
\r
420 }.createDelegate(this));
\r
424 * Expand all child nodes
\r
425 * @param {Boolean} deep (optional) true if the child nodes should also expand their child nodes
\r
427 expandChildNodes : function(deep){
\r
428 var cs = this.childNodes;
\r
429 for(var i = 0, len = cs.length; i < len; i++) {
\r
430 cs[i].expand(deep);
\r
435 * Collapse all child nodes
\r
436 * @param {Boolean} deep (optional) true if the child nodes should also collapse their child nodes
\r
438 collapseChildNodes : function(deep){
\r
439 var cs = this.childNodes;
\r
440 for(var i = 0, len = cs.length; i < len; i++) {
\r
441 cs[i].collapse(deep);
\r
446 * Disables this node
\r
448 disable : function(){
\r
449 this.disabled = true;
\r
451 if(this.rendered && this.ui.onDisableChange){ // event without subscribing
\r
452 this.ui.onDisableChange(this, true);
\r
454 this.fireEvent("disabledchange", this, true);
\r
458 * Enables this node
\r
460 enable : function(){
\r
461 this.disabled = false;
\r
462 if(this.rendered && this.ui.onDisableChange){ // event without subscribing
\r
463 this.ui.onDisableChange(this, false);
\r
465 this.fireEvent("disabledchange", this, false);
\r
469 renderChildren : function(suppressEvent){
\r
470 if(suppressEvent !== false){
\r
471 this.fireEvent("beforechildrenrendered", this);
\r
473 var cs = this.childNodes;
\r
474 for(var i = 0, len = cs.length; i < len; i++){
\r
475 cs[i].render(true);
\r
477 this.childrenRendered = true;
\r
481 sort : function(fn, scope){
\r
482 Ext.tree.TreeNode.superclass.sort.apply(this, arguments);
\r
483 if(this.childrenRendered){
\r
484 var cs = this.childNodes;
\r
485 for(var i = 0, len = cs.length; i < len; i++){
\r
486 cs[i].render(true);
\r
492 render : function(bulkRender){
\r
493 this.ui.render(bulkRender);
\r
494 if(!this.rendered){
\r
495 // make sure it is registered
\r
496 this.getOwnerTree().registerNode(this);
\r
497 this.rendered = true;
\r
499 this.expanded = false;
\r
500 this.expand(false, false);
\r
506 renderIndent : function(deep, refresh){
\r
508 this.ui.childIndent = null;
\r
510 this.ui.renderIndent();
\r
511 if(deep === true && this.childrenRendered){
\r
512 var cs = this.childNodes;
\r
513 for(var i = 0, len = cs.length; i < len; i++){
\r
514 cs[i].renderIndent(true, refresh);
\r
519 beginUpdate : function(){
\r
520 this.childrenRendered = false;
\r
523 endUpdate : function(){
\r
524 if(this.expanded && this.rendered){
\r
525 this.renderChildren();
\r
529 destroy : function(){
\r
530 if(this.childNodes){
\r
531 for(var i = 0,l = this.childNodes.length; i < l; i++){
\r
532 this.childNodes[i].destroy();
\r
534 this.childNodes = null;
\r
536 if(this.ui.destroy){
\r
542 onIdChange: function(id){
\r
543 this.ui.onIdChange(id);
\r
547 Ext.tree.TreePanel.nodeTypes.node = Ext.tree.TreeNode;</pre>
\r