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