[76] | 1 | /*! |
---|
| 2 | * Ext JS Library 3.4.0 |
---|
| 3 | * Copyright(c) 2006-2011 Sencha Inc. |
---|
| 4 | * licensing@sencha.com |
---|
| 5 | * http://www.sencha.com/license |
---|
| 6 | */ |
---|
| 7 | /** |
---|
| 8 | * @class Ext.MessageBox |
---|
| 9 | * <p>Utility class for generating different styles of message boxes. The alias Ext.Msg can also be used.<p/> |
---|
| 10 | * <p>Note that the MessageBox is asynchronous. Unlike a regular JavaScript <code>alert</code> (which will halt |
---|
| 11 | * browser execution), showing a MessageBox will not cause the code to stop. For this reason, if you have code |
---|
| 12 | * that should only run <em>after</em> some user feedback from the MessageBox, you must use a callback function |
---|
| 13 | * (see the <code>function</code> parameter for {@link #show} for more details).</p> |
---|
| 14 | * <p>Example usage:</p> |
---|
| 15 | *<pre><code> |
---|
| 16 | // Basic alert: |
---|
| 17 | Ext.Msg.alert('Status', 'Changes saved successfully.'); |
---|
| 18 | |
---|
| 19 | // Prompt for user data and process the result using a callback: |
---|
| 20 | Ext.Msg.prompt('Name', 'Please enter your name:', function(btn, text){ |
---|
| 21 | if (btn == 'ok'){ |
---|
| 22 | // process text value and close... |
---|
| 23 | } |
---|
| 24 | }); |
---|
| 25 | |
---|
| 26 | // Show a dialog using config options: |
---|
| 27 | Ext.Msg.show({ |
---|
| 28 | title:'Save Changes?', |
---|
| 29 | msg: 'You are closing a tab that has unsaved changes. Would you like to save your changes?', |
---|
| 30 | buttons: Ext.Msg.YESNOCANCEL, |
---|
| 31 | fn: processResult, |
---|
| 32 | animEl: 'elId', |
---|
| 33 | icon: Ext.MessageBox.QUESTION |
---|
| 34 | }); |
---|
| 35 | </code></pre> |
---|
| 36 | * @singleton |
---|
| 37 | */ |
---|
| 38 | Ext.MessageBox = function(){ |
---|
| 39 | var dlg, opt, mask, waitTimer, |
---|
| 40 | bodyEl, msgEl, textboxEl, textareaEl, progressBar, pp, iconEl, spacerEl, |
---|
| 41 | buttons, activeTextEl, bwidth, bufferIcon = '', iconCls = '', |
---|
| 42 | buttonNames = ['ok', 'yes', 'no', 'cancel']; |
---|
| 43 | |
---|
| 44 | // private |
---|
| 45 | var handleButton = function(button){ |
---|
| 46 | buttons[button].blur(); |
---|
| 47 | if(dlg.isVisible()){ |
---|
| 48 | dlg.hide(); |
---|
| 49 | handleHide(); |
---|
| 50 | Ext.callback(opt.fn, opt.scope||window, [button, activeTextEl.dom.value, opt], 1); |
---|
| 51 | } |
---|
| 52 | }; |
---|
| 53 | |
---|
| 54 | // private |
---|
| 55 | var handleHide = function(){ |
---|
| 56 | if(opt && opt.cls){ |
---|
| 57 | dlg.el.removeClass(opt.cls); |
---|
| 58 | } |
---|
| 59 | progressBar.reset(); |
---|
| 60 | }; |
---|
| 61 | |
---|
| 62 | // private |
---|
| 63 | var handleEsc = function(d, k, e){ |
---|
| 64 | if(opt && opt.closable !== false){ |
---|
| 65 | dlg.hide(); |
---|
| 66 | handleHide(); |
---|
| 67 | } |
---|
| 68 | if(e){ |
---|
| 69 | e.stopEvent(); |
---|
| 70 | } |
---|
| 71 | }; |
---|
| 72 | |
---|
| 73 | // private |
---|
| 74 | var updateButtons = function(b){ |
---|
| 75 | var width = 0, |
---|
| 76 | cfg; |
---|
| 77 | if(!b){ |
---|
| 78 | Ext.each(buttonNames, function(name){ |
---|
| 79 | buttons[name].hide(); |
---|
| 80 | }); |
---|
| 81 | return width; |
---|
| 82 | } |
---|
| 83 | dlg.footer.dom.style.display = ''; |
---|
| 84 | Ext.iterate(buttons, function(name, btn){ |
---|
| 85 | cfg = b[name]; |
---|
| 86 | if(cfg){ |
---|
| 87 | btn.show(); |
---|
| 88 | btn.setText(Ext.isString(cfg) ? cfg : Ext.MessageBox.buttonText[name]); |
---|
| 89 | width += btn.getEl().getWidth() + 15; |
---|
| 90 | }else{ |
---|
| 91 | btn.hide(); |
---|
| 92 | } |
---|
| 93 | }); |
---|
| 94 | return width; |
---|
| 95 | }; |
---|
| 96 | |
---|
| 97 | return { |
---|
| 98 | /** |
---|
| 99 | * Returns a reference to the underlying {@link Ext.Window} element |
---|
| 100 | * @return {Ext.Window} The window |
---|
| 101 | */ |
---|
| 102 | getDialog : function(titleText){ |
---|
| 103 | if(!dlg){ |
---|
| 104 | var btns = []; |
---|
| 105 | |
---|
| 106 | buttons = {}; |
---|
| 107 | Ext.each(buttonNames, function(name){ |
---|
| 108 | btns.push(buttons[name] = new Ext.Button({ |
---|
| 109 | text: this.buttonText[name], |
---|
| 110 | handler: handleButton.createCallback(name), |
---|
| 111 | hideMode: 'offsets' |
---|
| 112 | })); |
---|
| 113 | }, this); |
---|
| 114 | dlg = new Ext.Window({ |
---|
| 115 | autoCreate : true, |
---|
| 116 | title:titleText, |
---|
| 117 | resizable:false, |
---|
| 118 | constrain:true, |
---|
| 119 | constrainHeader:true, |
---|
| 120 | minimizable : false, |
---|
| 121 | maximizable : false, |
---|
| 122 | stateful: false, |
---|
| 123 | modal: true, |
---|
| 124 | shim:true, |
---|
| 125 | buttonAlign:"center", |
---|
| 126 | width:400, |
---|
| 127 | height:100, |
---|
| 128 | minHeight: 80, |
---|
| 129 | plain:true, |
---|
| 130 | footer:true, |
---|
| 131 | closable:true, |
---|
| 132 | close : function(){ |
---|
| 133 | if(opt && opt.buttons && opt.buttons.no && !opt.buttons.cancel){ |
---|
| 134 | handleButton("no"); |
---|
| 135 | }else{ |
---|
| 136 | handleButton("cancel"); |
---|
| 137 | } |
---|
| 138 | }, |
---|
| 139 | fbar: new Ext.Toolbar({ |
---|
| 140 | items: btns, |
---|
| 141 | enableOverflow: false |
---|
| 142 | }) |
---|
| 143 | }); |
---|
| 144 | dlg.render(document.body); |
---|
| 145 | dlg.getEl().addClass('x-window-dlg'); |
---|
| 146 | mask = dlg.mask; |
---|
| 147 | bodyEl = dlg.body.createChild({ |
---|
| 148 | 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>' |
---|
| 149 | }); |
---|
| 150 | iconEl = Ext.get(bodyEl.dom.firstChild); |
---|
| 151 | var contentEl = bodyEl.dom.childNodes[1]; |
---|
| 152 | msgEl = Ext.get(contentEl.firstChild); |
---|
| 153 | textboxEl = Ext.get(contentEl.childNodes[2].firstChild); |
---|
| 154 | textboxEl.enableDisplayMode(); |
---|
| 155 | textboxEl.addKeyListener([10,13], function(){ |
---|
| 156 | if(dlg.isVisible() && opt && opt.buttons){ |
---|
| 157 | if(opt.buttons.ok){ |
---|
| 158 | handleButton("ok"); |
---|
| 159 | }else if(opt.buttons.yes){ |
---|
| 160 | handleButton("yes"); |
---|
| 161 | } |
---|
| 162 | } |
---|
| 163 | }); |
---|
| 164 | textareaEl = Ext.get(contentEl.childNodes[2].childNodes[1]); |
---|
| 165 | textareaEl.enableDisplayMode(); |
---|
| 166 | progressBar = new Ext.ProgressBar({ |
---|
| 167 | renderTo:bodyEl |
---|
| 168 | }); |
---|
| 169 | bodyEl.createChild({cls:'x-clear'}); |
---|
| 170 | } |
---|
| 171 | return dlg; |
---|
| 172 | }, |
---|
| 173 | |
---|
| 174 | /** |
---|
| 175 | * Updates the message box body text |
---|
| 176 | * @param {String} text (optional) Replaces the message box element's innerHTML with the specified string (defaults to |
---|
| 177 | * the XHTML-compliant non-breaking space character '&#160;') |
---|
| 178 | * @return {Ext.MessageBox} this |
---|
| 179 | */ |
---|
| 180 | updateText : function(text){ |
---|
| 181 | if(!dlg.isVisible() && !opt.width){ |
---|
| 182 | dlg.setSize(this.maxWidth, 100); // resize first so content is never clipped from previous shows |
---|
| 183 | } |
---|
| 184 | // Append a space here for sizing. In IE, for some reason, it wraps text incorrectly without one in some cases |
---|
| 185 | msgEl.update(text ? text + ' ' : ' '); |
---|
| 186 | |
---|
| 187 | var iw = iconCls != '' ? (iconEl.getWidth() + iconEl.getMargins('lr')) : 0, |
---|
| 188 | mw = msgEl.getWidth() + msgEl.getMargins('lr'), |
---|
| 189 | fw = dlg.getFrameWidth('lr'), |
---|
| 190 | bw = dlg.body.getFrameWidth('lr'), |
---|
| 191 | w; |
---|
| 192 | |
---|
| 193 | w = Math.max(Math.min(opt.width || iw+mw+fw+bw, opt.maxWidth || this.maxWidth), |
---|
| 194 | Math.max(opt.minWidth || this.minWidth, bwidth || 0)); |
---|
| 195 | |
---|
| 196 | if(opt.prompt === true){ |
---|
| 197 | activeTextEl.setWidth(w-iw-fw-bw); |
---|
| 198 | } |
---|
| 199 | if(opt.progress === true || opt.wait === true){ |
---|
| 200 | progressBar.setSize(w-iw-fw-bw); |
---|
| 201 | } |
---|
| 202 | if(Ext.isIE && w == bwidth){ |
---|
| 203 | w += 4; //Add offset when the content width is smaller than the buttons. |
---|
| 204 | } |
---|
| 205 | msgEl.update(text || ' '); |
---|
| 206 | dlg.setSize(w, 'auto').center(); |
---|
| 207 | return this; |
---|
| 208 | }, |
---|
| 209 | |
---|
| 210 | /** |
---|
| 211 | * Updates a progress-style message box's text and progress bar. Only relevant on message boxes |
---|
| 212 | * initiated via {@link Ext.MessageBox#progress} or {@link Ext.MessageBox#wait}, |
---|
| 213 | * or by calling {@link Ext.MessageBox#show} with progress: true. |
---|
| 214 | * @param {Number} value Any number between 0 and 1 (e.g., .5, defaults to 0) |
---|
| 215 | * @param {String} progressText The progress text to display inside the progress bar (defaults to '') |
---|
| 216 | * @param {String} msg The message box's body text is replaced with the specified string (defaults to undefined |
---|
| 217 | * so that any existing body text will not get overwritten by default unless a new value is passed in) |
---|
| 218 | * @return {Ext.MessageBox} this |
---|
| 219 | */ |
---|
| 220 | updateProgress : function(value, progressText, msg){ |
---|
| 221 | progressBar.updateProgress(value, progressText); |
---|
| 222 | if(msg){ |
---|
| 223 | this.updateText(msg); |
---|
| 224 | } |
---|
| 225 | return this; |
---|
| 226 | }, |
---|
| 227 | |
---|
| 228 | /** |
---|
| 229 | * Returns true if the message box is currently displayed |
---|
| 230 | * @return {Boolean} True if the message box is visible, else false |
---|
| 231 | */ |
---|
| 232 | isVisible : function(){ |
---|
| 233 | return dlg && dlg.isVisible(); |
---|
| 234 | }, |
---|
| 235 | |
---|
| 236 | /** |
---|
| 237 | * Hides the message box if it is displayed |
---|
| 238 | * @return {Ext.MessageBox} this |
---|
| 239 | */ |
---|
| 240 | hide : function(){ |
---|
| 241 | var proxy = dlg ? dlg.activeGhost : null; |
---|
| 242 | if(this.isVisible() || proxy){ |
---|
| 243 | dlg.hide(); |
---|
| 244 | handleHide(); |
---|
| 245 | if (proxy){ |
---|
| 246 | // unghost is a private function, but i saw no better solution |
---|
| 247 | // to fix the locking problem when dragging while it closes |
---|
| 248 | dlg.unghost(false, false); |
---|
| 249 | } |
---|
| 250 | } |
---|
| 251 | return this; |
---|
| 252 | }, |
---|
| 253 | |
---|
| 254 | /** |
---|
| 255 | * Displays a new message box, or reinitializes an existing message box, based on the config options |
---|
| 256 | * passed in. All display functions (e.g. prompt, alert, etc.) on MessageBox call this function internally, |
---|
| 257 | * although those calls are basic shortcuts and do not support all of the config options allowed here. |
---|
| 258 | * @param {Object} config The following config options are supported: <ul> |
---|
| 259 | * <li><b>animEl</b> : String/Element<div class="sub-desc">An id or Element from which the message box should animate as it |
---|
| 260 | * opens and closes (defaults to undefined)</div></li> |
---|
| 261 | * <li><b>buttons</b> : Object/Boolean<div class="sub-desc">A button config object (e.g., Ext.MessageBox.OKCANCEL or {ok:'Foo', |
---|
| 262 | * cancel:'Bar'}), or false to not show any buttons (defaults to false)</div></li> |
---|
| 263 | * <li><b>closable</b> : Boolean<div class="sub-desc">False to hide the top-right close button (defaults to true). Note that |
---|
| 264 | * progress and wait dialogs will ignore this property and always hide the close button as they can only |
---|
| 265 | * be closed programmatically.</div></li> |
---|
| 266 | * <li><b>cls</b> : String<div class="sub-desc">A custom CSS class to apply to the message box's container element</div></li> |
---|
| 267 | * <li><b>defaultTextHeight</b> : Number<div class="sub-desc">The default height in pixels of the message box's multiline textarea |
---|
| 268 | * if displayed (defaults to 75)</div></li> |
---|
| 269 | * <li><b>fn</b> : Function<div class="sub-desc">A callback function which is called when the dialog is dismissed either |
---|
| 270 | * by clicking on the configured buttons, or on the dialog close button, or by pressing |
---|
| 271 | * the return button to enter input. |
---|
| 272 | * <p>Progress and wait dialogs will ignore this option since they do not respond to user |
---|
| 273 | * actions and can only be closed programmatically, so any required function should be called |
---|
| 274 | * by the same code after it closes the dialog. Parameters passed:<ul> |
---|
| 275 | * <li><b>buttonId</b> : String<div class="sub-desc">The ID of the button pressed, one of:<div class="sub-desc"><ul> |
---|
| 276 | * <li><tt>ok</tt></li> |
---|
| 277 | * <li><tt>yes</tt></li> |
---|
| 278 | * <li><tt>no</tt></li> |
---|
| 279 | * <li><tt>cancel</tt></li> |
---|
| 280 | * </ul></div></div></li> |
---|
| 281 | * <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> |
---|
| 282 | * or <tt><a href="#show-option-multiline" ext:member="show-option-multiline" ext:cls="Ext.MessageBox">multiline</a></tt> is true</div></li> |
---|
| 283 | * <li><b>opt</b> : Object<div class="sub-desc">The config object passed to show.</div></li> |
---|
| 284 | * </ul></p></div></li> |
---|
| 285 | * <li><b>scope</b> : Object<div class="sub-desc">The scope of the callback function</div></li> |
---|
| 286 | * <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 |
---|
| 287 | * dialog (e.g. Ext.MessageBox.WARNING or 'custom-class') (defaults to '')</div></li> |
---|
| 288 | * <li><b>iconCls</b> : String<div class="sub-desc">The standard {@link Ext.Window#iconCls} to |
---|
| 289 | * add an optional header icon (defaults to '')</div></li> |
---|
| 290 | * <li><b>maxWidth</b> : Number<div class="sub-desc">The maximum width in pixels of the message box (defaults to 600)</div></li> |
---|
| 291 | * <li><b>minWidth</b> : Number<div class="sub-desc">The minimum width in pixels of the message box (defaults to 100)</div></li> |
---|
| 292 | * <li><b>modal</b> : Boolean<div class="sub-desc">False to allow user interaction with the page while the message box is |
---|
| 293 | * displayed (defaults to true)</div></li> |
---|
| 294 | * <li><b>msg</b> : String<div class="sub-desc">A string that will replace the existing message box body text (defaults to the |
---|
| 295 | * XHTML-compliant non-breaking space character '&#160;')</div></li> |
---|
| 296 | * <li><a id="show-option-multiline"></a><b>multiline</b> : Boolean<div class="sub-desc"> |
---|
| 297 | * True to prompt the user to enter multi-line text (defaults to false)</div></li> |
---|
| 298 | * <li><b>progress</b> : Boolean<div class="sub-desc">True to display a progress bar (defaults to false)</div></li> |
---|
| 299 | * <li><b>progressText</b> : String<div class="sub-desc">The text to display inside the progress bar if progress = true (defaults to '')</div></li> |
---|
| 300 | * <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> |
---|
| 301 | * <li><b>proxyDrag</b> : Boolean<div class="sub-desc">True to display a lightweight proxy while dragging (defaults to false)</div></li> |
---|
| 302 | * <li><b>title</b> : String<div class="sub-desc">The title text</div></li> |
---|
| 303 | * <li><b>value</b> : String<div class="sub-desc">The string value to set into the active textbox element if displayed</div></li> |
---|
| 304 | * <li><b>wait</b> : Boolean<div class="sub-desc">True to display a progress bar (defaults to false)</div></li> |
---|
| 305 | * <li><b>waitConfig</b> : Object<div class="sub-desc">A {@link Ext.ProgressBar#waitConfig} object (applies only if wait = true)</div></li> |
---|
| 306 | * <li><b>width</b> : Number<div class="sub-desc">The width of the dialog in pixels</div></li> |
---|
| 307 | * </ul> |
---|
| 308 | * Example usage: |
---|
| 309 | * <pre><code> |
---|
| 310 | Ext.Msg.show({ |
---|
| 311 | title: 'Address', |
---|
| 312 | msg: 'Please enter your address:', |
---|
| 313 | width: 300, |
---|
| 314 | buttons: Ext.MessageBox.OKCANCEL, |
---|
| 315 | multiline: true, |
---|
| 316 | fn: saveAddress, |
---|
| 317 | animEl: 'addAddressBtn', |
---|
| 318 | icon: Ext.MessageBox.INFO |
---|
| 319 | }); |
---|
| 320 | </code></pre> |
---|
| 321 | * @return {Ext.MessageBox} this |
---|
| 322 | */ |
---|
| 323 | show : function(options){ |
---|
| 324 | if(this.isVisible()){ |
---|
| 325 | this.hide(); |
---|
| 326 | } |
---|
| 327 | opt = options; |
---|
| 328 | var d = this.getDialog(opt.title || " "); |
---|
| 329 | |
---|
| 330 | d.setTitle(opt.title || " "); |
---|
| 331 | var allowClose = (opt.closable !== false && opt.progress !== true && opt.wait !== true); |
---|
| 332 | d.tools.close.setDisplayed(allowClose); |
---|
| 333 | activeTextEl = textboxEl; |
---|
| 334 | opt.prompt = opt.prompt || (opt.multiline ? true : false); |
---|
| 335 | if(opt.prompt){ |
---|
| 336 | if(opt.multiline){ |
---|
| 337 | textboxEl.hide(); |
---|
| 338 | textareaEl.show(); |
---|
| 339 | textareaEl.setHeight(Ext.isNumber(opt.multiline) ? opt.multiline : this.defaultTextHeight); |
---|
| 340 | activeTextEl = textareaEl; |
---|
| 341 | }else{ |
---|
| 342 | textboxEl.show(); |
---|
| 343 | textareaEl.hide(); |
---|
| 344 | } |
---|
| 345 | }else{ |
---|
| 346 | textboxEl.hide(); |
---|
| 347 | textareaEl.hide(); |
---|
| 348 | } |
---|
| 349 | activeTextEl.dom.value = opt.value || ""; |
---|
| 350 | if(opt.prompt){ |
---|
| 351 | d.focusEl = activeTextEl; |
---|
| 352 | }else{ |
---|
| 353 | var bs = opt.buttons; |
---|
| 354 | var db = null; |
---|
| 355 | if(bs && bs.ok){ |
---|
| 356 | db = buttons["ok"]; |
---|
| 357 | }else if(bs && bs.yes){ |
---|
| 358 | db = buttons["yes"]; |
---|
| 359 | } |
---|
| 360 | if (db){ |
---|
| 361 | d.focusEl = db; |
---|
| 362 | } |
---|
| 363 | } |
---|
| 364 | if(Ext.isDefined(opt.iconCls)){ |
---|
| 365 | d.setIconClass(opt.iconCls); |
---|
| 366 | } |
---|
| 367 | this.setIcon(Ext.isDefined(opt.icon) ? opt.icon : bufferIcon); |
---|
| 368 | bwidth = updateButtons(opt.buttons); |
---|
| 369 | progressBar.setVisible(opt.progress === true || opt.wait === true); |
---|
| 370 | this.updateProgress(0, opt.progressText); |
---|
| 371 | this.updateText(opt.msg); |
---|
| 372 | if(opt.cls){ |
---|
| 373 | d.el.addClass(opt.cls); |
---|
| 374 | } |
---|
| 375 | d.proxyDrag = opt.proxyDrag === true; |
---|
| 376 | d.modal = opt.modal !== false; |
---|
| 377 | d.mask = opt.modal !== false ? mask : false; |
---|
| 378 | if(!d.isVisible()){ |
---|
| 379 | // force it to the end of the z-index stack so it gets a cursor in FF |
---|
| 380 | document.body.appendChild(dlg.el.dom); |
---|
| 381 | d.setAnimateTarget(opt.animEl); |
---|
| 382 | //workaround for window internally enabling keymap in afterShow |
---|
| 383 | d.on('show', function(){ |
---|
| 384 | if(allowClose === true){ |
---|
| 385 | d.keyMap.enable(); |
---|
| 386 | }else{ |
---|
| 387 | d.keyMap.disable(); |
---|
| 388 | } |
---|
| 389 | }, this, {single:true}); |
---|
| 390 | d.show(opt.animEl); |
---|
| 391 | } |
---|
| 392 | if(opt.wait === true){ |
---|
| 393 | progressBar.wait(opt.waitConfig); |
---|
| 394 | } |
---|
| 395 | return this; |
---|
| 396 | }, |
---|
| 397 | |
---|
| 398 | /** |
---|
| 399 | * Adds the specified icon to the dialog. By default, the class 'ext-mb-icon' is applied for default |
---|
| 400 | * styling, and the class passed in is expected to supply the background image url. Pass in empty string ('') |
---|
| 401 | * to clear any existing icon. This method must be called before the MessageBox is shown. |
---|
| 402 | * The following built-in icon classes are supported, but you can also pass in a custom class name: |
---|
| 403 | * <pre> |
---|
| 404 | Ext.MessageBox.INFO |
---|
| 405 | Ext.MessageBox.WARNING |
---|
| 406 | Ext.MessageBox.QUESTION |
---|
| 407 | Ext.MessageBox.ERROR |
---|
| 408 | *</pre> |
---|
| 409 | * @param {String} icon A CSS classname specifying the icon's background image url, or empty string to clear the icon |
---|
| 410 | * @return {Ext.MessageBox} this |
---|
| 411 | */ |
---|
| 412 | setIcon : function(icon){ |
---|
| 413 | if(!dlg){ |
---|
| 414 | bufferIcon = icon; |
---|
| 415 | return; |
---|
| 416 | } |
---|
| 417 | bufferIcon = undefined; |
---|
| 418 | if(icon && icon != ''){ |
---|
| 419 | iconEl.removeClass('x-hidden'); |
---|
| 420 | iconEl.replaceClass(iconCls, icon); |
---|
| 421 | bodyEl.addClass('x-dlg-icon'); |
---|
| 422 | iconCls = icon; |
---|
| 423 | }else{ |
---|
| 424 | iconEl.replaceClass(iconCls, 'x-hidden'); |
---|
| 425 | bodyEl.removeClass('x-dlg-icon'); |
---|
| 426 | iconCls = ''; |
---|
| 427 | } |
---|
| 428 | return this; |
---|
| 429 | }, |
---|
| 430 | |
---|
| 431 | /** |
---|
| 432 | * Displays a message box with a progress bar. This message box has no buttons and is not closeable by |
---|
| 433 | * the user. You are responsible for updating the progress bar as needed via {@link Ext.MessageBox#updateProgress} |
---|
| 434 | * and closing the message box when the process is complete. |
---|
| 435 | * @param {String} title The title bar text |
---|
| 436 | * @param {String} msg The message box body text |
---|
| 437 | * @param {String} progressText (optional) The text to display inside the progress bar (defaults to '') |
---|
| 438 | * @return {Ext.MessageBox} this |
---|
| 439 | */ |
---|
| 440 | progress : function(title, msg, progressText){ |
---|
| 441 | this.show({ |
---|
| 442 | title : title, |
---|
| 443 | msg : msg, |
---|
| 444 | buttons: false, |
---|
| 445 | progress:true, |
---|
| 446 | closable:false, |
---|
| 447 | minWidth: this.minProgressWidth, |
---|
| 448 | progressText: progressText |
---|
| 449 | }); |
---|
| 450 | return this; |
---|
| 451 | }, |
---|
| 452 | |
---|
| 453 | /** |
---|
| 454 | * Displays a message box with an infinitely auto-updating progress bar. This can be used to block user |
---|
| 455 | * interaction while waiting for a long-running process to complete that does not have defined intervals. |
---|
| 456 | * You are responsible for closing the message box when the process is complete. |
---|
| 457 | * @param {String} msg The message box body text |
---|
| 458 | * @param {String} title (optional) The title bar text |
---|
| 459 | * @param {Object} config (optional) A {@link Ext.ProgressBar#waitConfig} object |
---|
| 460 | * @return {Ext.MessageBox} this |
---|
| 461 | */ |
---|
| 462 | wait : function(msg, title, config){ |
---|
| 463 | this.show({ |
---|
| 464 | title : title, |
---|
| 465 | msg : msg, |
---|
| 466 | buttons: false, |
---|
| 467 | closable:false, |
---|
| 468 | wait:true, |
---|
| 469 | modal:true, |
---|
| 470 | minWidth: this.minProgressWidth, |
---|
| 471 | waitConfig: config |
---|
| 472 | }); |
---|
| 473 | return this; |
---|
| 474 | }, |
---|
| 475 | |
---|
| 476 | /** |
---|
| 477 | * Displays a standard read-only message box with an OK button (comparable to the basic JavaScript alert prompt). |
---|
| 478 | * If a callback function is passed it will be called after the user clicks the button, and the |
---|
| 479 | * id of the button that was clicked will be passed as the only parameter to the callback |
---|
| 480 | * (could also be the top-right close button). |
---|
| 481 | * @param {String} title The title bar text |
---|
| 482 | * @param {String} msg The message box body text |
---|
| 483 | * @param {Function} fn (optional) The callback function invoked after the message box is closed |
---|
| 484 | * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to the browser wnidow. |
---|
| 485 | * @return {Ext.MessageBox} this |
---|
| 486 | */ |
---|
| 487 | alert : function(title, msg, fn, scope){ |
---|
| 488 | this.show({ |
---|
| 489 | title : title, |
---|
| 490 | msg : msg, |
---|
| 491 | buttons: this.OK, |
---|
| 492 | fn: fn, |
---|
| 493 | scope : scope, |
---|
| 494 | minWidth: this.minWidth |
---|
| 495 | }); |
---|
| 496 | return this; |
---|
| 497 | }, |
---|
| 498 | |
---|
| 499 | /** |
---|
| 500 | * Displays a confirmation message box with Yes and No buttons (comparable to JavaScript's confirm). |
---|
| 501 | * If a callback function is passed it will be called after the user clicks either button, |
---|
| 502 | * and the id of the button that was clicked will be passed as the only parameter to the callback |
---|
| 503 | * (could also be the top-right close button). |
---|
| 504 | * @param {String} title The title bar text |
---|
| 505 | * @param {String} msg The message box body text |
---|
| 506 | * @param {Function} fn (optional) The callback function invoked after the message box is closed |
---|
| 507 | * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to the browser wnidow. |
---|
| 508 | * @return {Ext.MessageBox} this |
---|
| 509 | */ |
---|
| 510 | confirm : function(title, msg, fn, scope){ |
---|
| 511 | this.show({ |
---|
| 512 | title : title, |
---|
| 513 | msg : msg, |
---|
| 514 | buttons: this.YESNO, |
---|
| 515 | fn: fn, |
---|
| 516 | scope : scope, |
---|
| 517 | icon: this.QUESTION, |
---|
| 518 | minWidth: this.minWidth |
---|
| 519 | }); |
---|
| 520 | return this; |
---|
| 521 | }, |
---|
| 522 | |
---|
| 523 | /** |
---|
| 524 | * Displays a message box with OK and Cancel buttons prompting the user to enter some text (comparable to JavaScript's prompt). |
---|
| 525 | * The prompt can be a single-line or multi-line textbox. If a callback function is passed it will be called after the user |
---|
| 526 | * clicks either button, and the id of the button that was clicked (could also be the top-right |
---|
| 527 | * close button) and the text that was entered will be passed as the two parameters to the callback. |
---|
| 528 | * @param {String} title The title bar text |
---|
| 529 | * @param {String} msg The message box body text |
---|
| 530 | * @param {Function} fn (optional) The callback function invoked after the message box is closed |
---|
| 531 | * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to the browser wnidow. |
---|
| 532 | * @param {Boolean/Number} multiline (optional) True to create a multiline textbox using the defaultTextHeight |
---|
| 533 | * property, or the height in pixels to create the textbox (defaults to false / single-line) |
---|
| 534 | * @param {String} value (optional) Default value of the text input element (defaults to '') |
---|
| 535 | * @return {Ext.MessageBox} this |
---|
| 536 | */ |
---|
| 537 | prompt : function(title, msg, fn, scope, multiline, value){ |
---|
| 538 | this.show({ |
---|
| 539 | title : title, |
---|
| 540 | msg : msg, |
---|
| 541 | buttons: this.OKCANCEL, |
---|
| 542 | fn: fn, |
---|
| 543 | minWidth: this.minPromptWidth, |
---|
| 544 | scope : scope, |
---|
| 545 | prompt:true, |
---|
| 546 | multiline: multiline, |
---|
| 547 | value: value |
---|
| 548 | }); |
---|
| 549 | return this; |
---|
| 550 | }, |
---|
| 551 | |
---|
| 552 | /** |
---|
| 553 | * Button config that displays a single OK button |
---|
| 554 | * @type Object |
---|
| 555 | */ |
---|
| 556 | OK : {ok:true}, |
---|
| 557 | /** |
---|
| 558 | * Button config that displays a single Cancel button |
---|
| 559 | * @type Object |
---|
| 560 | */ |
---|
| 561 | CANCEL : {cancel:true}, |
---|
| 562 | /** |
---|
| 563 | * Button config that displays OK and Cancel buttons |
---|
| 564 | * @type Object |
---|
| 565 | */ |
---|
| 566 | OKCANCEL : {ok:true, cancel:true}, |
---|
| 567 | /** |
---|
| 568 | * Button config that displays Yes and No buttons |
---|
| 569 | * @type Object |
---|
| 570 | */ |
---|
| 571 | YESNO : {yes:true, no:true}, |
---|
| 572 | /** |
---|
| 573 | * Button config that displays Yes, No and Cancel buttons |
---|
| 574 | * @type Object |
---|
| 575 | */ |
---|
| 576 | YESNOCANCEL : {yes:true, no:true, cancel:true}, |
---|
| 577 | /** |
---|
| 578 | * The CSS class that provides the INFO icon image |
---|
| 579 | * @type String |
---|
| 580 | */ |
---|
| 581 | INFO : 'ext-mb-info', |
---|
| 582 | /** |
---|
| 583 | * The CSS class that provides the WARNING icon image |
---|
| 584 | * @type String |
---|
| 585 | */ |
---|
| 586 | WARNING : 'ext-mb-warning', |
---|
| 587 | /** |
---|
| 588 | * The CSS class that provides the QUESTION icon image |
---|
| 589 | * @type String |
---|
| 590 | */ |
---|
| 591 | QUESTION : 'ext-mb-question', |
---|
| 592 | /** |
---|
| 593 | * The CSS class that provides the ERROR icon image |
---|
| 594 | * @type String |
---|
| 595 | */ |
---|
| 596 | ERROR : 'ext-mb-error', |
---|
| 597 | |
---|
| 598 | /** |
---|
| 599 | * The default height in pixels of the message box's multiline textarea if displayed (defaults to 75) |
---|
| 600 | * @type Number |
---|
| 601 | */ |
---|
| 602 | defaultTextHeight : 75, |
---|
| 603 | /** |
---|
| 604 | * The maximum width in pixels of the message box (defaults to 600) |
---|
| 605 | * @type Number |
---|
| 606 | */ |
---|
| 607 | maxWidth : 600, |
---|
| 608 | /** |
---|
| 609 | * The minimum width in pixels of the message box (defaults to 100) |
---|
| 610 | * @type Number |
---|
| 611 | */ |
---|
| 612 | minWidth : 100, |
---|
| 613 | /** |
---|
| 614 | * The minimum width in pixels of the message box if it is a progress-style dialog. This is useful |
---|
| 615 | * for setting a different minimum width than text-only dialogs may need (defaults to 250). |
---|
| 616 | * @type Number |
---|
| 617 | */ |
---|
| 618 | minProgressWidth : 250, |
---|
| 619 | /** |
---|
| 620 | * The minimum width in pixels of the message box if it is a prompt dialog. This is useful |
---|
| 621 | * for setting a different minimum width than text-only dialogs may need (defaults to 250). |
---|
| 622 | * @type Number |
---|
| 623 | */ |
---|
| 624 | minPromptWidth: 250, |
---|
| 625 | /** |
---|
| 626 | * An object containing the default button text strings that can be overriden for localized language support. |
---|
| 627 | * Supported properties are: ok, cancel, yes and no. Generally you should include a locale-specific |
---|
| 628 | * resource file for handling language support across the framework. |
---|
| 629 | * Customize the default text like so: Ext.MessageBox.buttonText.yes = "oui"; //french |
---|
| 630 | * @type Object |
---|
| 631 | */ |
---|
| 632 | buttonText : { |
---|
| 633 | ok : "OK", |
---|
| 634 | cancel : "Cancel", |
---|
| 635 | yes : "Yes", |
---|
| 636 | no : "No" |
---|
| 637 | } |
---|
| 638 | }; |
---|
| 639 | }(); |
---|
| 640 | |
---|
| 641 | /** |
---|
| 642 | * Shorthand for {@link Ext.MessageBox} |
---|
| 643 | */ |
---|
| 644 | Ext.Msg = Ext.MessageBox; |
---|