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