3 * Copyright(c) 2006-2010 Sencha Inc.
5 * http://www.sencha.com/license
8 * @class Ext.tree.AsyncTreeNode
9 * @extends Ext.tree.TreeNode
10 * @cfg {TreeLoader} loader A TreeLoader to be used by this node (defaults to the loader defined on the tree)
12 * @param {Object/String} attributes The attributes/config for the node or just a string with the text for the node
14 Ext.tree.AsyncTreeNode = function(config){
15 this.loaded = config && config.loaded === true;
17 Ext.tree.AsyncTreeNode.superclass.constructor.apply(this, arguments);
20 * Fires before this node is loaded, return false to cancel
21 * @param {Node} this This node
23 this.addEvents('beforeload', 'load');
26 * Fires when this node is loaded
27 * @param {Node} this This node
30 * The loader used by this node (defaults to using the tree's defined loader)
35 Ext.extend(Ext.tree.AsyncTreeNode, Ext.tree.TreeNode, {
36 expand : function(deep, anim, callback, scope){
37 if(this.loading){ // if an async load is already running, waiting til it's done
40 if(!this.loading){ // done loading
42 this.expand(deep, anim, callback, scope);
44 }.createDelegate(this);
45 timer = setInterval(f, 200);
49 if(this.fireEvent("beforeload", this) === false){
53 this.ui.beforeLoad(this);
54 var loader = this.loader || this.attributes.loader || this.getOwnerTree().getLoader();
56 loader.load(this, this.loadComplete.createDelegate(this, [deep, anim, callback, scope]), this);
60 Ext.tree.AsyncTreeNode.superclass.expand.call(this, deep, anim, callback, scope);
64 * Returns true if this node is currently loading
67 isLoading : function(){
71 loadComplete : function(deep, anim, callback, scope){
74 this.ui.afterLoad(this);
75 this.fireEvent("load", this);
76 this.expand(deep, anim, callback, scope);
80 * Returns true if this node has been loaded
83 isLoaded : function(){
87 hasChildNodes : function(){
88 if(!this.isLeaf() && !this.loaded){
91 return Ext.tree.AsyncTreeNode.superclass.hasChildNodes.call(this);
96 * Trigger a reload for this node
97 * @param {Function} callback
98 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to this Node.
100 reload : function(callback, scope){
101 this.collapse(false, false);
102 while(this.firstChild){
103 this.removeChild(this.firstChild).destroy();
105 this.childrenRendered = false;
107 if(this.isHiddenRoot()){
108 this.expanded = false;
110 this.expand(false, false, callback, scope);
114 Ext.tree.TreePanel.nodeTypes.async = Ext.tree.AsyncTreeNode;