Upgrade to ExtJS 3.3.0 - Released 10/06/2010
[extjs.git] / pkgs / window-debug.js
1 /*!
2  * Ext JS Library 3.3.0
3  * Copyright(c) 2006-2010 Ext JS, Inc.
4  * licensing@extjs.com
5  * http://www.extjs.com/license
6  */
7 /**
8  * @class Ext.Window
9  * @extends Ext.Panel
10  * <p>A specialized panel intended for use as an application window.  Windows are floated, {@link #resizable}, and
11  * {@link #draggable} by default.  Windows can be {@link #maximizable maximized} to fill the viewport,
12  * restored to their prior size, and can be {@link #minimize}d.</p>
13  * <p>Windows can also be linked to a {@link Ext.WindowGroup} or managed by the {@link Ext.WindowMgr} to provide
14  * grouping, activation, to front, to back and other application-specific behavior.</p>
15  * <p>By default, Windows will be rendered to document.body. To {@link #constrain} a Window to another element
16  * specify {@link Ext.Component#renderTo renderTo}.</p>
17  * <p><b>Note:</b> By default, the <code>{@link #closable close}</code> header tool <i>destroys</i> the Window resulting in
18  * destruction of any child Components. This makes the Window object, and all its descendants <b>unusable</b>. To enable
19  * re-use of a Window, use <b><code>{@link #closeAction closeAction: 'hide'}</code></b>.</p>
20  * @constructor
21  * @param {Object} config The config object
22  * @xtype window
23  */
24 Ext.Window = Ext.extend(Ext.Panel, {
25     /**
26      * @cfg {Number} x
27      * The X position of the left edge of the window on initial showing. Defaults to centering the Window within
28      * the width of the Window's container {@link Ext.Element Element) (The Element that the Window is rendered to).
29      */
30     /**
31      * @cfg {Number} y
32      * The Y position of the top edge of the window on initial showing. Defaults to centering the Window within
33      * the height of the Window's container {@link Ext.Element Element) (The Element that the Window is rendered to).
34      */
35     /**
36      * @cfg {Boolean} modal
37      * True to make the window modal and mask everything behind it when displayed, false to display it without
38      * restricting access to other UI elements (defaults to false).
39      */
40     /**
41      * @cfg {String/Element} animateTarget
42      * Id or element from which the window should animate while opening (defaults to null with no animation).
43      */
44     /**
45      * @cfg {String} resizeHandles
46      * A valid {@link Ext.Resizable} handles config string (defaults to 'all').  Only applies when resizable = true.
47      */
48     /**
49      * @cfg {Ext.WindowGroup} manager
50      * A reference to the WindowGroup that should manage this window (defaults to {@link Ext.WindowMgr}).
51      */
52     /**
53     * @cfg {String/Number/Component} defaultButton
54     * <p>Specifies a Component to receive focus when this Window is focussed.</p>
55     * <p>This may be one of:</p><div class="mdetail-params"><ul>
56     * <li>The index of a footer Button.</li>
57     * <li>The id of a Component.</li>
58     * <li>A Component.</li>
59     * </ul></div>
60     */
61     /**
62     * @cfg {Function} onEsc
63     * Allows override of the built-in processing for the escape key. Default action
64     * is to close the Window (performing whatever action is specified in {@link #closeAction}.
65     * To prevent the Window closing when the escape key is pressed, specify this as
66     * Ext.emptyFn (See {@link Ext#emptyFn}).
67     */
68     /**
69      * @cfg {Boolean} collapsed
70      * True to render the window collapsed, false to render it expanded (defaults to false). Note that if
71      * {@link #expandOnShow} is true (the default) it will override the <tt>collapsed</tt> config and the window
72      * will always be expanded when shown.
73      */
74     /**
75      * @cfg {Boolean} maximized
76      * True to initially display the window in a maximized state. (Defaults to false).
77      */
78
79     /**
80     * @cfg {String} baseCls
81     * The base CSS class to apply to this panel's element (defaults to 'x-window').
82     */
83     baseCls : 'x-window',
84     /**
85      * @cfg {Boolean} resizable
86      * True to allow user resizing at each edge and corner of the window, false to disable resizing (defaults to true).
87      */
88     resizable : true,
89     /**
90      * @cfg {Boolean} draggable
91      * True to allow the window to be dragged by the header bar, false to disable dragging (defaults to true).  Note
92      * that by default the window will be centered in the viewport, so if dragging is disabled the window may need
93      * to be positioned programmatically after render (e.g., myWindow.setPosition(100, 100);).
94      */
95     draggable : true,
96     /**
97      * @cfg {Boolean} closable
98      * <p>True to display the 'close' tool button and allow the user to close the window, false to
99      * hide the button and disallow closing the window (defaults to true).</p>
100      * <p>By default, when close is requested by either clicking the close button in the header
101      * or pressing ESC when the Window has focus, the {@link #close} method will be called. This
102      * will <i>{@link Ext.Component#destroy destroy}</i> the Window and its content meaning that
103      * it may not be reused.</p>
104      * <p>To make closing a Window <i>hide</i> the Window so that it may be reused, set
105      * {@link #closeAction} to 'hide'.
106      */
107     closable : true,
108     /**
109      * @cfg {String} closeAction
110      * <p>The action to take when the close header tool is clicked:
111      * <div class="mdetail-params"><ul>
112      * <li><b><code>'{@link #close}'</code></b> : <b>Default</b><div class="sub-desc">
113      * {@link #close remove} the window from the DOM and {@link Ext.Component#destroy destroy}
114      * it and all descendant Components. The window will <b>not</b> be available to be
115      * redisplayed via the {@link #show} method.
116      * </div></li>
117      * <li><b><code>'{@link #hide}'</code></b> : <div class="sub-desc">
118      * {@link #hide} the window by setting visibility to hidden and applying negative offsets.
119      * The window will be available to be redisplayed via the {@link #show} method.
120      * </div></li>
121      * </ul></div>
122      * <p><b>Note:</b> This setting does not affect the {@link #close} method
123      * which will always {@link Ext.Component#destroy destroy} the window. To
124      * programatically <i>hide</i> a window, call {@link #hide}.</p>
125      */
126     closeAction : 'close',
127     /**
128      * @cfg {Boolean} constrain
129      * True to constrain the window within its containing element, false to allow it to fall outside of its
130      * containing element. By default the window will be rendered to document.body.  To render and constrain the
131      * window within another element specify {@link #renderTo}.
132      * (defaults to false).  Optionally the header only can be constrained using {@link #constrainHeader}.
133      */
134     constrain : false,
135     /**
136      * @cfg {Boolean} constrainHeader
137      * True to constrain the window header within its containing element (allowing the window body to fall outside
138      * of its containing element) or false to allow the header to fall outside its containing element (defaults to
139      * false). Optionally the entire window can be constrained using {@link #constrain}.
140      */
141     constrainHeader : false,
142     /**
143      * @cfg {Boolean} plain
144      * True to render the window body with a transparent background so that it will blend into the framing
145      * elements, false to add a lighter background color to visually highlight the body element and separate it
146      * more distinctly from the surrounding frame (defaults to false).
147      */
148     plain : false,
149     /**
150      * @cfg {Boolean} minimizable
151      * True to display the 'minimize' tool button and allow the user to minimize the window, false to hide the button
152      * and disallow minimizing the window (defaults to false).  Note that this button provides no implementation --
153      * the behavior of minimizing a window is implementation-specific, so the minimize event must be handled and a
154      * custom minimize behavior implemented for this option to be useful.
155      */
156     minimizable : false,
157     /**
158      * @cfg {Boolean} maximizable
159      * True to display the 'maximize' tool button and allow the user to maximize the window, false to hide the button
160      * and disallow maximizing the window (defaults to false).  Note that when a window is maximized, the tool button
161      * will automatically change to a 'restore' button with the appropriate behavior already built-in that will
162      * restore the window to its previous size.
163      */
164     maximizable : false,
165     /**
166      * @cfg {Number} minHeight
167      * The minimum height in pixels allowed for this window (defaults to 100).  Only applies when resizable = true.
168      */
169     minHeight : 100,
170     /**
171      * @cfg {Number} minWidth
172      * The minimum width in pixels allowed for this window (defaults to 200).  Only applies when resizable = true.
173      */
174     minWidth : 200,
175     /**
176      * @cfg {Boolean} expandOnShow
177      * True to always expand the window when it is displayed, false to keep it in its current state (which may be
178      * {@link #collapsed}) when displayed (defaults to true).
179      */
180     expandOnShow : true,
181     
182     /**
183      * @cfg {Number} showAnimDuration The number of seconds that the window show animation takes if enabled.
184      * Defaults to 0.25
185      */
186     showAnimDuration: 0.25,
187     
188     /**
189      * @cfg {Number} hideAnimDuration The number of seconds that the window hide animation takes if enabled.
190      * Defaults to 0.25
191      */
192     hideAnimDuration: 0.25,
193
194     // inherited docs, same default
195     collapsible : false,
196
197     /**
198      * @cfg {Boolean} initHidden
199      * True to hide the window until show() is explicitly called (defaults to true).
200      * @deprecated
201      */
202     initHidden : undefined,
203
204     /**
205      * @cfg {Boolean} hidden
206      * Render this component hidden (default is <tt>true</tt>). If <tt>true</tt>, the
207      * {@link #hide} method will be called internally.
208      */
209     hidden : true,
210
211     // The following configs are set to provide the basic functionality of a window.
212     // Changing them would require additional code to handle correctly and should
213     // usually only be done in subclasses that can provide custom behavior.  Changing them
214     // may have unexpected or undesirable results.
215     /** @cfg {String} elements @hide */
216     elements : 'header,body',
217     /** @cfg {Boolean} frame @hide */
218     frame : true,
219     /** @cfg {Boolean} floating @hide */
220     floating : true,
221
222     // private
223     initComponent : function(){
224         this.initTools();
225         Ext.Window.superclass.initComponent.call(this);
226         this.addEvents(
227             /**
228              * @event activate
229              * Fires after the window has been visually activated via {@link #setActive}.
230              * @param {Ext.Window} this
231              */
232             /**
233              * @event deactivate
234              * Fires after the window has been visually deactivated via {@link #setActive}.
235              * @param {Ext.Window} this
236              */
237             /**
238              * @event resize
239              * Fires after the window has been resized.
240              * @param {Ext.Window} this
241              * @param {Number} width The window's new width
242              * @param {Number} height The window's new height
243              */
244             'resize',
245             /**
246              * @event maximize
247              * Fires after the window has been maximized.
248              * @param {Ext.Window} this
249              */
250             'maximize',
251             /**
252              * @event minimize
253              * Fires after the window has been minimized.
254              * @param {Ext.Window} this
255              */
256             'minimize',
257             /**
258              * @event restore
259              * Fires after the window has been restored to its original size after being maximized.
260              * @param {Ext.Window} this
261              */
262             'restore'
263         );
264         // for backwards compat, this should be removed at some point
265         if(Ext.isDefined(this.initHidden)){
266             this.hidden = this.initHidden;
267         }
268         if(this.hidden === false){
269             this.hidden = true;
270             this.show();
271         }
272     },
273
274     // private
275     getState : function(){
276         return Ext.apply(Ext.Window.superclass.getState.call(this) || {}, this.getBox(true));
277     },
278
279     // private
280     onRender : function(ct, position){
281         Ext.Window.superclass.onRender.call(this, ct, position);
282
283         if(this.plain){
284             this.el.addClass('x-window-plain');
285         }
286
287         // this element allows the Window to be focused for keyboard events
288         this.focusEl = this.el.createChild({
289                     tag: 'a', href:'#', cls:'x-dlg-focus',
290                     tabIndex:'-1', html: '&#160;'});
291         this.focusEl.swallowEvent('click', true);
292
293         this.proxy = this.el.createProxy('x-window-proxy');
294         this.proxy.enableDisplayMode('block');
295
296         if(this.modal){
297             this.mask = this.container.createChild({cls:'ext-el-mask'}, this.el.dom);
298             this.mask.enableDisplayMode('block');
299             this.mask.hide();
300             this.mon(this.mask, 'click', this.focus, this);
301         }
302         if(this.maximizable){
303             this.mon(this.header, 'dblclick', this.toggleMaximize, this);
304         }
305     },
306
307     // private
308     initEvents : function(){
309         Ext.Window.superclass.initEvents.call(this);
310         if(this.animateTarget){
311             this.setAnimateTarget(this.animateTarget);
312         }
313
314         if(this.resizable){
315             this.resizer = new Ext.Resizable(this.el, {
316                 minWidth: this.minWidth,
317                 minHeight:this.minHeight,
318                 handles: this.resizeHandles || 'all',
319                 pinned: true,
320                 resizeElement : this.resizerAction,
321                 handleCls: 'x-window-handle'
322             });
323             this.resizer.window = this;
324             this.mon(this.resizer, 'beforeresize', this.beforeResize, this);
325         }
326
327         if(this.draggable){
328             this.header.addClass('x-window-draggable');
329         }
330         this.mon(this.el, 'mousedown', this.toFront, this);
331         this.manager = this.manager || Ext.WindowMgr;
332         this.manager.register(this);
333         if(this.maximized){
334             this.maximized = false;
335             this.maximize();
336         }
337         if(this.closable){
338             var km = this.getKeyMap();
339             km.on(27, this.onEsc, this);
340             km.disable();
341         }
342     },
343
344     initDraggable : function(){
345         /**
346          * <p>If this Window is configured {@link #draggable}, this property will contain
347          * an instance of {@link Ext.dd.DD} which handles dragging the Window's DOM Element.</p>
348          * <p>This has implementations of <code>startDrag</code>, <code>onDrag</code> and <code>endDrag</code>
349          * which perform the dragging action. If extra logic is needed at these points, use
350          * {@link Function#createInterceptor createInterceptor} or {@link Function#createSequence createSequence} to
351          * augment the existing implementations.</p>
352          * @type Ext.dd.DD
353          * @property dd
354          */
355         this.dd = new Ext.Window.DD(this);
356     },
357
358    // private
359     onEsc : function(k, e){
360         e.stopEvent();
361         this[this.closeAction]();
362     },
363
364     // private
365     beforeDestroy : function(){
366         if(this.rendered){
367             this.hide();
368             this.clearAnchor();
369             Ext.destroy(
370                 this.focusEl,
371                 this.resizer,
372                 this.dd,
373                 this.proxy,
374                 this.mask
375             );
376         }
377         Ext.Window.superclass.beforeDestroy.call(this);
378     },
379
380     // private
381     onDestroy : function(){
382         if(this.manager){
383             this.manager.unregister(this);
384         }
385         Ext.Window.superclass.onDestroy.call(this);
386     },
387
388     // private
389     initTools : function(){
390         if(this.minimizable){
391             this.addTool({
392                 id: 'minimize',
393                 handler: this.minimize.createDelegate(this, [])
394             });
395         }
396         if(this.maximizable){
397             this.addTool({
398                 id: 'maximize',
399                 handler: this.maximize.createDelegate(this, [])
400             });
401             this.addTool({
402                 id: 'restore',
403                 handler: this.restore.createDelegate(this, []),
404                 hidden:true
405             });
406         }
407         if(this.closable){
408             this.addTool({
409                 id: 'close',
410                 handler: this[this.closeAction].createDelegate(this, [])
411             });
412         }
413     },
414
415     // private
416     resizerAction : function(){
417         var box = this.proxy.getBox();
418         this.proxy.hide();
419         this.window.handleResize(box);
420         return box;
421     },
422
423     // private
424     beforeResize : function(){
425         this.resizer.minHeight = Math.max(this.minHeight, this.getFrameHeight() + 40); // 40 is a magic minimum content size?
426         this.resizer.minWidth = Math.max(this.minWidth, this.getFrameWidth() + 40);
427         this.resizeBox = this.el.getBox();
428     },
429
430     // private
431     updateHandles : function(){
432         if(Ext.isIE && this.resizer){
433             this.resizer.syncHandleHeight();
434             this.el.repaint();
435         }
436     },
437
438     // private
439     handleResize : function(box){
440         var rz = this.resizeBox;
441         if(rz.x != box.x || rz.y != box.y){
442             this.updateBox(box);
443         }else{
444             this.setSize(box);
445             if (Ext.isIE6 && Ext.isStrict) {
446                 this.doLayout();
447             }
448         }
449         this.focus();
450         this.updateHandles();
451         this.saveState();
452     },
453
454     /**
455      * Focuses the window.  If a defaultButton is set, it will receive focus, otherwise the
456      * window itself will receive focus.
457      */
458     focus : function(){
459         var f = this.focusEl,
460             db = this.defaultButton,
461             t = typeof db,
462             el,
463             ct;
464         if(Ext.isDefined(db)){
465             if(Ext.isNumber(db) && this.fbar){
466                 f = this.fbar.items.get(db);
467             }else if(Ext.isString(db)){
468                 f = Ext.getCmp(db);
469             }else{
470                 f = db;
471             }
472             el = f.getEl();
473             ct = Ext.getDom(this.container);
474             if (el && ct) {
475                 if (ct != document.body && !Ext.lib.Region.getRegion(ct).contains(Ext.lib.Region.getRegion(el.dom))){
476                     return;
477                 }
478             }
479         }
480         f = f || this.focusEl;
481         f.focus.defer(10, f);
482     },
483
484     /**
485      * Sets the target element from which the window should animate while opening.
486      * @param {String/Element} el The target element or id
487      */
488     setAnimateTarget : function(el){
489         el = Ext.get(el);
490         this.animateTarget = el;
491     },
492
493     // private
494     beforeShow : function(){
495         delete this.el.lastXY;
496         delete this.el.lastLT;
497         if(this.x === undefined || this.y === undefined){
498             var xy = this.el.getAlignToXY(this.container, 'c-c');
499             var pos = this.el.translatePoints(xy[0], xy[1]);
500             this.x = this.x === undefined? pos.left : this.x;
501             this.y = this.y === undefined? pos.top : this.y;
502         }
503         this.el.setLeftTop(this.x, this.y);
504
505         if(this.expandOnShow){
506             this.expand(false);
507         }
508
509         if(this.modal){
510             Ext.getBody().addClass('x-body-masked');
511             this.mask.setSize(Ext.lib.Dom.getViewWidth(true), Ext.lib.Dom.getViewHeight(true));
512             this.mask.show();
513         }
514     },
515
516     /**
517      * Shows the window, rendering it first if necessary, or activates it and brings it to front if hidden.
518      * @param {String/Element} animateTarget (optional) The target element or id from which the window should
519      * animate while opening (defaults to null with no animation)
520      * @param {Function} callback (optional) A callback function to call after the window is displayed
521      * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to this Window.
522      * @return {Ext.Window} this
523      */
524     show : function(animateTarget, cb, scope){
525         if(!this.rendered){
526             this.render(Ext.getBody());
527         }
528         if(this.hidden === false){
529             this.toFront();
530             return this;
531         }
532         if(this.fireEvent('beforeshow', this) === false){
533             return this;
534         }
535         if(cb){
536             this.on('show', cb, scope, {single:true});
537         }
538         this.hidden = false;
539         if(Ext.isDefined(animateTarget)){
540             this.setAnimateTarget(animateTarget);
541         }
542         this.beforeShow();
543         if(this.animateTarget){
544             this.animShow();
545         }else{
546             this.afterShow();
547         }
548         return this;
549     },
550
551     // private
552     afterShow : function(isAnim){
553         if (this.isDestroyed){
554             return false;
555         }
556         this.proxy.hide();
557         this.el.setStyle('display', 'block');
558         this.el.show();
559         if(this.maximized){
560             this.fitContainer();
561         }
562         if(Ext.isMac && Ext.isGecko2){ // work around stupid FF 2.0/Mac scroll bar bug
563             this.cascade(this.setAutoScroll);
564         }
565
566         if(this.monitorResize || this.modal || this.constrain || this.constrainHeader){
567             Ext.EventManager.onWindowResize(this.onWindowResize, this);
568         }
569         this.doConstrain();
570         this.doLayout();
571         if(this.keyMap){
572             this.keyMap.enable();
573         }
574         this.toFront();
575         this.updateHandles();
576         if(isAnim && (Ext.isIE || Ext.isWebKit)){
577             var sz = this.getSize();
578             this.onResize(sz.width, sz.height);
579         }
580         this.onShow();
581         this.fireEvent('show', this);
582     },
583
584     // private
585     animShow : function(){
586         this.proxy.show();
587         this.proxy.setBox(this.animateTarget.getBox());
588         this.proxy.setOpacity(0);
589         var b = this.getBox();
590         this.el.setStyle('display', 'none');
591         this.proxy.shift(Ext.apply(b, {
592             callback: this.afterShow.createDelegate(this, [true], false),
593             scope: this,
594             easing: 'easeNone',
595             duration: this.showAnimDuration,
596             opacity: 0.5
597         }));
598     },
599
600     /**
601      * Hides the window, setting it to invisible and applying negative offsets.
602      * @param {String/Element} animateTarget (optional) The target element or id to which the window should
603      * animate while hiding (defaults to null with no animation)
604      * @param {Function} callback (optional) A callback function to call after the window is hidden
605      * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to this Window.
606      * @return {Ext.Window} this
607      */
608     hide : function(animateTarget, cb, scope){
609         if(this.hidden || this.fireEvent('beforehide', this) === false){
610             return this;
611         }
612         if(cb){
613             this.on('hide', cb, scope, {single:true});
614         }
615         this.hidden = true;
616         if(animateTarget !== undefined){
617             this.setAnimateTarget(animateTarget);
618         }
619         if(this.modal){
620             this.mask.hide();
621             Ext.getBody().removeClass('x-body-masked');
622         }
623         if(this.animateTarget){
624             this.animHide();
625         }else{
626             this.el.hide();
627             this.afterHide();
628         }
629         return this;
630     },
631
632     // private
633     afterHide : function(){
634         this.proxy.hide();
635         if(this.monitorResize || this.modal || this.constrain || this.constrainHeader){
636             Ext.EventManager.removeResizeListener(this.onWindowResize, this);
637         }
638         if(this.keyMap){
639             this.keyMap.disable();
640         }
641         this.onHide();
642         this.fireEvent('hide', this);
643     },
644
645     // private
646     animHide : function(){
647         this.proxy.setOpacity(0.5);
648         this.proxy.show();
649         var tb = this.getBox(false);
650         this.proxy.setBox(tb);
651         this.el.hide();
652         this.proxy.shift(Ext.apply(this.animateTarget.getBox(), {
653             callback: this.afterHide,
654             scope: this,
655             duration: this.hideAnimDuration,
656             easing: 'easeNone',
657             opacity: 0
658         }));
659     },
660
661     /**
662      * Method that is called immediately before the <code>show</code> event is fired.
663      * Defaults to <code>Ext.emptyFn</code>.
664      */
665     onShow : Ext.emptyFn,
666
667     /**
668      * Method that is called immediately before the <code>hide</code> event is fired.
669      * Defaults to <code>Ext.emptyFn</code>.
670      */
671     onHide : Ext.emptyFn,
672
673     // private
674     onWindowResize : function(){
675         if(this.maximized){
676             this.fitContainer();
677         }
678         if(this.modal){
679             this.mask.setSize('100%', '100%');
680             var force = this.mask.dom.offsetHeight;
681             this.mask.setSize(Ext.lib.Dom.getViewWidth(true), Ext.lib.Dom.getViewHeight(true));
682         }
683         this.doConstrain();
684     },
685
686     // private
687     doConstrain : function(){
688         if(this.constrain || this.constrainHeader){
689             var offsets;
690             if(this.constrain){
691                 offsets = {
692                     right:this.el.shadowOffset,
693                     left:this.el.shadowOffset,
694                     bottom:this.el.shadowOffset
695                 };
696             }else {
697                 var s = this.getSize();
698                 offsets = {
699                     right:-(s.width - 100),
700                     bottom:-(s.height - 25)
701                 };
702             }
703
704             var xy = this.el.getConstrainToXY(this.container, true, offsets);
705             if(xy){
706                 this.setPosition(xy[0], xy[1]);
707             }
708         }
709     },
710
711     // private - used for dragging
712     ghost : function(cls){
713         var ghost = this.createGhost(cls);
714         var box = this.getBox(true);
715         ghost.setLeftTop(box.x, box.y);
716         ghost.setWidth(box.width);
717         this.el.hide();
718         this.activeGhost = ghost;
719         return ghost;
720     },
721
722     // private
723     unghost : function(show, matchPosition){
724         if(!this.activeGhost) {
725             return;
726         }
727         if(show !== false){
728             this.el.show();
729             this.focus.defer(10, this);
730             if(Ext.isMac && Ext.isGecko2){ // work around stupid FF 2.0/Mac scroll bar bug
731                 this.cascade(this.setAutoScroll);
732             }
733         }
734         if(matchPosition !== false){
735             this.setPosition(this.activeGhost.getLeft(true), this.activeGhost.getTop(true));
736         }
737         this.activeGhost.hide();
738         this.activeGhost.remove();
739         delete this.activeGhost;
740     },
741
742     /**
743      * Placeholder method for minimizing the window.  By default, this method simply fires the {@link #minimize} event
744      * since the behavior of minimizing a window is application-specific.  To implement custom minimize behavior,
745      * either the minimize event can be handled or this method can be overridden.
746      * @return {Ext.Window} this
747      */
748     minimize : function(){
749         this.fireEvent('minimize', this);
750         return this;
751     },
752
753     /**
754      * <p>Closes the Window, removes it from the DOM, {@link Ext.Component#destroy destroy}s
755      * the Window object and all its descendant Components. The {@link Ext.Panel#beforeclose beforeclose}
756      * event is fired before the close happens and will cancel the close action if it returns false.<p>
757      * <p><b>Note:</b> This method is not affected by the {@link #closeAction} setting which
758      * only affects the action triggered when clicking the {@link #closable 'close' tool in the header}.
759      * To hide the Window without destroying it, call {@link #hide}.</p>
760      */
761     close : function(){
762         if(this.fireEvent('beforeclose', this) !== false){
763             if(this.hidden){
764                 this.doClose();
765             }else{
766                 this.hide(null, this.doClose, this);
767             }
768         }
769     },
770
771     // private
772     doClose : function(){
773         this.fireEvent('close', this);
774         this.destroy();
775     },
776
777     /**
778      * Fits the window within its current container and automatically replaces
779      * the {@link #maximizable 'maximize' tool button} with the 'restore' tool button.
780      * Also see {@link #toggleMaximize}.
781      * @return {Ext.Window} this
782      */
783     maximize : function(){
784         if(!this.maximized){
785             this.expand(false);
786             this.restoreSize = this.getSize();
787             this.restorePos = this.getPosition(true);
788             if (this.maximizable){
789                 this.tools.maximize.hide();
790                 this.tools.restore.show();
791             }
792             this.maximized = true;
793             this.el.disableShadow();
794
795             if(this.dd){
796                 this.dd.lock();
797             }
798             if(this.collapsible){
799                 this.tools.toggle.hide();
800             }
801             this.el.addClass('x-window-maximized');
802             this.container.addClass('x-window-maximized-ct');
803
804             this.setPosition(0, 0);
805             this.fitContainer();
806             this.fireEvent('maximize', this);
807         }
808         return this;
809     },
810
811     /**
812      * Restores a {@link #maximizable maximized}  window back to its original
813      * size and position prior to being maximized and also replaces
814      * the 'restore' tool button with the 'maximize' tool button.
815      * Also see {@link #toggleMaximize}.
816      * @return {Ext.Window} this
817      */
818     restore : function(){
819         if(this.maximized){
820             var t = this.tools;
821             this.el.removeClass('x-window-maximized');
822             if(t.restore){
823                 t.restore.hide();
824             }
825             if(t.maximize){
826                 t.maximize.show();
827             }
828             this.setPosition(this.restorePos[0], this.restorePos[1]);
829             this.setSize(this.restoreSize.width, this.restoreSize.height);
830             delete this.restorePos;
831             delete this.restoreSize;
832             this.maximized = false;
833             this.el.enableShadow(true);
834
835             if(this.dd){
836                 this.dd.unlock();
837             }
838             if(this.collapsible && t.toggle){
839                 t.toggle.show();
840             }
841             this.container.removeClass('x-window-maximized-ct');
842
843             this.doConstrain();
844             this.fireEvent('restore', this);
845         }
846         return this;
847     },
848
849     /**
850      * A shortcut method for toggling between {@link #maximize} and {@link #restore} based on the current maximized
851      * state of the window.
852      * @return {Ext.Window} this
853      */
854     toggleMaximize : function(){
855         return this[this.maximized ? 'restore' : 'maximize']();
856     },
857
858     // private
859     fitContainer : function(){
860         var vs = this.container.getViewSize(false);
861         this.setSize(vs.width, vs.height);
862     },
863
864     // private
865     // z-index is managed by the WindowManager and may be overwritten at any time
866     setZIndex : function(index){
867         if(this.modal){
868             this.mask.setStyle('z-index', index);
869         }
870         this.el.setZIndex(++index);
871         index += 5;
872
873         if(this.resizer){
874             this.resizer.proxy.setStyle('z-index', ++index);
875         }
876
877         this.lastZIndex = index;
878     },
879
880     /**
881      * Aligns the window to the specified element
882      * @param {Mixed} element The element to align to.
883      * @param {String} position (optional, defaults to "tl-bl?") The position to align to (see {@link Ext.Element#alignTo} for more details).
884      * @param {Array} offsets (optional) Offset the positioning by [x, y]
885      * @return {Ext.Window} this
886      */
887     alignTo : function(element, position, offsets){
888         var xy = this.el.getAlignToXY(element, position, offsets);
889         this.setPagePosition(xy[0], xy[1]);
890         return this;
891     },
892
893     /**
894      * Anchors this window to another element and realigns it when the window is resized or scrolled.
895      * @param {Mixed} element The element to align to.
896      * @param {String} position The position to align to (see {@link Ext.Element#alignTo} for more details)
897      * @param {Array} offsets (optional) Offset the positioning by [x, y]
898      * @param {Boolean/Number} monitorScroll (optional) true to monitor body scroll and reposition. If this parameter
899      * is a number, it is used as the buffer delay (defaults to 50ms).
900      * @return {Ext.Window} this
901      */
902     anchorTo : function(el, alignment, offsets, monitorScroll){
903         this.clearAnchor();
904         this.anchorTarget = {
905             el: el,
906             alignment: alignment,
907             offsets: offsets
908         };
909
910         Ext.EventManager.onWindowResize(this.doAnchor, this);
911         var tm = typeof monitorScroll;
912         if(tm != 'undefined'){
913             Ext.EventManager.on(window, 'scroll', this.doAnchor, this,
914                 {buffer: tm == 'number' ? monitorScroll : 50});
915         }
916         return this.doAnchor();
917     },
918
919     /**
920      * Performs the anchor, using the saved anchorTarget property.
921      * @return {Ext.Window} this
922      * @private
923      */
924     doAnchor : function(){
925         var o = this.anchorTarget;
926         this.alignTo(o.el, o.alignment, o.offsets);
927         return this;
928     },
929
930     /**
931      * Removes any existing anchor from this window. See {@link #anchorTo}.
932      * @return {Ext.Window} this
933      */
934     clearAnchor : function(){
935         if(this.anchorTarget){
936             Ext.EventManager.removeResizeListener(this.doAnchor, this);
937             Ext.EventManager.un(window, 'scroll', this.doAnchor, this);
938             delete this.anchorTarget;
939         }
940         return this;
941     },
942
943     /**
944      * Brings this window to the front of any other visible windows
945      * @param {Boolean} e (optional) Specify <tt>false</tt> to prevent the window from being focused.
946      * @return {Ext.Window} this
947      */
948     toFront : function(e){
949         if(this.manager.bringToFront(this)){
950             if(!e || !e.getTarget().focus){
951                 this.focus();
952             }
953         }
954         return this;
955     },
956
957     /**
958      * Makes this the active window by showing its shadow, or deactivates it by hiding its shadow.  This method also
959      * fires the {@link #activate} or {@link #deactivate} event depending on which action occurred. This method is
960      * called internally by {@link Ext.WindowMgr}.
961      * @param {Boolean} active True to activate the window, false to deactivate it (defaults to false)
962      */
963     setActive : function(active){
964         if(active){
965             if(!this.maximized){
966                 this.el.enableShadow(true);
967             }
968             this.fireEvent('activate', this);
969         }else{
970             this.el.disableShadow();
971             this.fireEvent('deactivate', this);
972         }
973     },
974
975     /**
976      * Sends this window to the back of (lower z-index than) any other visible windows
977      * @return {Ext.Window} this
978      */
979     toBack : function(){
980         this.manager.sendToBack(this);
981         return this;
982     },
983
984     /**
985      * Centers this window in the viewport
986      * @return {Ext.Window} this
987      */
988     center : function(){
989         var xy = this.el.getAlignToXY(this.container, 'c-c');
990         this.setPagePosition(xy[0], xy[1]);
991         return this;
992     }
993
994     /**
995      * @cfg {Boolean} autoWidth @hide
996      **/
997 });
998 Ext.reg('window', Ext.Window);
999
1000 // private - custom Window DD implementation
1001 Ext.Window.DD = Ext.extend(Ext.dd.DD, {
1002     
1003     constructor : function(win){
1004         this.win = win;
1005         Ext.Window.DD.superclass.constructor.call(this, win.el.id, 'WindowDD-'+win.id);
1006         this.setHandleElId(win.header.id);
1007         this.scroll = false;        
1008     },
1009     
1010     moveOnly:true,
1011     headerOffsets:[100, 25],
1012     startDrag : function(){
1013         var w = this.win;
1014         this.proxy = w.ghost(w.initialConfig.cls);
1015         if(w.constrain !== false){
1016             var so = w.el.shadowOffset;
1017             this.constrainTo(w.container, {right: so, left: so, bottom: so});
1018         }else if(w.constrainHeader !== false){
1019             var s = this.proxy.getSize();
1020             this.constrainTo(w.container, {right: -(s.width-this.headerOffsets[0]), bottom: -(s.height-this.headerOffsets[1])});
1021         }
1022     },
1023     b4Drag : Ext.emptyFn,
1024
1025     onDrag : function(e){
1026         this.alignElWithMouse(this.proxy, e.getPageX(), e.getPageY());
1027     },
1028
1029     endDrag : function(e){
1030         this.win.unghost();
1031         this.win.saveState();
1032     }
1033 });
1034 /**
1035  * @class Ext.WindowGroup
1036  * An object that manages a group of {@link Ext.Window} instances and provides z-order management
1037  * and window activation behavior.
1038  * @constructor
1039  */
1040 Ext.WindowGroup = function(){
1041     var list = {};
1042     var accessList = [];
1043     var front = null;
1044
1045     // private
1046     var sortWindows = function(d1, d2){
1047         return (!d1._lastAccess || d1._lastAccess < d2._lastAccess) ? -1 : 1;
1048     };
1049
1050     // private
1051     var orderWindows = function(){
1052         var a = accessList, len = a.length;
1053         if(len > 0){
1054             a.sort(sortWindows);
1055             var seed = a[0].manager.zseed;
1056             for(var i = 0; i < len; i++){
1057                 var win = a[i];
1058                 if(win && !win.hidden){
1059                     win.setZIndex(seed + (i*10));
1060                 }
1061             }
1062         }
1063         activateLast();
1064     };
1065
1066     // private
1067     var setActiveWin = function(win){
1068         if(win != front){
1069             if(front){
1070                 front.setActive(false);
1071             }
1072             front = win;
1073             if(win){
1074                 win.setActive(true);
1075             }
1076         }
1077     };
1078
1079     // private
1080     var activateLast = function(){
1081         for(var i = accessList.length-1; i >=0; --i) {
1082             if(!accessList[i].hidden){
1083                 setActiveWin(accessList[i]);
1084                 return;
1085             }
1086         }
1087         // none to activate
1088         setActiveWin(null);
1089     };
1090
1091     return {
1092         /**
1093          * The starting z-index for windows in this WindowGroup (defaults to 9000)
1094          * @type Number The z-index value
1095          */
1096         zseed : 9000,
1097
1098         /**
1099          * <p>Registers a {@link Ext.Window Window} with this WindowManager. This should not
1100          * need to be called under normal circumstances. Windows are automatically registered
1101          * with a {@link Ext.Window#manager manager} at construction time.</p>
1102          * <p>Where this may be useful is moving Windows between two WindowManagers. For example,
1103          * to bring the Ext.MessageBox dialog under the same manager as the Desktop's
1104          * WindowManager in the desktop sample app:</p><code><pre>
1105 var msgWin = Ext.MessageBox.getDialog();
1106 MyDesktop.getDesktop().getManager().register(msgWin);
1107 </pre></code>
1108          * @param {Window} win The Window to register.
1109          */
1110         register : function(win){
1111             if(win.manager){
1112                 win.manager.unregister(win);
1113             }
1114             win.manager = this;
1115
1116             list[win.id] = win;
1117             accessList.push(win);
1118             win.on('hide', activateLast);
1119         },
1120
1121         /**
1122          * <p>Unregisters a {@link Ext.Window Window} from this WindowManager. This should not
1123          * need to be called. Windows are automatically unregistered upon destruction.
1124          * See {@link #register}.</p>
1125          * @param {Window} win The Window to unregister.
1126          */
1127         unregister : function(win){
1128             delete win.manager;
1129             delete list[win.id];
1130             win.un('hide', activateLast);
1131             accessList.remove(win);
1132         },
1133
1134         /**
1135          * Gets a registered window by id.
1136          * @param {String/Object} id The id of the window or a {@link Ext.Window} instance
1137          * @return {Ext.Window}
1138          */
1139         get : function(id){
1140             return typeof id == "object" ? id : list[id];
1141         },
1142
1143         /**
1144          * Brings the specified window to the front of any other active windows in this WindowGroup.
1145          * @param {String/Object} win The id of the window or a {@link Ext.Window} instance
1146          * @return {Boolean} True if the dialog was brought to the front, else false
1147          * if it was already in front
1148          */
1149         bringToFront : function(win){
1150             win = this.get(win);
1151             if(win != front){
1152                 win._lastAccess = new Date().getTime();
1153                 orderWindows();
1154                 return true;
1155             }
1156             return false;
1157         },
1158
1159         /**
1160          * Sends the specified window to the back of other active windows in this WindowGroup.
1161          * @param {String/Object} win The id of the window or a {@link Ext.Window} instance
1162          * @return {Ext.Window} The window
1163          */
1164         sendToBack : function(win){
1165             win = this.get(win);
1166             win._lastAccess = -(new Date().getTime());
1167             orderWindows();
1168             return win;
1169         },
1170
1171         /**
1172          * Hides all windows in this WindowGroup.
1173          */
1174         hideAll : function(){
1175             for(var id in list){
1176                 if(list[id] && typeof list[id] != "function" && list[id].isVisible()){
1177                     list[id].hide();
1178                 }
1179             }
1180         },
1181
1182         /**
1183          * Gets the currently-active window in this WindowGroup.
1184          * @return {Ext.Window} The active window
1185          */
1186         getActive : function(){
1187             return front;
1188         },
1189
1190         /**
1191          * Returns zero or more windows in this WindowGroup using the custom search function passed to this method.
1192          * The function should accept a single {@link Ext.Window} reference as its only argument and should
1193          * return true if the window matches the search criteria, otherwise it should return false.
1194          * @param {Function} fn The search function
1195          * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the Window being tested.
1196          * that gets passed to the function if not specified)
1197          * @return {Array} An array of zero or more matching windows
1198          */
1199         getBy : function(fn, scope){
1200             var r = [];
1201             for(var i = accessList.length-1; i >=0; --i) {
1202                 var win = accessList[i];
1203                 if(fn.call(scope||win, win) !== false){
1204                     r.push(win);
1205                 }
1206             }
1207             return r;
1208         },
1209
1210         /**
1211          * Executes the specified function once for every window in this WindowGroup, passing each
1212          * window as the only parameter. Returning false from the function will stop the iteration.
1213          * @param {Function} fn The function to execute for each item
1214          * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the current Window in the iteration.
1215          */
1216         each : function(fn, scope){
1217             for(var id in list){
1218                 if(list[id] && typeof list[id] != "function"){
1219                     if(fn.call(scope || list[id], list[id]) === false){
1220                         return;
1221                     }
1222                 }
1223             }
1224         }
1225     };
1226 };
1227
1228
1229 /**
1230  * @class Ext.WindowMgr
1231  * @extends Ext.WindowGroup
1232  * The default global window group that is available automatically.  To have more than one group of windows
1233  * with separate z-order stacks, create additional instances of {@link Ext.WindowGroup} as needed.
1234  * @singleton
1235  */
1236 Ext.WindowMgr = new Ext.WindowGroup();/**
1237  * @class Ext.MessageBox
1238  * <p>Utility class for generating different styles of message boxes.  The alias Ext.Msg can also be used.<p/>
1239  * <p>Note that the MessageBox is asynchronous.  Unlike a regular JavaScript <code>alert</code> (which will halt
1240  * browser execution), showing a MessageBox will not cause the code to stop.  For this reason, if you have code
1241  * that should only run <em>after</em> some user feedback from the MessageBox, you must use a callback function
1242  * (see the <code>function</code> parameter for {@link #show} for more details).</p>
1243  * <p>Example usage:</p>
1244  *<pre><code>
1245 // Basic alert:
1246 Ext.Msg.alert('Status', 'Changes saved successfully.');
1247
1248 // Prompt for user data and process the result using a callback:
1249 Ext.Msg.prompt('Name', 'Please enter your name:', function(btn, text){
1250     if (btn == 'ok'){
1251         // process text value and close...
1252     }
1253 });
1254
1255 // Show a dialog using config options:
1256 Ext.Msg.show({
1257    title:'Save Changes?',
1258    msg: 'You are closing a tab that has unsaved changes. Would you like to save your changes?',
1259    buttons: Ext.Msg.YESNOCANCEL,
1260    fn: processResult,
1261    animEl: 'elId',
1262    icon: Ext.MessageBox.QUESTION
1263 });
1264 </code></pre>
1265  * @singleton
1266  */
1267 Ext.MessageBox = function(){
1268     var dlg, opt, mask, waitTimer,
1269         bodyEl, msgEl, textboxEl, textareaEl, progressBar, pp, iconEl, spacerEl,
1270         buttons, activeTextEl, bwidth, bufferIcon = '', iconCls = '',
1271         buttonNames = ['ok', 'yes', 'no', 'cancel'];
1272
1273     // private
1274     var handleButton = function(button){
1275         buttons[button].blur();
1276         if(dlg.isVisible()){
1277             dlg.hide();
1278             handleHide();
1279             Ext.callback(opt.fn, opt.scope||window, [button, activeTextEl.dom.value, opt], 1);
1280         }
1281     };
1282
1283     // private
1284     var handleHide = function(){
1285         if(opt && opt.cls){
1286             dlg.el.removeClass(opt.cls);
1287         }
1288         progressBar.reset();        
1289     };
1290
1291     // private
1292     var handleEsc = function(d, k, e){
1293         if(opt && opt.closable !== false){
1294             dlg.hide();
1295             handleHide();
1296         }
1297         if(e){
1298             e.stopEvent();
1299         }
1300     };
1301
1302     // private
1303     var updateButtons = function(b){
1304         var width = 0,
1305             cfg;
1306         if(!b){
1307             Ext.each(buttonNames, function(name){
1308                 buttons[name].hide();
1309             });
1310             return width;
1311         }
1312         dlg.footer.dom.style.display = '';
1313         Ext.iterate(buttons, function(name, btn){
1314             cfg = b[name];
1315             if(cfg){
1316                 btn.show();
1317                 btn.setText(Ext.isString(cfg) ? cfg : Ext.MessageBox.buttonText[name]);
1318                 width += btn.getEl().getWidth() + 15;
1319             }else{
1320                 btn.hide();
1321             }
1322         });
1323         return width;
1324     };
1325
1326     return {
1327         /**
1328          * Returns a reference to the underlying {@link Ext.Window} element
1329          * @return {Ext.Window} The window
1330          */
1331         getDialog : function(titleText){
1332            if(!dlg){
1333                 var btns = [];
1334                 
1335                 buttons = {};
1336                 Ext.each(buttonNames, function(name){
1337                     btns.push(buttons[name] = new Ext.Button({
1338                         text: this.buttonText[name],
1339                         handler: handleButton.createCallback(name),
1340                         hideMode: 'offsets'
1341                     }));
1342                 }, this);
1343                 dlg = new Ext.Window({
1344                     autoCreate : true,
1345                     title:titleText,
1346                     resizable:false,
1347                     constrain:true,
1348                     constrainHeader:true,
1349                     minimizable : false,
1350                     maximizable : false,
1351                     stateful: false,
1352                     modal: true,
1353                     shim:true,
1354                     buttonAlign:"center",
1355                     width:400,
1356                     height:100,
1357                     minHeight: 80,
1358                     plain:true,
1359                     footer:true,
1360                     closable:true,
1361                     close : function(){
1362                         if(opt && opt.buttons && opt.buttons.no && !opt.buttons.cancel){
1363                             handleButton("no");
1364                         }else{
1365                             handleButton("cancel");
1366                         }
1367                     },
1368                     fbar: new Ext.Toolbar({
1369                         items: btns,
1370                         enableOverflow: false
1371                     })
1372                 });
1373                 dlg.render(document.body);
1374                 dlg.getEl().addClass('x-window-dlg');
1375                 mask = dlg.mask;
1376                 bodyEl = dlg.body.createChild({
1377                     html:'<div class="ext-mb-icon"></div><div class="ext-mb-content"><span class="ext-mb-text"></span><br /><div class="ext-mb-fix-cursor"><input type="text" class="ext-mb-input" /><textarea class="ext-mb-textarea"></textarea></div></div>'
1378                 });
1379                 iconEl = Ext.get(bodyEl.dom.firstChild);
1380                 var contentEl = bodyEl.dom.childNodes[1];
1381                 msgEl = Ext.get(contentEl.firstChild);
1382                 textboxEl = Ext.get(contentEl.childNodes[2].firstChild);
1383                 textboxEl.enableDisplayMode();
1384                 textboxEl.addKeyListener([10,13], function(){
1385                     if(dlg.isVisible() && opt && opt.buttons){
1386                         if(opt.buttons.ok){
1387                             handleButton("ok");
1388                         }else if(opt.buttons.yes){
1389                             handleButton("yes");
1390                         }
1391                     }
1392                 });
1393                 textareaEl = Ext.get(contentEl.childNodes[2].childNodes[1]);
1394                 textareaEl.enableDisplayMode();
1395                 progressBar = new Ext.ProgressBar({
1396                     renderTo:bodyEl
1397                 });
1398                bodyEl.createChild({cls:'x-clear'});
1399             }
1400             return dlg;
1401         },
1402
1403         /**
1404          * Updates the message box body text
1405          * @param {String} text (optional) Replaces the message box element's innerHTML with the specified string (defaults to
1406          * the XHTML-compliant non-breaking space character '&amp;#160;')
1407          * @return {Ext.MessageBox} this
1408          */
1409         updateText : function(text){
1410             if(!dlg.isVisible() && !opt.width){
1411                 dlg.setSize(this.maxWidth, 100); // resize first so content is never clipped from previous shows
1412             }
1413             // Append a space here for sizing. In IE, for some reason, it wraps text incorrectly without one in some cases
1414             msgEl.update(text ? text + ' ' : '&#160;');
1415
1416             var iw = iconCls != '' ? (iconEl.getWidth() + iconEl.getMargins('lr')) : 0,
1417                 mw = msgEl.getWidth() + msgEl.getMargins('lr'),
1418                 fw = dlg.getFrameWidth('lr'),
1419                 bw = dlg.body.getFrameWidth('lr'),
1420                 w;
1421                 
1422             w = Math.max(Math.min(opt.width || iw+mw+fw+bw, opt.maxWidth || this.maxWidth),
1423                     Math.max(opt.minWidth || this.minWidth, bwidth || 0));
1424
1425             if(opt.prompt === true){
1426                 activeTextEl.setWidth(w-iw-fw-bw);
1427             }
1428             if(opt.progress === true || opt.wait === true){
1429                 progressBar.setSize(w-iw-fw-bw);
1430             }
1431             if(Ext.isIE && w == bwidth){
1432                 w += 4; //Add offset when the content width is smaller than the buttons.    
1433             }
1434             msgEl.update(text || '&#160;');
1435             dlg.setSize(w, 'auto').center();
1436             return this;
1437         },
1438
1439         /**
1440          * Updates a progress-style message box's text and progress bar. Only relevant on message boxes
1441          * initiated via {@link Ext.MessageBox#progress} or {@link Ext.MessageBox#wait},
1442          * or by calling {@link Ext.MessageBox#show} with progress: true.
1443          * @param {Number} value Any number between 0 and 1 (e.g., .5, defaults to 0)
1444          * @param {String} progressText The progress text to display inside the progress bar (defaults to '')
1445          * @param {String} msg The message box's body text is replaced with the specified string (defaults to undefined
1446          * so that any existing body text will not get overwritten by default unless a new value is passed in)
1447          * @return {Ext.MessageBox} this
1448          */
1449         updateProgress : function(value, progressText, msg){
1450             progressBar.updateProgress(value, progressText);
1451             if(msg){
1452                 this.updateText(msg);
1453             }
1454             return this;
1455         },
1456
1457         /**
1458          * Returns true if the message box is currently displayed
1459          * @return {Boolean} True if the message box is visible, else false
1460          */
1461         isVisible : function(){
1462             return dlg && dlg.isVisible();
1463         },
1464
1465         /**
1466          * Hides the message box if it is displayed
1467          * @return {Ext.MessageBox} this
1468          */
1469         hide : function(){
1470             var proxy = dlg ? dlg.activeGhost : null;
1471             if(this.isVisible() || proxy){
1472                 dlg.hide();
1473                 handleHide();
1474                 if (proxy){
1475                     // unghost is a private function, but i saw no better solution
1476                     // to fix the locking problem when dragging while it closes
1477                     dlg.unghost(false, false);
1478                 } 
1479             }
1480             return this;
1481         },
1482
1483         /**
1484          * Displays a new message box, or reinitializes an existing message box, based on the config options
1485          * passed in. All display functions (e.g. prompt, alert, etc.) on MessageBox call this function internally,
1486          * although those calls are basic shortcuts and do not support all of the config options allowed here.
1487          * @param {Object} config The following config options are supported: <ul>
1488          * <li><b>animEl</b> : String/Element<div class="sub-desc">An id or Element from which the message box should animate as it
1489          * opens and closes (defaults to undefined)</div></li>
1490          * <li><b>buttons</b> : Object/Boolean<div class="sub-desc">A button config object (e.g., Ext.MessageBox.OKCANCEL or {ok:'Foo',
1491          * cancel:'Bar'}), or false to not show any buttons (defaults to false)</div></li>
1492          * <li><b>closable</b> : Boolean<div class="sub-desc">False to hide the top-right close button (defaults to true). Note that
1493          * progress and wait dialogs will ignore this property and always hide the close button as they can only
1494          * be closed programmatically.</div></li>
1495          * <li><b>cls</b> : String<div class="sub-desc">A custom CSS class to apply to the message box's container element</div></li>
1496          * <li><b>defaultTextHeight</b> : Number<div class="sub-desc">The default height in pixels of the message box's multiline textarea
1497          * if displayed (defaults to 75)</div></li>
1498          * <li><b>fn</b> : Function<div class="sub-desc">A callback function which is called when the dialog is dismissed either
1499          * by clicking on the configured buttons, or on the dialog close button, or by pressing
1500          * the return button to enter input.
1501          * <p>Progress and wait dialogs will ignore this option since they do not respond to user
1502          * actions and can only be closed programmatically, so any required function should be called
1503          * by the same code after it closes the dialog. Parameters passed:<ul>
1504          * <li><b>buttonId</b> : String<div class="sub-desc">The ID of the button pressed, one of:<div class="sub-desc"><ul>
1505          * <li><tt>ok</tt></li>
1506          * <li><tt>yes</tt></li>
1507          * <li><tt>no</tt></li>
1508          * <li><tt>cancel</tt></li>
1509          * </ul></div></div></li>
1510          * <li><b>text</b> : String<div class="sub-desc">Value of the input field if either <tt><a href="#show-option-prompt" ext:member="show-option-prompt" ext:cls="Ext.MessageBox">prompt</a></tt>
1511          * or <tt><a href="#show-option-multiline" ext:member="show-option-multiline" ext:cls="Ext.MessageBox">multiline</a></tt> is true</div></li>
1512          * <li><b>opt</b> : Object<div class="sub-desc">The config object passed to show.</div></li>
1513          * </ul></p></div></li>
1514          * <li><b>scope</b> : Object<div class="sub-desc">The scope of the callback function</div></li>
1515          * <li><b>icon</b> : String<div class="sub-desc">A CSS class that provides a background image to be used as the body icon for the
1516          * dialog (e.g. Ext.MessageBox.WARNING or 'custom-class') (defaults to '')</div></li>
1517          * <li><b>iconCls</b> : String<div class="sub-desc">The standard {@link Ext.Window#iconCls} to
1518          * add an optional header icon (defaults to '')</div></li>
1519          * <li><b>maxWidth</b> : Number<div class="sub-desc">The maximum width in pixels of the message box (defaults to 600)</div></li>
1520          * <li><b>minWidth</b> : Number<div class="sub-desc">The minimum width in pixels of the message box (defaults to 100)</div></li>
1521          * <li><b>modal</b> : Boolean<div class="sub-desc">False to allow user interaction with the page while the message box is
1522          * displayed (defaults to true)</div></li>
1523          * <li><b>msg</b> : String<div class="sub-desc">A string that will replace the existing message box body text (defaults to the
1524          * XHTML-compliant non-breaking space character '&amp;#160;')</div></li>
1525          * <li><a id="show-option-multiline"></a><b>multiline</b> : Boolean<div class="sub-desc">
1526          * True to prompt the user to enter multi-line text (defaults to false)</div></li>
1527          * <li><b>progress</b> : Boolean<div class="sub-desc">True to display a progress bar (defaults to false)</div></li>
1528          * <li><b>progressText</b> : String<div class="sub-desc">The text to display inside the progress bar if progress = true (defaults to '')</div></li>
1529          * <li><a id="show-option-prompt"></a><b>prompt</b> : Boolean<div class="sub-desc">True to prompt the user to enter single-line text (defaults to false)</div></li>
1530          * <li><b>proxyDrag</b> : Boolean<div class="sub-desc">True to display a lightweight proxy while dragging (defaults to false)</div></li>
1531          * <li><b>title</b> : String<div class="sub-desc">The title text</div></li>
1532          * <li><b>value</b> : String<div class="sub-desc">The string value to set into the active textbox element if displayed</div></li>
1533          * <li><b>wait</b> : Boolean<div class="sub-desc">True to display a progress bar (defaults to false)</div></li>
1534          * <li><b>waitConfig</b> : Object<div class="sub-desc">A {@link Ext.ProgressBar#waitConfig} object (applies only if wait = true)</div></li>
1535          * <li><b>width</b> : Number<div class="sub-desc">The width of the dialog in pixels</div></li>
1536          * </ul>
1537          * Example usage:
1538          * <pre><code>
1539 Ext.Msg.show({
1540    title: 'Address',
1541    msg: 'Please enter your address:',
1542    width: 300,
1543    buttons: Ext.MessageBox.OKCANCEL,
1544    multiline: true,
1545    fn: saveAddress,
1546    animEl: 'addAddressBtn',
1547    icon: Ext.MessageBox.INFO
1548 });
1549 </code></pre>
1550          * @return {Ext.MessageBox} this
1551          */
1552         show : function(options){
1553             if(this.isVisible()){
1554                 this.hide();
1555             }
1556             opt = options;
1557             var d = this.getDialog(opt.title || "&#160;");
1558
1559             d.setTitle(opt.title || "&#160;");
1560             var allowClose = (opt.closable !== false && opt.progress !== true && opt.wait !== true);
1561             d.tools.close.setDisplayed(allowClose);
1562             activeTextEl = textboxEl;
1563             opt.prompt = opt.prompt || (opt.multiline ? true : false);
1564             if(opt.prompt){
1565                 if(opt.multiline){
1566                     textboxEl.hide();
1567                     textareaEl.show();
1568                     textareaEl.setHeight(Ext.isNumber(opt.multiline) ? opt.multiline : this.defaultTextHeight);
1569                     activeTextEl = textareaEl;
1570                 }else{
1571                     textboxEl.show();
1572                     textareaEl.hide();
1573                 }
1574             }else{
1575                 textboxEl.hide();
1576                 textareaEl.hide();
1577             }
1578             activeTextEl.dom.value = opt.value || "";
1579             if(opt.prompt){
1580                 d.focusEl = activeTextEl;
1581             }else{
1582                 var bs = opt.buttons;
1583                 var db = null;
1584                 if(bs && bs.ok){
1585                     db = buttons["ok"];
1586                 }else if(bs && bs.yes){
1587                     db = buttons["yes"];
1588                 }
1589                 if (db){
1590                     d.focusEl = db;
1591                 }
1592             }
1593             if(Ext.isDefined(opt.iconCls)){
1594               d.setIconClass(opt.iconCls);
1595             }
1596             this.setIcon(Ext.isDefined(opt.icon) ? opt.icon : bufferIcon);
1597             bwidth = updateButtons(opt.buttons);
1598             progressBar.setVisible(opt.progress === true || opt.wait === true);
1599             this.updateProgress(0, opt.progressText);
1600             this.updateText(opt.msg);
1601             if(opt.cls){
1602                 d.el.addClass(opt.cls);
1603             }
1604             d.proxyDrag = opt.proxyDrag === true;
1605             d.modal = opt.modal !== false;
1606             d.mask = opt.modal !== false ? mask : false;
1607             if(!d.isVisible()){
1608                 // force it to the end of the z-index stack so it gets a cursor in FF
1609                 document.body.appendChild(dlg.el.dom);
1610                 d.setAnimateTarget(opt.animEl);
1611                 //workaround for window internally enabling keymap in afterShow
1612                 d.on('show', function(){
1613                     if(allowClose === true){
1614                         d.keyMap.enable();
1615                     }else{
1616                         d.keyMap.disable();
1617                     }
1618                 }, this, {single:true});
1619                 d.show(opt.animEl);
1620             }
1621             if(opt.wait === true){
1622                 progressBar.wait(opt.waitConfig);
1623             }
1624             return this;
1625         },
1626
1627         /**
1628          * Adds the specified icon to the dialog.  By default, the class 'ext-mb-icon' is applied for default
1629          * styling, and the class passed in is expected to supply the background image url. Pass in empty string ('')
1630          * to clear any existing icon. This method must be called before the MessageBox is shown.
1631          * The following built-in icon classes are supported, but you can also pass in a custom class name:
1632          * <pre>
1633 Ext.MessageBox.INFO
1634 Ext.MessageBox.WARNING
1635 Ext.MessageBox.QUESTION
1636 Ext.MessageBox.ERROR
1637          *</pre>
1638          * @param {String} icon A CSS classname specifying the icon's background image url, or empty string to clear the icon
1639          * @return {Ext.MessageBox} this
1640          */
1641         setIcon : function(icon){
1642             if(!dlg){
1643                 bufferIcon = icon;
1644                 return;
1645             }
1646             bufferIcon = undefined;
1647             if(icon && icon != ''){
1648                 iconEl.removeClass('x-hidden');
1649                 iconEl.replaceClass(iconCls, icon);
1650                 bodyEl.addClass('x-dlg-icon');
1651                 iconCls = icon;
1652             }else{
1653                 iconEl.replaceClass(iconCls, 'x-hidden');
1654                 bodyEl.removeClass('x-dlg-icon');
1655                 iconCls = '';
1656             }
1657             return this;
1658         },
1659
1660         /**
1661          * Displays a message box with a progress bar.  This message box has no buttons and is not closeable by
1662          * the user.  You are responsible for updating the progress bar as needed via {@link Ext.MessageBox#updateProgress}
1663          * and closing the message box when the process is complete.
1664          * @param {String} title The title bar text
1665          * @param {String} msg The message box body text
1666          * @param {String} progressText (optional) The text to display inside the progress bar (defaults to '')
1667          * @return {Ext.MessageBox} this
1668          */
1669         progress : function(title, msg, progressText){
1670             this.show({
1671                 title : title,
1672                 msg : msg,
1673                 buttons: false,
1674                 progress:true,
1675                 closable:false,
1676                 minWidth: this.minProgressWidth,
1677                 progressText: progressText
1678             });
1679             return this;
1680         },
1681
1682         /**
1683          * Displays a message box with an infinitely auto-updating progress bar.  This can be used to block user
1684          * interaction while waiting for a long-running process to complete that does not have defined intervals.
1685          * You are responsible for closing the message box when the process is complete.
1686          * @param {String} msg The message box body text
1687          * @param {String} title (optional) The title bar text
1688          * @param {Object} config (optional) A {@link Ext.ProgressBar#waitConfig} object
1689          * @return {Ext.MessageBox} this
1690          */
1691         wait : function(msg, title, config){
1692             this.show({
1693                 title : title,
1694                 msg : msg,
1695                 buttons: false,
1696                 closable:false,
1697                 wait:true,
1698                 modal:true,
1699                 minWidth: this.minProgressWidth,
1700                 waitConfig: config
1701             });
1702             return this;
1703         },
1704
1705         /**
1706          * Displays a standard read-only message box with an OK button (comparable to the basic JavaScript alert prompt).
1707          * If a callback function is passed it will be called after the user clicks the button, and the
1708          * id of the button that was clicked will be passed as the only parameter to the callback
1709          * (could also be the top-right close button).
1710          * @param {String} title The title bar text
1711          * @param {String} msg The message box body text
1712          * @param {Function} fn (optional) The callback function invoked after the message box is closed
1713          * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to the browser wnidow.
1714          * @return {Ext.MessageBox} this
1715          */
1716         alert : function(title, msg, fn, scope){
1717             this.show({
1718                 title : title,
1719                 msg : msg,
1720                 buttons: this.OK,
1721                 fn: fn,
1722                 scope : scope,
1723                 minWidth: this.minWidth
1724             });
1725             return this;
1726         },
1727
1728         /**
1729          * Displays a confirmation message box with Yes and No buttons (comparable to JavaScript's confirm).
1730          * If a callback function is passed it will be called after the user clicks either button,
1731          * and the id of the button that was clicked will be passed as the only parameter to the callback
1732          * (could also be the top-right close button).
1733          * @param {String} title The title bar text
1734          * @param {String} msg The message box body text
1735          * @param {Function} fn (optional) The callback function invoked after the message box is closed
1736          * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to the browser wnidow.
1737          * @return {Ext.MessageBox} this
1738          */
1739         confirm : function(title, msg, fn, scope){
1740             this.show({
1741                 title : title,
1742                 msg : msg,
1743                 buttons: this.YESNO,
1744                 fn: fn,
1745                 scope : scope,
1746                 icon: this.QUESTION,
1747                 minWidth: this.minWidth
1748             });
1749             return this;
1750         },
1751
1752         /**
1753          * Displays a message box with OK and Cancel buttons prompting the user to enter some text (comparable to JavaScript's prompt).
1754          * The prompt can be a single-line or multi-line textbox.  If a callback function is passed it will be called after the user
1755          * clicks either button, and the id of the button that was clicked (could also be the top-right
1756          * close button) and the text that was entered will be passed as the two parameters to the callback.
1757          * @param {String} title The title bar text
1758          * @param {String} msg The message box body text
1759          * @param {Function} fn (optional) The callback function invoked after the message box is closed
1760          * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to the browser wnidow.
1761          * @param {Boolean/Number} multiline (optional) True to create a multiline textbox using the defaultTextHeight
1762          * property, or the height in pixels to create the textbox (defaults to false / single-line)
1763          * @param {String} value (optional) Default value of the text input element (defaults to '')
1764          * @return {Ext.MessageBox} this
1765          */
1766         prompt : function(title, msg, fn, scope, multiline, value){
1767             this.show({
1768                 title : title,
1769                 msg : msg,
1770                 buttons: this.OKCANCEL,
1771                 fn: fn,
1772                 minWidth: this.minPromptWidth,
1773                 scope : scope,
1774                 prompt:true,
1775                 multiline: multiline,
1776                 value: value
1777             });
1778             return this;
1779         },
1780
1781         /**
1782          * Button config that displays a single OK button
1783          * @type Object
1784          */
1785         OK : {ok:true},
1786         /**
1787          * Button config that displays a single Cancel button
1788          * @type Object
1789          */
1790         CANCEL : {cancel:true},
1791         /**
1792          * Button config that displays OK and Cancel buttons
1793          * @type Object
1794          */
1795         OKCANCEL : {ok:true, cancel:true},
1796         /**
1797          * Button config that displays Yes and No buttons
1798          * @type Object
1799          */
1800         YESNO : {yes:true, no:true},
1801         /**
1802          * Button config that displays Yes, No and Cancel buttons
1803          * @type Object
1804          */
1805         YESNOCANCEL : {yes:true, no:true, cancel:true},
1806         /**
1807          * The CSS class that provides the INFO icon image
1808          * @type String
1809          */
1810         INFO : 'ext-mb-info',
1811         /**
1812          * The CSS class that provides the WARNING icon image
1813          * @type String
1814          */
1815         WARNING : 'ext-mb-warning',
1816         /**
1817          * The CSS class that provides the QUESTION icon image
1818          * @type String
1819          */
1820         QUESTION : 'ext-mb-question',
1821         /**
1822          * The CSS class that provides the ERROR icon image
1823          * @type String
1824          */
1825         ERROR : 'ext-mb-error',
1826
1827         /**
1828          * The default height in pixels of the message box's multiline textarea if displayed (defaults to 75)
1829          * @type Number
1830          */
1831         defaultTextHeight : 75,
1832         /**
1833          * The maximum width in pixels of the message box (defaults to 600)
1834          * @type Number
1835          */
1836         maxWidth : 600,
1837         /**
1838          * The minimum width in pixels of the message box (defaults to 100)
1839          * @type Number
1840          */
1841         minWidth : 100,
1842         /**
1843          * The minimum width in pixels of the message box if it is a progress-style dialog.  This is useful
1844          * for setting a different minimum width than text-only dialogs may need (defaults to 250).
1845          * @type Number
1846          */
1847         minProgressWidth : 250,
1848         /**
1849          * The minimum width in pixels of the message box if it is a prompt dialog.  This is useful
1850          * for setting a different minimum width than text-only dialogs may need (defaults to 250).
1851          * @type Number
1852          */
1853         minPromptWidth: 250,
1854         /**
1855          * An object containing the default button text strings that can be overriden for localized language support.
1856          * Supported properties are: ok, cancel, yes and no.  Generally you should include a locale-specific
1857          * resource file for handling language support across the framework.
1858          * Customize the default text like so: Ext.MessageBox.buttonText.yes = "oui"; //french
1859          * @type Object
1860          */
1861         buttonText : {
1862             ok : "OK",
1863             cancel : "Cancel",
1864             yes : "Yes",
1865             no : "No"
1866         }
1867     };
1868 }();
1869
1870 /**
1871  * Shorthand for {@link Ext.MessageBox}
1872  */
1873 Ext.Msg = Ext.MessageBox;/**
1874  * @class Ext.dd.PanelProxy
1875  * A custom drag proxy implementation specific to {@link Ext.Panel}s. This class is primarily used internally
1876  * for the Panel's drag drop implementation, and should never need to be created directly.
1877  * @constructor
1878  * @param panel The {@link Ext.Panel} to proxy for
1879  * @param config Configuration options
1880  */
1881 Ext.dd.PanelProxy  = Ext.extend(Object, {
1882     
1883     constructor : function(panel, config){
1884         this.panel = panel;
1885         this.id = this.panel.id +'-ddproxy';
1886         Ext.apply(this, config);        
1887     },
1888     
1889     /**
1890      * @cfg {Boolean} insertProxy True to insert a placeholder proxy element while dragging the panel,
1891      * false to drag with no proxy (defaults to true).
1892      */
1893     insertProxy : true,
1894
1895     // private overrides
1896     setStatus : Ext.emptyFn,
1897     reset : Ext.emptyFn,
1898     update : Ext.emptyFn,
1899     stop : Ext.emptyFn,
1900     sync: Ext.emptyFn,
1901
1902     /**
1903      * Gets the proxy's element
1904      * @return {Element} The proxy's element
1905      */
1906     getEl : function(){
1907         return this.ghost;
1908     },
1909
1910     /**
1911      * Gets the proxy's ghost element
1912      * @return {Element} The proxy's ghost element
1913      */
1914     getGhost : function(){
1915         return this.ghost;
1916     },
1917
1918     /**
1919      * Gets the proxy's element
1920      * @return {Element} The proxy's element
1921      */
1922     getProxy : function(){
1923         return this.proxy;
1924     },
1925
1926     /**
1927      * Hides the proxy
1928      */
1929     hide : function(){
1930         if(this.ghost){
1931             if(this.proxy){
1932                 this.proxy.remove();
1933                 delete this.proxy;
1934             }
1935             this.panel.el.dom.style.display = '';
1936             this.ghost.remove();
1937             delete this.ghost;
1938         }
1939     },
1940
1941     /**
1942      * Shows the proxy
1943      */
1944     show : function(){
1945         if(!this.ghost){
1946             this.ghost = this.panel.createGhost(this.panel.initialConfig.cls, undefined, Ext.getBody());
1947             this.ghost.setXY(this.panel.el.getXY());
1948             if(this.insertProxy){
1949                 this.proxy = this.panel.el.insertSibling({cls:'x-panel-dd-spacer'});
1950                 this.proxy.setSize(this.panel.getSize());
1951             }
1952             this.panel.el.dom.style.display = 'none';
1953         }
1954     },
1955
1956     // private
1957     repair : function(xy, callback, scope){
1958         this.hide();
1959         if(typeof callback == "function"){
1960             callback.call(scope || this);
1961         }
1962     },
1963
1964     /**
1965      * Moves the proxy to a different position in the DOM.  This is typically called while dragging the Panel
1966      * to keep the proxy sync'd to the Panel's location.
1967      * @param {HTMLElement} parentNode The proxy's parent DOM node
1968      * @param {HTMLElement} before (optional) The sibling node before which the proxy should be inserted (defaults
1969      * to the parent's last child if not specified)
1970      */
1971     moveProxy : function(parentNode, before){
1972         if(this.proxy){
1973             parentNode.insertBefore(this.proxy.dom, before);
1974         }
1975     }
1976 });
1977
1978 // private - DD implementation for Panels
1979 Ext.Panel.DD = Ext.extend(Ext.dd.DragSource, {
1980     
1981     constructor : function(panel, cfg){
1982         this.panel = panel;
1983         this.dragData = {panel: panel};
1984         this.proxy = new Ext.dd.PanelProxy(panel, cfg);
1985         Ext.Panel.DD.superclass.constructor.call(this, panel.el, cfg);
1986         var h = panel.header,
1987             el = panel.body;
1988         if(h){
1989             this.setHandleElId(h.id);
1990             el = panel.header;
1991         }
1992         el.setStyle('cursor', 'move');
1993         this.scroll = false;        
1994     },
1995     
1996     showFrame: Ext.emptyFn,
1997     startDrag: Ext.emptyFn,
1998     b4StartDrag: function(x, y) {
1999         this.proxy.show();
2000     },
2001     b4MouseDown: function(e) {
2002         var x = e.getPageX(),
2003             y = e.getPageY();
2004         this.autoOffset(x, y);
2005     },
2006     onInitDrag : function(x, y){
2007         this.onStartDrag(x, y);
2008         return true;
2009     },
2010     createFrame : Ext.emptyFn,
2011     getDragEl : function(e){
2012         return this.proxy.ghost.dom;
2013     },
2014     endDrag : function(e){
2015         this.proxy.hide();
2016         this.panel.saveState();
2017     },
2018
2019     autoOffset : function(x, y) {
2020         x -= this.startPageX;
2021         y -= this.startPageY;
2022         this.setDelta(x, y);
2023     }
2024 });