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