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