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

« back to all changes in this revision

Viewing changes to gis/dhis-gis-geostat/mfbase/ext/source/widgets/WindowManager.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.WindowGroup
 
11
 * An object that represents a group of {@link Ext.Window} instances and provides z-order management
 
12
 * and window activation behavior.
 
13
 * @constructor
 
14
 */
 
15
Ext.WindowGroup = function(){
 
16
    var list = {};
 
17
    var accessList = [];
 
18
    var front = null;
 
19
 
 
20
    // private
 
21
    var sortWindows = function(d1, d2){
 
22
        return (!d1._lastAccess || d1._lastAccess < d2._lastAccess) ? -1 : 1;
 
23
    };
 
24
 
 
25
    // private
 
26
    var orderWindows = function(){
 
27
        var a = accessList, len = a.length;
 
28
        if(len > 0){
 
29
            a.sort(sortWindows);
 
30
            var seed = a[0].manager.zseed;
 
31
            for(var i = 0; i < len; i++){
 
32
                var win = a[i];
 
33
                if(win && !win.hidden){
 
34
                    win.setZIndex(seed + (i*10));
 
35
                }
 
36
            }
 
37
        }
 
38
        activateLast();
 
39
    };
 
40
 
 
41
    // private
 
42
    var setActiveWin = function(win){
 
43
        if(win != front){
 
44
            if(front){
 
45
                front.setActive(false);
 
46
            }
 
47
            front = win;
 
48
            if(win){
 
49
                win.setActive(true);
 
50
            }
 
51
        }
 
52
    };
 
53
 
 
54
    // private
 
55
    var activateLast = function(){
 
56
        for(var i = accessList.length-1; i >=0; --i) {
 
57
            if(!accessList[i].hidden){
 
58
                setActiveWin(accessList[i]);
 
59
                return;
 
60
            }
 
61
        }
 
62
        // none to activate
 
63
        setActiveWin(null);
 
64
    };
 
65
 
 
66
    return {
 
67
        /**
 
68
         * The starting z-index for windows (defaults to 9000)
 
69
         * @type Number The z-index value
 
70
         */
 
71
        zseed : 9000,
 
72
 
 
73
        // private
 
74
        register : function(win){
 
75
            list[win.id] = win;
 
76
            accessList.push(win);
 
77
            win.on('hide', activateLast);
 
78
        },
 
79
 
 
80
        // private
 
81
        unregister : function(win){
 
82
            delete list[win.id];
 
83
            win.un('hide', activateLast);
 
84
            accessList.remove(win);
 
85
        },
 
86
 
 
87
        /**
 
88
         * Gets a registered window by id.
 
89
         * @param {String/Object} id The id of the window or a {@link Ext.Window} instance
 
90
         * @return {Ext.Window}
 
91
         */
 
92
        get : function(id){
 
93
            return typeof id == "object" ? id : list[id];
 
94
        },
 
95
 
 
96
        /**
 
97
         * Brings the specified window to the front of any other active windows.
 
98
         * @param {String/Object} win The id of the window or a {@link Ext.Window} instance
 
99
         * @return {Boolean} True if the dialog was brought to the front, else false
 
100
         * if it was already in front
 
101
         */
 
102
        bringToFront : function(win){
 
103
            win = this.get(win);
 
104
            if(win != front){
 
105
                win._lastAccess = new Date().getTime();
 
106
                orderWindows();
 
107
                return true;
 
108
            }
 
109
            return false;
 
110
        },
 
111
 
 
112
        /**
 
113
         * Sends the specified window to the back of other active windows.
 
114
         * @param {String/Object} win The id of the window or a {@link Ext.Window} instance
 
115
         * @return {Ext.Window} The window
 
116
         */
 
117
        sendToBack : function(win){
 
118
            win = this.get(win);
 
119
            win._lastAccess = -(new Date().getTime());
 
120
            orderWindows();
 
121
            return win;
 
122
        },
 
123
 
 
124
        /**
 
125
         * Hides all windows in the group.
 
126
         */
 
127
        hideAll : function(){
 
128
            for(var id in list){
 
129
                if(list[id] && typeof list[id] != "function" && list[id].isVisible()){
 
130
                    list[id].hide();
 
131
                }
 
132
            }
 
133
        },
 
134
 
 
135
        /**
 
136
         * Gets the currently-active window in the group.
 
137
         * @return {Ext.Window} The active window
 
138
         */
 
139
        getActive : function(){
 
140
            return front;
 
141
        },
 
142
 
 
143
        /**
 
144
         * Returns zero or more windows in the group using the custom search function passed to this method.
 
145
         * The function should accept a single {@link Ext.Window} reference as its only argument and should
 
146
         * return true if the window matches the search criteria, otherwise it should return false.
 
147
         * @param {Function} fn The search function
 
148
         * @param {Object} scope (optional) The scope in which to execute the function (defaults to the window
 
149
         * that gets passed to the function if not specified)
 
150
         * @return {Array} An array of zero or more matching windows
 
151
         */
 
152
        getBy : function(fn, scope){
 
153
            var r = [];
 
154
            for(var i = accessList.length-1; i >=0; --i) {
 
155
                var win = accessList[i];
 
156
                if(fn.call(scope||win, win) !== false){
 
157
                    r.push(win);
 
158
                }
 
159
            }
 
160
            return r;
 
161
        },
 
162
 
 
163
        /**
 
164
         * Executes the specified function once for every window in the group, passing each
 
165
         * window as the only parameter. Returning false from the function will stop the iteration.
 
166
         * @param {Function} fn The function to execute for each item
 
167
         * @param {Object} scope (optional) The scope in which to execute the function
 
168
         */
 
169
        each : function(fn, scope){
 
170
            for(var id in list){
 
171
                if(list[id] && typeof list[id] != "function"){
 
172
                    if(fn.call(scope || list[id], list[id]) === false){
 
173
                        return;
 
174
                    }
 
175
                }
 
176
            }
 
177
        }
 
178
    };
 
179
};
 
180
 
 
181
 
 
182
/**
 
183
 * @class Ext.WindowMgr
 
184
 * @extends Ext.WindowGroup
 
185
 * The default global window group that is available automatically.  To have more than one group of windows
 
186
 * with separate z-order stacks, create additional instances of {@link Ext.WindowGroup} as needed.
 
187
 * @singleton
 
188
 */
 
189
Ext.WindowMgr = new Ext.WindowGroup();
 
 
b'\\ No newline at end of file'