~zubairassad89/sahana-eden/vms_gsoc

« back to all changes in this revision

Viewing changes to static/mfbase/ext/source/legacy/layout/BasicLayoutRegion.js

  • Committer: Fran Boon
  • Date: 2008-12-09 22:35:23 UTC
  • Revision ID: flavour@partyvibe.com-20081209223523-fcs5k95jjk0uqo0z
Initial import of work done so far

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Ext JS Library 2.0.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.BasicLayoutRegion
 
11
 * @extends Ext.util.Observable
 
12
 * This class represents a lightweight region in a layout manager. This region does not move dom nodes
 
13
 * and does not have a titlebar, tabs or any other features. All it does is size and position 
 
14
 * panels. To create a BasicLayoutRegion, add lightweight:true or basic:true to your regions config.
 
15
 */
 
16
Ext.BasicLayoutRegion = function(mgr, config, pos, skipConfig){
 
17
    this.mgr = mgr;
 
18
    this.position  = pos;
 
19
    this.events = {
 
20
        /**
 
21
         * @event beforeremove
 
22
         * Fires before a panel is removed (or closed). To cancel the removal set "e.cancel = true" on the event argument.
 
23
         * @param {Ext.LayoutRegion} this
 
24
         * @param {Ext.ContentPanel} panel The panel
 
25
         * @param {Object} e The cancel event object
 
26
         */
 
27
        "beforeremove" : true,
 
28
        /**
 
29
         * @event invalidated
 
30
         * Fires when the layout for this region is changed.
 
31
         * @param {Ext.LayoutRegion} this
 
32
         */
 
33
        "invalidated" : true,
 
34
        /**
 
35
         * @event visibilitychange
 
36
         * Fires when this region is shown or hidden 
 
37
         * @param {Ext.LayoutRegion} this
 
38
         * @param {Boolean} visibility true or false
 
39
         */
 
40
        "visibilitychange" : true,
 
41
        /**
 
42
         * @event paneladded
 
43
         * Fires when a panel is added. 
 
44
         * @param {Ext.LayoutRegion} this
 
45
         * @param {Ext.ContentPanel} panel The panel
 
46
         */
 
47
        "paneladded" : true,
 
48
        /**
 
49
         * @event panelremoved
 
50
         * Fires when a panel is removed. 
 
51
         * @param {Ext.LayoutRegion} this
 
52
         * @param {Ext.ContentPanel} panel The panel
 
53
         */
 
54
        "panelremoved" : true,
 
55
        /**
 
56
         * @event collapsed
 
57
         * Fires when this region is collapsed.
 
58
         * @param {Ext.LayoutRegion} this
 
59
         */
 
60
        "collapsed" : true,
 
61
        /**
 
62
         * @event expanded
 
63
         * Fires when this region is expanded.
 
64
         * @param {Ext.LayoutRegion} this
 
65
         */
 
66
        "expanded" : true,
 
67
        /**
 
68
         * @event slideshow
 
69
         * Fires when this region is slid into view.
 
70
         * @param {Ext.LayoutRegion} this
 
71
         */
 
72
        "slideshow" : true,
 
73
        /**
 
74
         * @event slidehide
 
75
         * Fires when this region slides out of view. 
 
76
         * @param {Ext.LayoutRegion} this
 
77
         */
 
78
        "slidehide" : true,
 
79
        /**
 
80
         * @event panelactivated
 
81
         * Fires when a panel is activated. 
 
82
         * @param {Ext.LayoutRegion} this
 
83
         * @param {Ext.ContentPanel} panel The activated panel
 
84
         */
 
85
        "panelactivated" : true,
 
86
        /**
 
87
         * @event resized
 
88
         * Fires when the user resizes this region. 
 
89
         * @param {Ext.LayoutRegion} this
 
90
         * @param {Number} newSize The new size (width for east/west, height for north/south)
 
91
         */
 
92
        "resized" : true
 
93
    };
 
94
    /** A collection of panels in this region. @type Ext.util.MixedCollection */
 
95
    this.panels = new Ext.util.MixedCollection();
 
96
    this.panels.getKey = this.getPanelId.createDelegate(this);
 
97
    this.box = null;
 
98
    this.activePanel = null;
 
99
    if(skipConfig !== true){
 
100
        this.applyConfig(config);
 
101
    }
 
102
};
 
103
 
 
104
Ext.extend(Ext.BasicLayoutRegion, Ext.util.Observable, {
 
105
    getPanelId : function(p){
 
106
        return p.getId();
 
107
    },
 
108
    
 
109
    applyConfig : function(config){
 
110
        this.margins = config.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
 
111
        this.config = config;
 
112
    },
 
113
    
 
114
    /**
 
115
     * Resizes the region to the specified size. For vertical regions (west, east) this adjusts 
 
116
     * the width, for horizontal (north, south) the height.
 
117
     * @param {Number} newSize The new width or height
 
118
     */
 
119
    resizeTo : function(newSize){
 
120
        var el = this.el ? this.el :
 
121
                 (this.activePanel ? this.activePanel.getEl() : null);
 
122
        if(el){
 
123
            switch(this.position){
 
124
                case "east":
 
125
                case "west":
 
126
                    el.setWidth(newSize);
 
127
                    this.fireEvent("resized", this, newSize);
 
128
                break;
 
129
                case "north":
 
130
                case "south":
 
131
                    el.setHeight(newSize);
 
132
                    this.fireEvent("resized", this, newSize);
 
133
                break;                
 
134
            }
 
135
        }
 
136
    },
 
137
    
 
138
    getBox : function(){
 
139
        return this.activePanel ? this.activePanel.getEl().getBox(false, true) : null;
 
140
    },
 
141
    
 
142
    getMargins : function(){
 
143
        return this.margins;
 
144
    },
 
145
    
 
146
    updateBox : function(box){
 
147
        this.box = box;
 
148
        var el = this.activePanel.getEl();
 
149
        el.dom.style.left = box.x + "px";
 
150
        el.dom.style.top = box.y + "px";
 
151
        this.activePanel.setSize(box.width, box.height);
 
152
    },
 
153
    
 
154
    /**
 
155
     * Returns the container element for this region.
 
156
     * @return {Ext.Element}
 
157
     */
 
158
    getEl : function(){
 
159
        return this.activePanel;
 
160
    },
 
161
    
 
162
    /**
 
163
     * Returns true if this region is currently visible.
 
164
     * @return {Boolean}
 
165
     */
 
166
    isVisible : function(){
 
167
        return this.activePanel ? true : false;
 
168
    },
 
169
    
 
170
    setActivePanel : function(panel){
 
171
        panel = this.getPanel(panel);
 
172
        if(this.activePanel && this.activePanel != panel){
 
173
            this.activePanel.setActiveState(false);
 
174
            this.activePanel.getEl().setLeftTop(-10000,-10000);
 
175
        }
 
176
        this.activePanel = panel;
 
177
        panel.setActiveState(true);
 
178
        if(this.box){
 
179
            panel.setSize(this.box.width, this.box.height);
 
180
        }
 
181
        this.fireEvent("panelactivated", this, panel);
 
182
        this.fireEvent("invalidated");
 
183
    },
 
184
    
 
185
    /**
 
186
     * Show the specified panel.
 
187
     * @param {Number/String/ContentPanel} panelId The panels index, id or the panel itself
 
188
     * @return {Ext.ContentPanel} The shown panel or null
 
189
     */
 
190
    showPanel : function(panel){
 
191
        if(panel = this.getPanel(panel)){
 
192
            this.setActivePanel(panel);
 
193
        }
 
194
        return panel;
 
195
    },
 
196
    
 
197
    /**
 
198
     * Get the active panel for this region.
 
199
     * @return {Ext.ContentPanel} The active panel or null
 
200
     */
 
201
    getActivePanel : function(){
 
202
        return this.activePanel;
 
203
    },
 
204
    
 
205
    /**
 
206
     * Add the passed ContentPanel(s)
 
207
     * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
 
208
     * @return {Ext.ContentPanel} The panel added (if only one was added)
 
209
     */
 
210
    add : function(panel){
 
211
        if(arguments.length > 1){
 
212
            for(var i = 0, len = arguments.length; i < len; i++) {
 
213
                this.add(arguments[i]);
 
214
            }
 
215
            return null;
 
216
        }
 
217
        if(this.hasPanel(panel)){
 
218
            this.showPanel(panel);
 
219
            return panel;
 
220
        }
 
221
        var el = panel.getEl();
 
222
        if(el.dom.parentNode != this.mgr.el.dom){
 
223
            this.mgr.el.dom.appendChild(el.dom);
 
224
        }
 
225
        if(panel.setRegion){
 
226
            panel.setRegion(this);
 
227
        }
 
228
        this.panels.add(panel);
 
229
        el.setStyle("position", "absolute");
 
230
        if(!panel.background){
 
231
            this.setActivePanel(panel);
 
232
            if(this.config.initialSize && this.panels.getCount()==1){
 
233
                this.resizeTo(this.config.initialSize);
 
234
            }
 
235
        }
 
236
        this.fireEvent("paneladded", this, panel);
 
237
        return panel;
 
238
    },
 
239
    
 
240
    /**
 
241
     * Returns true if the panel is in this region.
 
242
     * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
 
243
     * @return {Boolean}
 
244
     */
 
245
    hasPanel : function(panel){
 
246
        if(typeof panel == "object"){ // must be panel obj
 
247
            panel = panel.getId();
 
248
        }
 
249
        return this.getPanel(panel) ? true : false;
 
250
    },
 
251
    
 
252
    /**
 
253
     * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
 
254
     * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
 
255
     * @param {Boolean} preservePanel Overrides the config preservePanel option
 
256
     * @return {Ext.ContentPanel} The panel that was removed
 
257
     */
 
258
    remove : function(panel, preservePanel){
 
259
        panel = this.getPanel(panel);
 
260
        if(!panel){
 
261
            return null;
 
262
        }
 
263
        var e = {};
 
264
        this.fireEvent("beforeremove", this, panel, e);
 
265
        if(e.cancel === true){
 
266
            return null;
 
267
        }
 
268
        var panelId = panel.getId();
 
269
        this.panels.removeKey(panelId);
 
270
        return panel;
 
271
    },
 
272
    
 
273
    /**
 
274
     * Returns the panel specified or null if it's not in this region.
 
275
     * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
 
276
     * @return {Ext.ContentPanel}
 
277
     */
 
278
    getPanel : function(id){
 
279
        if(typeof id == "object"){ // must be panel obj
 
280
            return id;
 
281
        }
 
282
        return this.panels.get(id);
 
283
    },
 
284
    
 
285
    /**
 
286
     * Returns this regions position (north/south/east/west/center).
 
287
     * @return {String} 
 
288
     */
 
289
    getPosition: function(){
 
290
        return this.position;    
 
291
    }
 
292
});
 
 
b'\\ No newline at end of file'