Upgrade to ExtJS 3.2.1 - Released 04/27/2010
[extjs.git] / docs / source / AsyncTreeNode.html
1 <html>
2 <head>
3   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    
4   <title>The source code</title>
5     <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6     <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
7 </head>
8 <body  onload="prettyPrint();">
9     <pre class="prettyprint lang-js">/*!
10  * Ext JS Library 3.2.1
11  * Copyright(c) 2006-2010 Ext JS, Inc.
12  * licensing@extjs.com
13  * http://www.extjs.com/license
14  */
15 <div id="cls-Ext.tree.AsyncTreeNode"></div>/**
16  * @class Ext.tree.AsyncTreeNode
17  * @extends Ext.tree.TreeNode
18  * @cfg {TreeLoader} loader A TreeLoader to be used by this node (defaults to the loader defined on the tree)
19  * @constructor
20  * @param {Object/String} attributes The attributes/config for the node or just a string with the text for the node 
21  */
22  Ext.tree.AsyncTreeNode = function(config){
23     this.loaded = config && config.loaded === true;
24     this.loading = false;
25     Ext.tree.AsyncTreeNode.superclass.constructor.apply(this, arguments);
26     /**
27     * @event beforeload
28     * Fires before this node is loaded, return false to cancel
29     * @param {Node} this This node
30     */
31     this.addEvents('beforeload', 'load');
32     /**
33     * @event load
34     * Fires when this node is loaded
35     * @param {Node} this This node
36     */
37     /**
38      * The loader used by this node (defaults to using the tree's defined loader)
39      * @type TreeLoader
40      * @property loader
41      */
42 };
43 Ext.extend(Ext.tree.AsyncTreeNode, Ext.tree.TreeNode, {
44     expand : function(deep, anim, callback, scope){
45         if(this.loading){ // if an async load is already running, waiting til it's done
46             var timer;
47             var f = function(){
48                 if(!this.loading){ // done loading
49                     clearInterval(timer);
50                     this.expand(deep, anim, callback, scope);
51                 }
52             }.createDelegate(this);
53             timer = setInterval(f, 200);
54             return;
55         }
56         if(!this.loaded){
57             if(this.fireEvent("beforeload", this) === false){
58                 return;
59             }
60             this.loading = true;
61             this.ui.beforeLoad(this);
62             var loader = this.loader || this.attributes.loader || this.getOwnerTree().getLoader();
63             if(loader){
64                 loader.load(this, this.loadComplete.createDelegate(this, [deep, anim, callback, scope]), this);
65                 return;
66             }
67         }
68         Ext.tree.AsyncTreeNode.superclass.expand.call(this, deep, anim, callback, scope);
69     },
70     
71     /**
72      * Returns true if this node is currently loading
73      * @return {Boolean}
74      */
75     isLoading : function(){
76         return this.loading;  
77     },
78     
79     loadComplete : function(deep, anim, callback, scope){
80         this.loading = false;
81         this.loaded = true;
82         this.ui.afterLoad(this);
83         this.fireEvent("load", this);
84         this.expand(deep, anim, callback, scope);
85     },
86     
87     /**
88      * Returns true if this node has been loaded
89      * @return {Boolean}
90      */
91     isLoaded : function(){
92         return this.loaded;
93     },
94     
95     hasChildNodes : function(){
96         if(!this.isLeaf() && !this.loaded){
97             return true;
98         }else{
99             return Ext.tree.AsyncTreeNode.superclass.hasChildNodes.call(this);
100         }
101     },
102
103     /**
104      * Trigger a reload for this node
105      * @param {Function} callback
106      * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to this Node.
107      */
108     reload : function(callback, scope){
109         this.collapse(false, false);
110         while(this.firstChild){
111             this.removeChild(this.firstChild).destroy();
112         }
113         this.childrenRendered = false;
114         this.loaded = false;
115         if(this.isHiddenRoot()){
116             this.expanded = false;
117         }
118         this.expand(false, false, callback, scope);
119     }
120 });
121
122 Ext.tree.TreePanel.nodeTypes.async = Ext.tree.AsyncTreeNode;</pre>    
123 </body>
124 </html>