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>
7 <body onload="prettyPrint();">
8 <pre class="prettyprint lang-js">/*!
10 * Copyright(c) 2006-2009 Ext JS, LLC
12 * http://www.extjs.com/license
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
19 * @param {Object/String} attributes The attributes/config for the node or just a string with the text for the node
\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
27 * Fires before this node is loaded, return false to cancel
\r
28 * @param {Node} this This node
\r
30 this.addEvents('beforeload', 'load');
\r
33 * Fires when this node is loaded
\r
34 * @param {Node} this This node
\r
37 * The loader used by this node (defaults to using the tree's defined loader)
\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
47 if(!this.loading){ // done loading
\r
48 clearInterval(timer);
\r
49 this.expand(deep, anim, callback, scope);
\r
51 }.createDelegate(this);
\r
52 timer = setInterval(f, 200);
\r
56 if(this.fireEvent("beforeload", this) === false){
\r
59 this.loading = true;
\r
60 this.ui.beforeLoad(this);
\r
61 var loader = this.loader || this.attributes.loader || this.getOwnerTree().getLoader();
\r
63 loader.load(this, this.loadComplete.createDelegate(this, [deep, anim, callback, scope]), this);
\r
67 Ext.tree.AsyncTreeNode.superclass.expand.call(this, deep, anim, callback, scope);
\r
71 * Returns true if this node is currently loading
\r
74 isLoading : function(){
\r
75 return this.loading;
\r
78 loadComplete : function(deep, anim, callback, scope){
\r
79 this.loading = false;
\r
81 this.ui.afterLoad(this);
\r
82 this.fireEvent("load", this);
\r
83 this.expand(deep, anim, callback, scope);
\r
87 * Returns true if this node has been loaded
\r
90 isLoaded : function(){
\r
94 hasChildNodes : function(){
\r
95 if(!this.isLeaf() && !this.loaded){
\r
98 return Ext.tree.AsyncTreeNode.superclass.hasChildNodes.call(this);
\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
107 reload : function(callback, scope){
\r
108 this.collapse(false, false);
\r
109 while(this.firstChild){
\r
110 this.removeChild(this.firstChild).destroy();
\r
112 this.childrenRendered = false;
\r
113 this.loaded = false;
\r
114 if(this.isHiddenRoot()){
\r
115 this.expanded = false;
\r
117 this.expand(false, false, callback, scope);
\r
121 Ext.tree.TreePanel.nodeTypes.async = Ext.tree.AsyncTreeNode;</pre>