Upgrade to ExtJS 3.1.0 - Released 12/16/2009
[extjs.git] / src / widgets / MessageBox.js
index 10c17d6..9de65c4 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
@@ -38,10 +38,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
@@ -54,7 +56,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
@@ -70,26 +72,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
@@ -100,6 +101,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
@@ -124,16 +135,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
@@ -373,18 +380,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
@@ -477,7 +482,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
@@ -499,7 +504,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
@@ -522,7 +527,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