2 * Ext JS Library 2.2.1
\r
3 * Copyright(c) 2006-2009, Ext JS, LLC.
\r
4 * licensing@extjs.com
\r
6 * http://extjs.com/license
\r
10 * @class Ext.tree.AsyncTreeNode
\r
11 * @extends Ext.tree.TreeNode
\r
12 * @cfg {TreeLoader} loader A TreeLoader to be used by this node (defaults to the loader defined on the tree)
\r
14 * @param {Object/String} attributes The attributes/config for the node or just a string with the text for the node
\r
16 Ext.tree.AsyncTreeNode = function(config){
\r
17 this.loaded = config && config.loaded === true;
\r
18 this.loading = false;
\r
19 Ext.tree.AsyncTreeNode.superclass.constructor.apply(this, arguments);
\r
22 * Fires before this node is loaded, return false to cancel
\r
23 * @param {Node} this This node
\r
25 this.addEvents('beforeload', 'load');
\r
28 * Fires when this node is loaded
\r
29 * @param {Node} this This node
\r
32 * The loader used by this node (defaults to using the tree's defined loader)
\r
37 Ext.extend(Ext.tree.AsyncTreeNode, Ext.tree.TreeNode, {
\r
38 expand : function(deep, anim, callback){
\r
39 if(this.loading){ // if an async load is already running, waiting til it's done
\r
42 if(!this.loading){ // done loading
\r
43 clearInterval(timer);
\r
44 this.expand(deep, anim, callback);
\r
46 }.createDelegate(this);
\r
47 timer = setInterval(f, 200);
\r
51 if(this.fireEvent("beforeload", this) === false){
\r
54 this.loading = true;
\r
55 this.ui.beforeLoad(this);
\r
56 var loader = this.loader || this.attributes.loader || this.getOwnerTree().getLoader();
\r
58 loader.load(this, this.loadComplete.createDelegate(this, [deep, anim, callback]));
\r
62 Ext.tree.AsyncTreeNode.superclass.expand.call(this, deep, anim, callback);
\r
66 * Returns true if this node is currently loading
\r
69 isLoading : function(){
\r
70 return this.loading;
\r
73 loadComplete : function(deep, anim, callback){
\r
74 this.loading = false;
\r
76 this.ui.afterLoad(this);
\r
77 this.fireEvent("load", this);
\r
78 this.expand(deep, anim, callback);
\r
82 * Returns true if this node has been loaded
\r
85 isLoaded : function(){
\r
89 hasChildNodes : function(){
\r
90 if(!this.isLeaf() && !this.loaded){
\r
93 return Ext.tree.AsyncTreeNode.superclass.hasChildNodes.call(this);
\r
98 * Trigger a reload for this node
\r
99 * @param {Function} callback
\r
101 reload : function(callback){
\r
102 this.collapse(false, false);
\r
103 while(this.firstChild){
\r
104 this.removeChild(this.firstChild).destroy();
\r
106 this.childrenRendered = false;
\r
107 this.loaded = false;
\r
108 if(this.isHiddenRoot()){
\r
109 this.expanded = false;
\r
111 this.expand(false, false, callback);
\r
115 Ext.tree.TreePanel.nodeTypes.async = Ext.tree.AsyncTreeNode;