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

« back to all changes in this revision

Viewing changes to gis/dhis-gis-geostat/mfbase/ext/source/legacy/layout/BorderLayout.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.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.BorderLayout
 
11
 * @extends Ext.LayoutManager
 
12
 * This class represents a common layout manager used in desktop applications. 
 
13
 * Example:
 
14
 <pre><code>
 
15
 var layout = new Ext.BorderLayout(document.body, {
 
16
    north: {
 
17
        initialSize: 25,
 
18
        titlebar: false
 
19
    },
 
20
    west: {
 
21
        split:true,
 
22
        initialSize: 200,
 
23
        minSize: 175,
 
24
        maxSize: 400,
 
25
        titlebar: true,
 
26
        collapsible: true
 
27
    },
 
28
    east: {
 
29
        split:true,
 
30
        initialSize: 202,
 
31
        minSize: 175,
 
32
        maxSize: 400,
 
33
        titlebar: true,
 
34
        collapsible: true
 
35
    },
 
36
    south: {
 
37
        split:true,
 
38
        initialSize: 100,
 
39
        minSize: 100,
 
40
        maxSize: 200,
 
41
        titlebar: true,
 
42
        collapsible: true
 
43
    },
 
44
    center: {
 
45
        titlebar: true,
 
46
        autoScroll:true,
 
47
        resizeTabs: true,
 
48
        minTabWidth: 50,
 
49
        preferredTabWidth: 150
 
50
    }
 
51
});
 
52
 
 
53
// shorthand
 
54
var CP = Ext.ContentPanel;
 
55
 
 
56
layout.beginUpdate();
 
57
layout.add("north", new CP("north", "North"));
 
58
layout.add("south", new CP("south", {title: "South", closable: true}));
 
59
layout.add("west", new CP("west", {title: "West"}));
 
60
layout.add("east", new CP("autoTabs", {title: "Auto Tabs", closable: true}));
 
61
layout.add("center", new CP("center1", {title: "Close Me", closable: true}));
 
62
layout.add("center", new CP("center2", {title: "Center Panel", closable: false}));
 
63
layout.getRegion("center").showPanel("center1");
 
64
layout.endUpdate();
 
65
</code></pre>
 
66
 
 
67
<b>The container the layout is rendered into can be either the body element or any other element.
 
68
If it is not the body element, the container needs to either be an absolute positioned element,
 
69
or you will need to add "position:relative" to the css of the container.  You will also need to specify
 
70
the container size if it is not the body element.</b>
 
71
 
 
72
* @constructor
 
73
* Create a new BorderLayout
 
74
* @param {Mixed} container The container this layout is bound to
 
75
* @param {Object} config Configuration options
 
76
 */
 
77
Ext.BorderLayout = function(container, config){
 
78
    config = config || {};
 
79
    Ext.BorderLayout.superclass.constructor.call(this, container, config);
 
80
    this.factory = config.factory || Ext.BorderLayout.RegionFactory;
 
81
    for(var i = 0, len = this.factory.validRegions.length; i < len; i++) {
 
82
        var target = this.factory.validRegions[i];
 
83
        if(config[target]){
 
84
            this.addRegion(target, config[target]);
 
85
        }
 
86
    }
 
87
};
 
88
 
 
89
Ext.extend(Ext.BorderLayout, Ext.LayoutManager, {
 
90
    /**
 
91
     * Creates and adds a new region if it doesn't already exist.
 
92
     * @param {String} target The target region key (north, south, east, west or center).
 
93
     * @param {Object} config The regions config object
 
94
     * @return {BorderLayoutRegion} The new region
 
95
     */
 
96
    addRegion : function(target, config){
 
97
        if(!this.regions[target]){
 
98
            var r = this.factory.create(target, this, config);
 
99
            this.bindRegion(target, r);
 
100
        }
 
101
        return this.regions[target];
 
102
    },
 
103
 
 
104
    // private (kinda)
 
105
    bindRegion : function(name, r){
 
106
        this.regions[name] = r;
 
107
        r.on("visibilitychange", this.layout, this);
 
108
        r.on("paneladded", this.layout, this);
 
109
        r.on("panelremoved", this.layout, this);
 
110
        r.on("invalidated", this.layout, this);
 
111
        r.on("resized", this.onRegionResized, this);
 
112
        r.on("collapsed", this.onRegionCollapsed, this);
 
113
        r.on("expanded", this.onRegionExpanded, this);
 
114
    },
 
115
 
 
116
    /**
 
117
     * Performs a layout update.
 
118
     */
 
119
    layout : function(){
 
120
        if(this.updating) return;
 
121
        var size = this.getViewSize();
 
122
        var w = size.width, h = size.height;
 
123
        var centerW = w, centerH = h, centerY = 0, centerX = 0;
 
124
        //var x = 0, y = 0;
 
125
 
 
126
        var rs = this.regions;
 
127
        var n = rs["north"], s = rs["south"], west = rs["west"], e = rs["east"], c = rs["center"];
 
128
        //if(this.hideOnLayout){ // not supported anymore
 
129
            //c.el.setStyle("display", "none");
 
130
        //}
 
131
        if(n && n.isVisible()){
 
132
            var b = n.getBox();
 
133
            var m = n.getMargins();
 
134
            b.width = w - (m.left+m.right);
 
135
            b.x = m.left;
 
136
            b.y = m.top;
 
137
            centerY = b.height + b.y + m.bottom;
 
138
            centerH -= centerY;
 
139
            n.updateBox(this.safeBox(b));
 
140
        }
 
141
        if(s && s.isVisible()){
 
142
            var b = s.getBox();
 
143
            var m = s.getMargins();
 
144
            b.width = w - (m.left+m.right);
 
145
            b.x = m.left;
 
146
            var totalHeight = (b.height + m.top + m.bottom);
 
147
            b.y = h - totalHeight + m.top;
 
148
            centerH -= totalHeight;
 
149
            s.updateBox(this.safeBox(b));
 
150
        }
 
151
        if(west && west.isVisible()){
 
152
            var b = west.getBox();
 
153
            var m = west.getMargins();
 
154
            b.height = centerH - (m.top+m.bottom);
 
155
            b.x = m.left;
 
156
            b.y = centerY + m.top;
 
157
            var totalWidth = (b.width + m.left + m.right);
 
158
            centerX += totalWidth;
 
159
            centerW -= totalWidth;
 
160
            west.updateBox(this.safeBox(b));
 
161
        }
 
162
        if(e && e.isVisible()){
 
163
            var b = e.getBox();
 
164
            var m = e.getMargins();
 
165
            b.height = centerH - (m.top+m.bottom);
 
166
            var totalWidth = (b.width + m.left + m.right);
 
167
            b.x = w - totalWidth + m.left;
 
168
            b.y = centerY + m.top;
 
169
            centerW -= totalWidth;
 
170
            e.updateBox(this.safeBox(b));
 
171
        }
 
172
        if(c){
 
173
            var m = c.getMargins();
 
174
            var centerBox = {
 
175
                x: centerX + m.left,
 
176
                y: centerY + m.top,
 
177
                width: centerW - (m.left+m.right),
 
178
                height: centerH - (m.top+m.bottom)
 
179
            };
 
180
            //if(this.hideOnLayout){
 
181
                //c.el.setStyle("display", "block");
 
182
            //}
 
183
            c.updateBox(this.safeBox(centerBox));
 
184
        }
 
185
        this.el.repaint();
 
186
        this.fireEvent("layout", this);
 
187
    },
 
188
 
 
189
    safeBox : function(box){
 
190
        box.width = Math.max(0, box.width);
 
191
        box.height = Math.max(0, box.height);
 
192
        return box;
 
193
    },
 
194
 
 
195
    /**
 
196
     * Adds a ContentPanel (or subclass) to this layout.
 
197
     * @param {String} target The target region key (north, south, east, west or center).
 
198
     * @param {Ext.ContentPanel} panel The panel to add
 
199
     * @return {Ext.ContentPanel} The added panel
 
200
     */
 
201
    add : function(target, panel){
 
202
        target = target.toLowerCase();
 
203
        return this.regions[target].add(panel);
 
204
    },
 
205
 
 
206
    /**
 
207
     * Remove a ContentPanel (or subclass) to this layout.
 
208
     * @param {String} target The target region key (north, south, east, west or center).
 
209
     * @param {Number/String/Ext.ContentPanel} panel The index, id or panel to remove
 
210
     * @return {Ext.ContentPanel} The removed panel
 
211
     */
 
212
    remove : function(target, panel){
 
213
        target = target.toLowerCase();
 
214
        return this.regions[target].remove(panel);
 
215
    },
 
216
 
 
217
    /**
 
218
     * Searches all regions for a panel with the specified id
 
219
     * @param {String} panelId
 
220
     * @return {Ext.ContentPanel} The panel or null if it wasn't found
 
221
     */
 
222
    findPanel : function(panelId){
 
223
        var rs = this.regions;
 
224
        for(var target in rs){
 
225
            if(typeof rs[target] != "function"){
 
226
                var p = rs[target].getPanel(panelId);
 
227
                if(p){
 
228
                    return p;
 
229
                }
 
230
            }
 
231
        }
 
232
        return null;
 
233
    },
 
234
 
 
235
    /**
 
236
     * Searches all regions for a panel with the specified id and activates (shows) it.
 
237
     * @param {String/ContentPanel} panelId The panels id or the panel itself
 
238
     * @return {Ext.ContentPanel} The shown panel or null
 
239
     */
 
240
    showPanel : function(panelId) {
 
241
      var rs = this.regions;
 
242
      for(var target in rs){
 
243
         var r = rs[target];
 
244
         if(typeof r != "function"){
 
245
            if(r.hasPanel(panelId)){
 
246
               return r.showPanel(panelId);
 
247
            }
 
248
         }
 
249
      }
 
250
      return null;
 
251
   },
 
252
 
 
253
   /**
 
254
     * Restores this layouts state using Ext.state.Manager or the state provided by the passed provider.
 
255
     * @param {Ext.state.Provider} provider (optional) An alternate state provider
 
256
     */
 
257
    restoreState : function(provider){
 
258
        if(!provider){
 
259
            provider = Ext.state.Manager;
 
260
        }
 
261
        var sm = new Ext.LayoutStateManager();
 
262
        sm.init(this, provider);
 
263
    },
 
264
 
 
265
 
 
266
    batchAdd : function(regions){
 
267
        this.beginUpdate();
 
268
        for(var rname in regions){
 
269
            var lr = this.regions[rname];
 
270
            if(lr){
 
271
                this.addTypedPanels(lr, regions[rname]);
 
272
            }
 
273
        }
 
274
        this.endUpdate();
 
275
    },
 
276
 
 
277
    /* @private */
 
278
    addTypedPanels : function(lr, ps){
 
279
        if(typeof ps == 'string'){
 
280
            lr.add(new Ext.ContentPanel(ps));
 
281
        }
 
282
        else if(Ext.isArray(ps)){
 
283
            for(var i =0, len = ps.length; i < len; i++){
 
284
                this.addTypedPanels(lr, ps[i]);
 
285
            }
 
286
        }
 
287
        else if(!ps.events){ // raw config?
 
288
            var el = ps.el;
 
289
            delete ps.el; // prevent conflict
 
290
            lr.add(new Ext.ContentPanel(el || Ext.id(), ps));
 
291
        }
 
292
        else {  // panel object assumed!
 
293
            lr.add(ps);
 
294
        }
 
295
    }
 
296
});
 
297
 
 
298
Ext.BorderLayout.create = function(config, targetEl){
 
299
    var layout = new Ext.BorderLayout(targetEl || document.body, config);
 
300
    layout.beginUpdate();
 
301
    var regions = Ext.BorderLayout.RegionFactory.validRegions;
 
302
    for(var j = 0, jlen = regions.length; j < jlen; j++){
 
303
        var lr = regions[j];
 
304
        if(layout.regions[lr] && config[lr].panels){
 
305
            var r = layout.regions[lr];
 
306
            var ps = config[lr].panels;
 
307
            layout.addTypedPanels(r, ps);
 
308
        }
 
309
    }
 
310
    layout.endUpdate();
 
311
    return layout;
 
312
};
 
313
 
 
314
Ext.BorderLayout.RegionFactory = {
 
315
    validRegions : ["north","south","east","west","center"],
 
316
 
 
317
    create : function(target, mgr, config){
 
318
        target = target.toLowerCase();
 
319
        if(config.lightweight || config.basic){
 
320
            return new Ext.BasicLayoutRegion(mgr, config, target);
 
321
        }
 
322
        switch(target){
 
323
            case "north":
 
324
                return new Ext.NorthLayoutRegion(mgr, config);
 
325
            case "south":
 
326
                return new Ext.SouthLayoutRegion(mgr, config);
 
327
            case "east":
 
328
                return new Ext.EastLayoutRegion(mgr, config);
 
329
            case "west":
 
330
                return new Ext.WestLayoutRegion(mgr, config);
 
331
            case "center":
 
332
                return new Ext.CenterLayoutRegion(mgr, config);
 
333
        }
 
334
        throw 'Layout region "'+target+'" not supported.';
 
335
    }
 
336
};
 
 
b'\\ No newline at end of file'