~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/ContentPanels.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.ContentPanel
 
11
 * @extends Ext.util.Observable
 
12
 * A basic ContentPanel element.
 
13
 * @cfg {Boolean} fitToFrame True for this panel to adjust its size to fit when the region resizes  (defaults to false)
 
14
 * @cfg {Boolean} fitContainer When using {@link #fitToFrame} and {@link #resizeEl}, you can also fit the parent container  (defaults to false)
 
15
 * @cfg {Boolean/Object} autoCreate True to auto generate the DOM element for this panel, or a {@link Ext.DomHelper} config of the element to create
 
16
 * @cfg {Boolean} closable True if the panel can be closed/removed
 
17
 * @cfg {Boolean} background True if the panel should not be activated when it is added (defaults to false)
 
18
 * @cfg {Mixed} resizeEl An element to resize if {@link #fitToFrame} is true (instead of this panel's element)
 
19
 * @cfg {Toolbar} toolbar A toolbar for this panel
 
20
 * @cfg {Boolean} autoScroll True to scroll overflow in this panel (use with {@link #fitToFrame})
 
21
 * @cfg {String} title The title for this panel
 
22
 * @cfg {Array} adjustments Values to <b>add</b> to the width/height when doing a {@link #fitToFrame} (default is [0, 0])
 
23
 * @cfg {String} url Calls {@link #setUrl} with this value
 
24
 * @cfg {String/Object} params When used with {@link #url}, calls {@link #setUrl} with this value
 
25
 * @cfg {Boolean} loadOnce When used with {@link #url}, calls {@link #setUrl} with this value
 
26
 * @constructor
 
27
 * Create a new ContentPanel.
 
28
 * @param {Mixed} el The container element for this panel
 
29
 * @param {String/Object} config A string to set only the title or a config object
 
30
 * @param {String} content (optional) Set the HTML content for this panel
 
31
 */
 
32
Ext.ContentPanel = function(el, config, content){
 
33
    if(el.autoCreate){
 
34
        config = el;
 
35
        el = Ext.id();
 
36
    }
 
37
    this.el = Ext.get(el);
 
38
    if(!this.el && config && config.autoCreate){
 
39
        if(typeof config.autoCreate == "object"){
 
40
            if(!config.autoCreate.id){
 
41
                config.autoCreate.id = config.id||el;
 
42
            }
 
43
            this.el = Ext.DomHelper.append(document.body,
 
44
                        config.autoCreate, true);
 
45
        }else{
 
46
            this.el = Ext.DomHelper.append(document.body,
 
47
                        {tag: "div", cls: "x-layout-inactive-content", id: config.id||el}, true);
 
48
        }
 
49
    }
 
50
    this.closable = false;
 
51
    this.loaded = false;
 
52
    this.active = false;
 
53
    if(typeof config == "string"){
 
54
        this.title = config;
 
55
    }else{
 
56
        Ext.apply(this, config);
 
57
    }
 
58
    if(this.resizeEl){
 
59
        this.resizeEl = Ext.get(this.resizeEl, true);
 
60
    }else{
 
61
        this.resizeEl = this.el;
 
62
    }
 
63
    this.addEvents({
 
64
        /**
 
65
         * @event activate
 
66
         * Fires when this panel is activated. 
 
67
         * @param {Ext.ContentPanel} this
 
68
         */
 
69
        "activate" : true,
 
70
        /**
 
71
         * @event deactivate
 
72
         * Fires when this panel is activated. 
 
73
         * @param {Ext.ContentPanel} this
 
74
         */
 
75
        "deactivate" : true,
 
76
 
 
77
        /**
 
78
         * @event resize
 
79
         * Fires when this panel is resized if fitToFrame is true.
 
80
         * @param {Ext.ContentPanel} this
 
81
         * @param {Number} width The width after any component adjustments
 
82
         * @param {Number} height The height after any component adjustments
 
83
         */
 
84
        "resize" : true
 
85
    });
 
86
    if(this.autoScroll){
 
87
        this.resizeEl.setStyle("overflow", "auto");
 
88
    }
 
89
    content = content || this.content;
 
90
    if(content){
 
91
        this.setContent(content);
 
92
    }
 
93
    if(config && config.url){
 
94
        this.setUrl(this.url, this.params, this.loadOnce);
 
95
    }
 
96
    Ext.ContentPanel.superclass.constructor.call(this);
 
97
};
 
98
 
 
99
Ext.extend(Ext.ContentPanel, Ext.util.Observable, {
 
100
    tabTip:'',
 
101
    setRegion : function(region){
 
102
        this.region = region;
 
103
        if(region){
 
104
           this.el.replaceClass("x-layout-inactive-content", "x-layout-active-content");
 
105
        }else{
 
106
           this.el.replaceClass("x-layout-active-content", "x-layout-inactive-content");
 
107
        } 
 
108
    },
 
109
    
 
110
    /**
 
111
     * Returns the toolbar for this Panel if one was configured. 
 
112
     * @return {Ext.Toolbar} 
 
113
     */
 
114
    getToolbar : function(){
 
115
        return this.toolbar;
 
116
    },
 
117
    
 
118
    setActiveState : function(active){
 
119
        this.active = active;
 
120
        if(!active){
 
121
            this.fireEvent("deactivate", this);
 
122
        }else{
 
123
            this.fireEvent("activate", this);
 
124
        }
 
125
    },
 
126
    /**
 
127
     * Updates this panel's element
 
128
     * @param {String} content The new content
 
129
     * @param {Boolean} loadScripts (optional) true to look for and process scripts
 
130
    */
 
131
    setContent : function(content, loadScripts){
 
132
        this.el.update(content, loadScripts);
 
133
    },
 
134
 
 
135
    ignoreResize : function(w, h){
 
136
        if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
 
137
            return true;
 
138
        }else{
 
139
            this.lastSize = {width: w, height: h};
 
140
            return false;
 
141
        }
 
142
    },
 
143
    /**
 
144
     * Get the {@link Ext.Updater} for this panel. Enables you to perform Ajax updates.
 
145
     * @return {Ext.Updater} The Updater
 
146
     */
 
147
    getUpdater : function(){
 
148
        return this.el.getUpdater();
 
149
    },
 
150
     /**
 
151
     * Loads this content panel immediately with content from XHR. Note: to delay loading until the panel is activated, use {@link #setUrl}.
 
152
     * @param {Object/String/Function} url The URL for this request or a function to call to get the URL or a config object containing any of the following options:
 
153
<pre><code>
 
154
panel.load({
 
155
    url: "your-url.php",
 
156
    params: {param1: "foo", param2: "bar"}, // or a URL encoded string
 
157
    callback: yourFunction,
 
158
    scope: yourObject, //(optional scope)
 
159
    discardUrl: false,
 
160
    nocache: false,
 
161
    text: "Loading...",
 
162
    timeout: 30,
 
163
    scripts: false
 
164
});
 
165
</code></pre>
 
166
     * The only required property is <i>url</i>. The optional properties <i>nocache</i>, <i>text</i> and <i>scripts</i>
 
167
     * are shorthand for <i>disableCaching</i>, <i>indicatorText</i> and <i>loadScripts</i> and are used to set their associated property on this panel Updater instance.
 
168
     * @param {String/Object} params (optional) The parameters to pass as either a URL encoded string "param1=1&amp;param2=2" or an object {param1: 1, param2: 2}
 
169
     * @param {Function} callback (optional) Callback when transaction is complete -- called with signature (oElement, bSuccess, oResponse)
 
170
     * @param {Boolean} discardUrl (optional) By default when you execute an update the defaultUrl is changed to the last used URL. If true, it will not store the URL.
 
171
     * @return {Ext.ContentPanel} this
 
172
     */
 
173
    load : function(){
 
174
        this.el.load.apply(this.el, arguments);
 
175
        return this;
 
176
    },
 
177
 
 
178
 
 
179
    /**
 
180
     * Set a URL to be used to load the content for this panel. When this panel is activated, the content will be loaded from that URL.
 
181
     * @param {String/Function} url The URL to load the content from or a function to call to get the URL
 
182
     * @param {String/Object} params (optional) The string params for the update call or an object of the params. See {@link Ext.Updater#update} for more details. (Defaults to null)
 
183
     * @param {Boolean} loadOnce (optional) Whether to only load the content once. If this is false it makes the Ajax call every time this panel is activated. (Defaults to false)
 
184
     * @return {Ext.Updater} The Updater
 
185
     */
 
186
    setUrl : function(url, params, loadOnce){
 
187
        if(this.refreshDelegate){
 
188
            this.removeListener("activate", this.refreshDelegate);
 
189
        }
 
190
        this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
 
191
        this.on("activate", this.refreshDelegate);
 
192
        return this.el.getUpdater();
 
193
    },
 
194
    
 
195
    _handleRefresh : function(url, params, loadOnce){
 
196
        if(!loadOnce || !this.loaded){
 
197
            var updater = this.el.getUpdater();
 
198
            updater.update(url, params, this._setLoaded.createDelegate(this));
 
199
        }
 
200
    },
 
201
    
 
202
    _setLoaded : function(){
 
203
        this.loaded = true;
 
204
    }, 
 
205
    
 
206
    /**
 
207
     * Returns this panel's id
 
208
     * @return {String} 
 
209
     */
 
210
    getId : function(){
 
211
        return this.el.id;
 
212
    },
 
213
    
 
214
    /**
 
215
     * Returns this panel's element
 
216
     * @return {Ext.Element} 
 
217
     */
 
218
    getEl : function(){
 
219
        return this.el;
 
220
    },
 
221
    
 
222
    adjustForComponents : function(width, height){
 
223
        if(this.resizeEl != this.el){
 
224
            width -= this.el.getFrameWidth('lr');
 
225
            height -= this.el.getFrameWidth('tb');
 
226
        }
 
227
        if(this.toolbar){
 
228
            var te = this.toolbar.getEl();
 
229
            height -= te.getHeight();
 
230
            te.setWidth(width);
 
231
        }
 
232
        if(this.adjustments){
 
233
            width += this.adjustments[0];
 
234
            height += this.adjustments[1];
 
235
        }
 
236
        return {"width": width, "height": height};
 
237
    },
 
238
    
 
239
    setSize : function(width, height){
 
240
        if(this.fitToFrame && !this.ignoreResize(width, height)){
 
241
            if(this.fitContainer && this.resizeEl != this.el){
 
242
                this.el.setSize(width, height);
 
243
            }
 
244
            var size = this.adjustForComponents(width, height);
 
245
            this.resizeEl.setSize(this.autoWidth ? "auto" : size.width, this.autoHeight ? "auto" : size.height);
 
246
            this.fireEvent('resize', this, size.width, size.height);
 
247
        }
 
248
    },
 
249
    
 
250
    /**
 
251
     * Returns this panel's title
 
252
     * @return {String} 
 
253
     */
 
254
    getTitle : function(){
 
255
        return this.title;
 
256
    },
 
257
    
 
258
    /**
 
259
     * Set this panel's title
 
260
     * @param {String} title
 
261
     */
 
262
    setTitle : function(title){
 
263
        this.title = title;
 
264
        if(this.region){
 
265
            this.region.updatePanelTitle(this, title);
 
266
        }
 
267
    },
 
268
    
 
269
    /**
 
270
     * Returns true is this panel was configured to be closable
 
271
     * @return {Boolean} 
 
272
     */
 
273
    isClosable : function(){
 
274
        return this.closable;
 
275
    },
 
276
    
 
277
    beforeSlide : function(){
 
278
        this.el.clip();
 
279
        this.resizeEl.clip();
 
280
    },
 
281
    
 
282
    afterSlide : function(){
 
283
        this.el.unclip();
 
284
        this.resizeEl.unclip();
 
285
    },
 
286
    
 
287
    /**
 
288
     *   Force a content refresh from the URL specified in the {@link #setUrl} method.
 
289
     *   Will fail silently if the {@link #setUrl} method has not been called.
 
290
     *   This does not activate the panel, just updates its content.
 
291
     */
 
292
    refresh : function(){
 
293
        if(this.refreshDelegate){
 
294
           this.loaded = false;
 
295
           this.refreshDelegate();
 
296
        }
 
297
    },
 
298
    
 
299
    /**
 
300
     * Destroys this panel
 
301
     */
 
302
    destroy : function(){
 
303
        this.el.removeAllListeners();
 
304
        var tempEl = document.createElement("span");
 
305
        tempEl.appendChild(this.el.dom);
 
306
        tempEl.innerHTML = "";
 
307
        this.el.remove();
 
308
        this.el = null;
 
309
    }
 
310
});
 
311
 
 
312
Ext.ContentPanel.prototype.getUpdateManager = Ext.ContentPanel.prototype.getUpdater;
 
313
 
 
314
/**
 
315
 * @class Ext.GridPanel
 
316
 * @extends Ext.ContentPanel
 
317
 * @constructor
 
318
 * Create a new GridPanel.
 
319
 * @param {Ext.grid.Grid} grid The grid for this panel
 
320
 * @param {String/Object} config A string to set only the panel's title, or a config object
 
321
 */
 
322
Ext.GridPanel = function(grid, config){
 
323
    this.wrapper = Ext.DomHelper.append(document.body, // wrapper for IE7 strict & safari scroll issue
 
324
        {tag: "div", cls: "x-layout-grid-wrapper x-layout-inactive-content"}, true);
 
325
    this.wrapper.dom.appendChild(grid.getGridEl().dom);
 
326
    Ext.GridPanel.superclass.constructor.call(this, this.wrapper, config);
 
327
    if(this.toolbar){
 
328
        this.toolbar.el.insertBefore(this.wrapper.dom.firstChild);
 
329
    }
 
330
    grid.monitorWindowResize = false; // turn off autosizing
 
331
    grid.autoHeight = false;
 
332
    grid.autoWidth = false;
 
333
    this.grid = grid;
 
334
    this.grid.getGridEl().replaceClass("x-layout-inactive-content", "x-layout-component-panel");
 
335
};
 
336
 
 
337
Ext.extend(Ext.GridPanel, Ext.ContentPanel, {
 
338
    getId : function(){
 
339
        return this.grid.id;
 
340
    },
 
341
    
 
342
    /**
 
343
     * Returns the grid for this panel
 
344
     * @return {Ext.grid.Grid} 
 
345
     */
 
346
    getGrid : function(){
 
347
        return this.grid;    
 
348
    },
 
349
    
 
350
    setSize : function(width, height){
 
351
        if(!this.ignoreResize(width, height)){
 
352
            var grid = this.grid;
 
353
            var size = this.adjustForComponents(width, height);
 
354
            grid.getGridEl().setSize(size.width, size.height);
 
355
            grid.autoSize();
 
356
        }
 
357
    },
 
358
    
 
359
    beforeSlide : function(){
 
360
        this.grid.getView().scroller.clip();
 
361
    },
 
362
    
 
363
    afterSlide : function(){
 
364
        this.grid.getView().scroller.unclip();
 
365
    },
 
366
    
 
367
    destroy : function(){
 
368
        this.grid.destroy();
 
369
        delete this.grid;
 
370
        Ext.GridPanel.superclass.destroy.call(this); 
 
371
    }
 
372
});
 
373
 
 
374
 
 
375
/**
 
376
 * @class Ext.NestedLayoutPanel
 
377
 * @extends Ext.ContentPanel
 
378
 * @constructor
 
379
 * Create a new NestedLayoutPanel.
 
380
 * @param {Ext.BorderLayout} layout The layout for this panel
 
381
 * @param {String/Object} config A string to set only the title or a config object
 
382
 */
 
383
Ext.NestedLayoutPanel = function(layout, config){
 
384
    Ext.NestedLayoutPanel.superclass.constructor.call(this, layout.getEl(), config);
 
385
    layout.monitorWindowResize = false; // turn off autosizing
 
386
    this.layout = layout;
 
387
    this.layout.getEl().addClass("x-layout-nested-layout");
 
388
};
 
389
 
 
390
Ext.extend(Ext.NestedLayoutPanel, Ext.ContentPanel, {
 
391
 
 
392
    setSize : function(width, height){
 
393
        if(!this.ignoreResize(width, height)){
 
394
            var size = this.adjustForComponents(width, height);
 
395
            var el = this.layout.getEl();
 
396
            el.setSize(size.width, size.height);
 
397
            var touch = el.dom.offsetWidth;
 
398
            this.layout.layout();
 
399
            // ie requires a double layout on the first pass
 
400
            if(Ext.isIE && !this.initialized){
 
401
                this.initialized = true;
 
402
                this.layout.layout();
 
403
            }
 
404
        }
 
405
    },
 
406
    
 
407
    /**
 
408
     * Returns the nested BorderLayout for this panel
 
409
     * @return {Ext.BorderLayout} 
 
410
     */
 
411
    getLayout : function(){
 
412
        return this.layout;
 
413
    }
 
414
});
 
415
 
 
416
Ext.ScrollPanel = function(el, config, content){
 
417
    config = config || {};
 
418
    config.fitToFrame = true;
 
419
    Ext.ScrollPanel.superclass.constructor.call(this, el, config, content);
 
420
    
 
421
    this.el.dom.style.overflow = "hidden";
 
422
    var wrap = this.el.wrap({cls: "x-scroller x-layout-inactive-content"});
 
423
    this.el.removeClass("x-layout-inactive-content");
 
424
    this.el.on("mousewheel", this.onWheel, this);
 
425
 
 
426
    var up = wrap.createChild({cls: "x-scroller-up", html: "&#160;"}, this.el.dom);
 
427
    var down = wrap.createChild({cls: "x-scroller-down", html: "&#160;"});
 
428
    up.unselectable(); down.unselectable();
 
429
    up.on("click", this.scrollUp, this);
 
430
    down.on("click", this.scrollDown, this);
 
431
    up.addClassOnOver("x-scroller-btn-over");
 
432
    down.addClassOnOver("x-scroller-btn-over");
 
433
    up.addClassOnClick("x-scroller-btn-click");
 
434
    down.addClassOnClick("x-scroller-btn-click");
 
435
    this.adjustments = [0, -(up.getHeight() + down.getHeight())];
 
436
 
 
437
    this.resizeEl = this.el;
 
438
    this.el = wrap; this.up = up; this.down = down;
 
439
};
 
440
 
 
441
Ext.extend(Ext.ScrollPanel, Ext.ContentPanel, {
 
442
    increment : 100,
 
443
    wheelIncrement : 5,
 
444
    scrollUp : function(){
 
445
        this.resizeEl.scroll("up", this.increment, {callback: this.afterScroll, scope: this});
 
446
    },
 
447
 
 
448
    scrollDown : function(){
 
449
        this.resizeEl.scroll("down", this.increment, {callback: this.afterScroll, scope: this});
 
450
    },
 
451
 
 
452
    afterScroll : function(){
 
453
        var el = this.resizeEl;
 
454
        var t = el.dom.scrollTop, h = el.dom.scrollHeight, ch = el.dom.clientHeight;
 
455
        this.up[t == 0 ? "addClass" : "removeClass"]("x-scroller-btn-disabled");
 
456
        this.down[h - t <= ch ? "addClass" : "removeClass"]("x-scroller-btn-disabled");
 
457
    },
 
458
 
 
459
    setSize : function(){
 
460
        Ext.ScrollPanel.superclass.setSize.apply(this, arguments);
 
461
        this.afterScroll();
 
462
    },
 
463
 
 
464
    onWheel : function(e){
 
465
        var d = e.getWheelDelta();
 
466
        this.resizeEl.dom.scrollTop -= (d*this.wheelIncrement);
 
467
        this.afterScroll();
 
468
        e.stopEvent();
 
469
    },
 
470
 
 
471
    setContent : function(content, loadScripts){
 
472
        this.resizeEl.update(content, loadScripts);
 
473
    }
 
474
 
 
475
});
 
 
b'\\ No newline at end of file'