~mortenoh/+junk/dhis2-detailed-import-export

« back to all changes in this revision

Viewing changes to gis/dhis-gis-geostat/mfbase/ext/source/widgets/tree/AsyncTreeNode.js

  • Committer: larshelge at gmail
  • Date: 2009-03-03 16:46:36 UTC
  • Revision ID: larshelge@gmail.com-20090303164636-2sjlrquo7ib1gf7r
Initial check-in

Show diffs side-by-side

added added

removed removed

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