/* * Based on: * Ext JS Library 1.1.1 * Copyright(c) 2006-2007, Ext JS, LLC. * * Originally Released Under LGPL - original licence link has changed is not relivant. * * Fork - LGPL * <script type="text/javascript"> */ /** * @class Roo.tree.AsyncTreeNode * @extends Roo.tree.TreeNode * @cfg {TreeLoader} loader A TreeLoader to be used by this node (defaults to the loader defined on the tree) * @constructor * @param {Object/String} attributes The attributes/config for the node or just a string with the text for the node */ Roo.tree.AsyncTreeNode = function(config){ this.loaded = false; this.loading = false; Roo.tree.AsyncTreeNode.superclass.constructor.apply(this, arguments); /** * @event beforeload * Fires before this node is loaded, return false to cancel * @param {Node} this This node */ this.addEvents({'beforeload':true, 'load': true}); /** * @event load * Fires when this node is loaded * @param {Node} this This node */ /** * The loader used by this node (defaults to using the tree's defined loader) * @type TreeLoader * @property loader */ }; Roo.extend(Roo.tree.AsyncTreeNode, Roo.tree.TreeNode, { expand : function(deep, anim, callback){ if(this.loading){ // if an async load is already running, waiting til it's done var timer; var f = function(){ if(!this.loading){ // done loading clearInterval(timer); this.expand(deep, anim, callback); } }.createDelegate(this); timer = setInterval(f, 200); return; } if(!this.loaded){ if(this.fireEvent("beforeload", this) === false){ return; } this.loading = true; this.ui.beforeLoad(this); var loader = this.loader || this.attributes.loader || this.getOwnerTree().getLoader(); if(loader){ loader.load(this, this.loadComplete.createDelegate(this, [deep, anim, callback])); return; } } Roo.tree.AsyncTreeNode.superclass.expand.call(this, deep, anim, callback); }, /** * Returns true if this node is currently loading * @return {Boolean} */ isLoading : function(){ return this.loading; }, loadComplete : function(deep, anim, callback){ this.loading = false; this.loaded = true; this.ui.afterLoad(this); this.fireEvent("load", this); this.expand(deep, anim, callback); }, /** * Returns true if this node has been loaded * @return {Boolean} */ isLoaded : function(){ return this.loaded; }, hasChildNodes : function(){ if(!this.isLeaf() && !this.loaded){ return true; }else{ return Roo.tree.AsyncTreeNode.superclass.hasChildNodes.call(this); } }, /** * Trigger a reload for this node * @param {Function} callback */ reload : function(callback){ this.collapse(false, false); while(this.firstChild){ this.removeChild(this.firstChild); } this.childrenRendered = false; this.loaded = false; if(this.isHiddenRoot()){ this.expanded = false; } this.expand(false, false, callback); } });