Upgrade to ExtJS 3.1.0 - Released 12/16/2009
[extjs.git] / pkgs / window-debug.js
index 7273d54..0461d5e 100644 (file)
@@ -1,5 +1,5 @@
 /*!
- * Ext JS Library 3.0.3
+ * Ext JS Library 3.1.0
  * Copyright(c) 2006-2009 Ext JS, LLC
  * licensing@extjs.com
  * http://www.extjs.com/license
@@ -50,8 +50,13 @@ Ext.Window = Ext.extend(Ext.Panel, {
      * A reference to the WindowGroup that should manage this window (defaults to {@link Ext.WindowMgr}).
      */
     /**
-    * @cfg {String/Number/Button} defaultButton
-    * The id / index of a button or a button instance to focus when this window received the focus.
+    * @cfg {String/Number/Component} defaultButton
+    * <p>Specifies a Component to receive focus when this Window is focussed.</p>
+    * <p>This may be one of:</p><div class="mdetail-params"><ul>
+    * <li>The index of a footer Button.</li>
+    * <li>The id of a Component.</li>
+    * <li>A Component.</li>
+    * </ul></div>
     */
     /**
     * @cfg {Function} onEsc
@@ -183,14 +188,14 @@ Ext.Window = Ext.extend(Ext.Panel, {
      * @deprecated
      */
     initHidden : undefined,
-    
+
     /**
      * @cfg {Boolean} hidden
      * Render this component hidden (default is <tt>true</tt>). If <tt>true</tt>, the
      * {@link #hide} method will be called internally.
      */
     hidden : true,
-    
+
     /**
     * @cfg {Boolean} monitorResize @hide
     * This is automatically managed based on the value of constrain and constrainToHeader
@@ -432,7 +437,6 @@ Ext.Window = Ext.extend(Ext.Panel, {
         this.focus();
         this.updateHandles();
         this.saveState();
-        this.doLayout();
     },
 
     /**
@@ -491,7 +495,7 @@ Ext.Window = Ext.extend(Ext.Panel, {
      * @param {String/Element} animateTarget (optional) The target element or id from which the window should
      * animate while opening (defaults to null with no animation)
      * @param {Function} callback (optional) A callback function to call after the window is displayed
-     * @param {Object} scope (optional) The scope in which to execute the callback
+     * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to this Window.
      * @return {Ext.Window} this
      */
     show : function(animateTarget, cb, scope){
@@ -529,7 +533,7 @@ Ext.Window = Ext.extend(Ext.Panel, {
         if(this.maximized){
             this.fitContainer();
         }
-        if(Ext.isMac && Ext.isGecko){ // work around stupid FF 2.0/Mac scroll bar bug
+        if(Ext.isMac && Ext.isGecko2){ // work around stupid FF 2.0/Mac scroll bar bug
             this.cascade(this.setAutoScroll);
         }
 
@@ -547,6 +551,7 @@ Ext.Window = Ext.extend(Ext.Panel, {
             var sz = this.getSize();
             this.onResize(sz.width, sz.height);
         }
+        this.onShow();
         this.fireEvent('show', this);
     },
 
@@ -571,7 +576,7 @@ Ext.Window = Ext.extend(Ext.Panel, {
      * @param {String/Element} animateTarget (optional) The target element or id to which the window should
      * animate while hiding (defaults to null with no animation)
      * @param {Function} callback (optional) A callback function to call after the window is hidden
-     * @param {Object} scope (optional) The scope in which to execute the callback
+     * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to this Window.
      * @return {Ext.Window} this
      */
     hide : function(animateTarget, cb, scope){
@@ -607,6 +612,7 @@ Ext.Window = Ext.extend(Ext.Panel, {
         if(this.keyMap){
             this.keyMap.disable();
         }
+        this.onHide();
         this.fireEvent('hide', this);
     },
 
@@ -626,6 +632,18 @@ Ext.Window = Ext.extend(Ext.Panel, {
         }));
     },
 
+    /**
+     * Method that is called immediately before the <code>show</code> event is fired.
+     * Defaults to <code>Ext.emptyFn</code>.
+     */
+    onShow : Ext.emptyFn,
+
+    /**
+     * Method that is called immediately before the <code>hide</code> event is fired.
+     * Defaults to <code>Ext.emptyFn</code>.
+     */
+    onHide : Ext.emptyFn,
+
     // private
     onWindowResize : function(){
         if(this.maximized){
@@ -683,7 +701,7 @@ Ext.Window = Ext.extend(Ext.Panel, {
         if(show !== false){
             this.el.show();
             this.focus();
-            if(Ext.isMac && Ext.isGecko){ // work around stupid FF 2.0/Mac scroll bar bug
+            if(Ext.isMac && Ext.isGecko2){ // work around stupid FF 2.0/Mac scroll bar bug
                 this.cascade(this.setAutoScroll);
             }
         }
@@ -723,7 +741,7 @@ Ext.Window = Ext.extend(Ext.Panel, {
             }
         }
     },
-    
+
     // private
     doClose : function(){
         this.fireEvent('close', this);
@@ -773,9 +791,14 @@ Ext.Window = Ext.extend(Ext.Panel, {
      */
     restore : function(){
         if(this.maximized){
+            var t = this.tools;
             this.el.removeClass('x-window-maximized');
-            this.tools.restore.hide();
-            this.tools.maximize.show();
+            if(t.restore){
+                t.restore.hide();
+            }
+            if(t.maximize){
+                t.maximize.show();
+            }
             this.setPosition(this.restorePos[0], this.restorePos[1]);
             this.setSize(this.restoreSize.width, this.restoreSize.height);
             delete this.restorePos;
@@ -786,8 +809,8 @@ Ext.Window = Ext.extend(Ext.Panel, {
             if(this.dd){
                 this.dd.unlock();
             }
-            if(this.collapsible){
-                this.tools.toggle.show();
+            if(this.collapsible && t.toggle){
+                t.toggle.show();
             }
             this.container.removeClass('x-window-maximized-ct');
 
@@ -808,7 +831,7 @@ Ext.Window = Ext.extend(Ext.Panel, {
 
     // private
     fitContainer : function(){
-        var vs = this.container.getViewSize();
+        var vs = this.container.getViewSize(false);
         this.setSize(vs.width, vs.height);
     },
 
@@ -831,7 +854,7 @@ Ext.Window = Ext.extend(Ext.Panel, {
     /**
      * Aligns the window to the specified element
      * @param {Mixed} element The element to align to.
-     * @param {String} position The position to align to (see {@link Ext.Element#alignTo} for more details).
+     * @param {String} position (optional, defaults to "tl-bl?") The position to align to (see {@link Ext.Element#alignTo} for more details).
      * @param {Array} offsets (optional) Offset the positioning by [x, y]
      * @return {Ext.Window} this
      */
@@ -961,7 +984,7 @@ Ext.extend(Ext.Window.DD, Ext.dd.DD, {
 });
 /**
  * @class Ext.WindowGroup
- * An object that represents a group of {@link Ext.Window} instances and provides z-order management
+ * An object that manages a group of {@link Ext.Window} instances and provides z-order management
  * and window activation behavior.
  * @constructor
  */
@@ -1018,20 +1041,42 @@ Ext.WindowGroup = function(){
 
     return {
         /**
-         * The starting z-index for windows (defaults to 9000)
+         * The starting z-index for windows in this WindowGroup (defaults to 9000)
          * @type Number The z-index value
          */
         zseed : 9000,
 
-        // private
+        /**
+         * <p>Registers a {@link Ext.Window Window} with this WindowManager. This should not
+         * need to be called under normal circumstances. Windows are automatically registered
+         * with a {@link Ext.Window#manager manager} at construction time.</p>
+         * <p>Where this may be useful is moving Windows between two WindowManagers. For example,
+         * to bring the Ext.MessageBox dialog under the same manager as the Desktop's
+         * WindowManager in the desktop sample app:</p><code><pre>
+var msgWin = Ext.MessageBox.getDialog();
+MyDesktop.getDesktop().getManager().register(msgWin);
+</pre></code>
+         * @param {Window} win The Window to register.
+         */
         register : function(win){
+            if(win.manager){
+                win.manager.unregister(win);
+            }
+            win.manager = this;
+
             list[win.id] = win;
             accessList.push(win);
             win.on('hide', activateLast);
         },
 
-        // private
+        /**
+         * <p>Unregisters a {@link Ext.Window Window} from this WindowManager. This should not
+         * need to be called. Windows are automatically unregistered upon destruction.
+         * See {@link #register}.</p>
+         * @param {Window} win The Window to unregister.
+         */
         unregister : function(win){
+            delete win.manager;
             delete list[win.id];
             win.un('hide', activateLast);
             accessList.remove(win);
@@ -1047,7 +1092,7 @@ Ext.WindowGroup = function(){
         },
 
         /**
-         * Brings the specified window to the front of any other active windows.
+         * Brings the specified window to the front of any other active windows in this WindowGroup.
          * @param {String/Object} win The id of the window or a {@link Ext.Window} instance
          * @return {Boolean} True if the dialog was brought to the front, else false
          * if it was already in front
@@ -1063,7 +1108,7 @@ Ext.WindowGroup = function(){
         },
 
         /**
-         * Sends the specified window to the back of other active windows.
+         * Sends the specified window to the back of other active windows in this WindowGroup.
          * @param {String/Object} win The id of the window or a {@link Ext.Window} instance
          * @return {Ext.Window} The window
          */
@@ -1075,7 +1120,7 @@ Ext.WindowGroup = function(){
         },
 
         /**
-         * Hides all windows in the group.
+         * Hides all windows in this WindowGroup.
          */
         hideAll : function(){
             for(var id in list){
@@ -1086,7 +1131,7 @@ Ext.WindowGroup = function(){
         },
 
         /**
-         * Gets the currently-active window in the group.
+         * Gets the currently-active window in this WindowGroup.
          * @return {Ext.Window} The active window
          */
         getActive : function(){
@@ -1094,11 +1139,11 @@ Ext.WindowGroup = function(){
         },
 
         /**
-         * Returns zero or more windows in the group using the custom search function passed to this method.
+         * Returns zero or more windows in this WindowGroup using the custom search function passed to this method.
          * The function should accept a single {@link Ext.Window} reference as its only argument and should
          * return true if the window matches the search criteria, otherwise it should return false.
          * @param {Function} fn The search function
-         * @param {Object} scope (optional) The scope in which to execute the function (defaults to the window
+         * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the Window being tested.
          * that gets passed to the function if not specified)
          * @return {Array} An array of zero or more matching windows
          */
@@ -1114,10 +1159,10 @@ Ext.WindowGroup = function(){
         },
 
         /**
-         * Executes the specified function once for every window in the group, passing each
+         * Executes the specified function once for every window in this WindowGroup, passing each
          * window as the only parameter. Returning false from the function will stop the iteration.
          * @param {Function} fn The function to execute for each item
-         * @param {Object} scope (optional) The scope in which to execute the function
+         * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the current Window in the iteration.
          */
         each : function(fn, scope){
             for(var id in list){
@@ -1173,10 +1218,12 @@ Ext.Msg.show({
 Ext.MessageBox = function(){\r
     var dlg, opt, mask, waitTimer,\r
         bodyEl, msgEl, textboxEl, textareaEl, progressBar, pp, iconEl, spacerEl,\r
-        buttons, activeTextEl, bwidth, bufferIcon = '', iconCls = '';\r
+        buttons, activeTextEl, bwidth, bufferIcon = '', iconCls = '',\r
+        buttonNames = ['ok', 'yes', 'no', 'cancel'];\r
 \r
     // private\r
     var handleButton = function(button){\r
+        buttons[button].blur();\r
         if(dlg.isVisible()){\r
             dlg.hide();\r
             handleHide();\r
@@ -1189,7 +1236,7 @@ Ext.MessageBox = function(){
         if(opt && opt.cls){\r
             dlg.el.removeClass(opt.cls);\r
         }\r
-        progressBar.reset();\r
+        progressBar.reset();        \r
     };\r
 \r
     // private\r
@@ -1205,26 +1252,25 @@ Ext.MessageBox = function(){
 \r
     // private\r
     var updateButtons = function(b){\r
-        var width = 0;\r
+        var width = 0,\r
+            cfg;\r
         if(!b){\r
-            buttons["ok"].hide();\r
-            buttons["cancel"].hide();\r
-            buttons["yes"].hide();\r
-            buttons["no"].hide();\r
+            Ext.each(buttonNames, function(name){\r
+                buttons[name].hide();\r
+            });\r
             return width;\r
         }\r
         dlg.footer.dom.style.display = '';\r
-        for(var k in buttons){\r
-            if(!Ext.isFunction(buttons[k])){\r
-                if(b[k]){\r
-                    buttons[k].show();\r
-                    buttons[k].setText(Ext.isString(b[k]) ? b[k] : Ext.MessageBox.buttonText[k]);\r
-                    width += buttons[k].el.getWidth()+15;\r
-                }else{\r
-                    buttons[k].hide();\r
-                }\r
+        Ext.iterate(buttons, function(name, btn){\r
+            cfg = b[name];\r
+            if(cfg){\r
+                btn.show();\r
+                btn.setText(Ext.isString(cfg) ? cfg : Ext.MessageBox.buttonText[name]);\r
+                width += btn.getEl().getWidth() + 15;\r
+            }else{\r
+                btn.hide();\r
             }\r
-        }\r
+        });\r
         return width;\r
     };\r
 \r
@@ -1235,6 +1281,16 @@ Ext.MessageBox = function(){
          */\r
         getDialog : function(titleText){\r
            if(!dlg){\r
+                var btns = [];\r
+                \r
+                buttons = {};\r
+                Ext.each(buttonNames, function(name){\r
+                    btns.push(buttons[name] = new Ext.Button({\r
+                        text: this.buttonText[name],\r
+                        handler: handleButton.createCallback(name),\r
+                        hideMode: 'offsets'\r
+                    }));\r
+                }, this);\r
                 dlg = new Ext.Window({\r
                     autoCreate : true,\r
                     title:titleText,\r
@@ -1259,16 +1315,12 @@ Ext.MessageBox = function(){
                         }else{\r
                             handleButton("cancel");\r
                         }\r
-                    }\r
+                    },\r
+                    fbar: new Ext.Toolbar({\r
+                        items: btns,\r
+                        enableOverflow: false\r
+                    })\r
                 });\r
-                buttons = {};\r
-                var bt = this.buttonText;\r
-                //TODO: refactor this block into a buttons config to pass into the Window constructor\r
-                buttons["ok"] = dlg.addButton(bt["ok"], handleButton.createCallback("ok"));\r
-                buttons["yes"] = dlg.addButton(bt["yes"], handleButton.createCallback("yes"));\r
-                buttons["no"] = dlg.addButton(bt["no"], handleButton.createCallback("no"));\r
-                buttons["cancel"] = dlg.addButton(bt["cancel"], handleButton.createCallback("cancel"));\r
-                buttons["ok"].hideMode = buttons["yes"].hideMode = buttons["no"].hideMode = buttons["cancel"].hideMode = 'offsets';\r
                 dlg.render(document.body);\r
                 dlg.getEl().addClass('x-window-dlg');\r
                 mask = dlg.mask;\r
@@ -1508,18 +1560,16 @@ Ext.Msg.show({
                 // force it to the end of the z-index stack so it gets a cursor in FF\r
                 document.body.appendChild(dlg.el.dom);\r
                 d.setAnimateTarget(opt.animEl);\r
+                //workaround for window internally enabling keymap in afterShow\r
+                d.on('show', function(){\r
+                    if(allowClose === true){\r
+                        d.keyMap.enable();\r
+                    }else{\r
+                        d.keyMap.disable();\r
+                    }\r
+                }, this, {single:true});\r
                 d.show(opt.animEl);\r
             }\r
-\r
-            //workaround for window internally enabling keymap in afterShow\r
-            d.on('show', function(){\r
-                if(allowClose === true){\r
-                    d.keyMap.enable();\r
-                }else{\r
-                    d.keyMap.disable();\r
-                }\r
-            }, this, {single:true});\r
-\r
             if(opt.wait === true){\r
                 progressBar.wait(opt.waitConfig);\r
             }\r
@@ -1612,7 +1662,7 @@ Ext.MessageBox.ERROR
          * @param {String} title The title bar text\r
          * @param {String} msg The message box body text\r
          * @param {Function} fn (optional) The callback function invoked after the message box is closed\r
-         * @param {Object} scope (optional) The scope of the callback function\r
+         * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to the browser wnidow.\r
          * @return {Ext.MessageBox} this\r
          */\r
         alert : function(title, msg, fn, scope){\r
@@ -1634,7 +1684,7 @@ Ext.MessageBox.ERROR
          * @param {String} title The title bar text\r
          * @param {String} msg The message box body text\r
          * @param {Function} fn (optional) The callback function invoked after the message box is closed\r
-         * @param {Object} scope (optional) The scope of the callback function\r
+         * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to the browser wnidow.\r
          * @return {Ext.MessageBox} this\r
          */\r
         confirm : function(title, msg, fn, scope){\r
@@ -1657,7 +1707,7 @@ Ext.MessageBox.ERROR
          * @param {String} title The title bar text\r
          * @param {String} msg The message box body text\r
          * @param {Function} fn (optional) The callback function invoked after the message box is closed\r
-         * @param {Object} scope (optional) The scope of the callback function\r
+         * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to the browser wnidow.\r
          * @param {Boolean/Number} multiline (optional) True to create a multiline textbox using the defaultTextHeight\r
          * property, or the height in pixels to create the textbox (defaults to false / single-line)\r
          * @param {String} value (optional) Default value of the text input element (defaults to '')\r