3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.2.0
11 * Copyright(c) 2006-2010 Ext JS, Inc.
13 * http://www.extjs.com/license
15 <div id="cls-Ext.MessageBox"></div>/**
16 * @class Ext.MessageBox
17 * <p>Utility class for generating different styles of message boxes. The alias Ext.Msg can also be used.<p/>
18 * <p>Note that the MessageBox is asynchronous. Unlike a regular JavaScript <code>alert</code> (which will halt
19 * browser execution), showing a MessageBox will not cause the code to stop. For this reason, if you have code
20 * that should only run <em>after</em> some user feedback from the MessageBox, you must use a callback function
21 * (see the <code>function</code> parameter for {@link #show} for more details).</p>
22 * <p>Example usage:</p>
25 Ext.Msg.alert('Status', 'Changes saved successfully.');
27 // Prompt for user data and process the result using a callback:
28 Ext.Msg.prompt('Name', 'Please enter your name:', function(btn, text){
30 // process text value and close...
34 // Show a dialog using config options:
36 title:'Save Changes?',
37 msg: 'You are closing a tab that has unsaved changes. Would you like to save your changes?',
38 buttons: Ext.Msg.YESNOCANCEL,
41 icon: Ext.MessageBox.QUESTION
46 Ext.MessageBox = function(){
47 var dlg, opt, mask, waitTimer,
48 bodyEl, msgEl, textboxEl, textareaEl, progressBar, pp, iconEl, spacerEl,
49 buttons, activeTextEl, bwidth, bufferIcon = '', iconCls = '',
50 buttonNames = ['ok', 'yes', 'no', 'cancel'];
53 var handleButton = function(button){
54 buttons[button].blur();
58 Ext.callback(opt.fn, opt.scope||window, [button, activeTextEl.dom.value, opt], 1);
63 var handleHide = function(){
65 dlg.el.removeClass(opt.cls);
71 var handleEsc = function(d, k, e){
72 if(opt && opt.closable !== false){
82 var updateButtons = function(b){
86 Ext.each(buttonNames, function(name){
91 dlg.footer.dom.style.display = '';
92 Ext.iterate(buttons, function(name, btn){
96 btn.setText(Ext.isString(cfg) ? cfg : Ext.MessageBox.buttonText[name]);
97 width += btn.getEl().getWidth() + 15;
106 <div id="method-Ext.MessageBox-getDialog"></div>/**
107 * Returns a reference to the underlying {@link Ext.Window} element
108 * @return {Ext.Window} The window
110 getDialog : function(titleText){
115 Ext.each(buttonNames, function(name){
116 btns.push(buttons[name] = new Ext.Button({
117 text: this.buttonText[name],
118 handler: handleButton.createCallback(name),
122 dlg = new Ext.Window({
127 constrainHeader:true,
133 buttonAlign:"center",
141 if(opt && opt.buttons && opt.buttons.no && !opt.buttons.cancel){
144 handleButton("cancel");
147 fbar: new Ext.Toolbar({
149 enableOverflow: false
152 dlg.render(document.body);
153 dlg.getEl().addClass('x-window-dlg');
155 bodyEl = dlg.body.createChild({
156 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>'
158 iconEl = Ext.get(bodyEl.dom.firstChild);
159 var contentEl = bodyEl.dom.childNodes[1];
160 msgEl = Ext.get(contentEl.firstChild);
161 textboxEl = Ext.get(contentEl.childNodes[2].firstChild);
162 textboxEl.enableDisplayMode();
163 textboxEl.addKeyListener([10,13], function(){
164 if(dlg.isVisible() && opt && opt.buttons){
167 }else if(opt.buttons.yes){
172 textareaEl = Ext.get(contentEl.childNodes[2].childNodes[1]);
173 textareaEl.enableDisplayMode();
174 progressBar = new Ext.ProgressBar({
177 bodyEl.createChild({cls:'x-clear'});
182 <div id="method-Ext.MessageBox-updateText"></div>/**
183 * Updates the message box body text
184 * @param {String} text (optional) Replaces the message box element's innerHTML with the specified string (defaults to
185 * the XHTML-compliant non-breaking space character '&#160;')
186 * @return {Ext.MessageBox} this
188 updateText : function(text){
189 if(!dlg.isVisible() && !opt.width){
190 dlg.setSize(this.maxWidth, 100); // resize first so content is never clipped from previous shows
192 msgEl.update(text || ' ');
194 var iw = iconCls != '' ? (iconEl.getWidth() + iconEl.getMargins('lr')) : 0,
195 mw = msgEl.getWidth() + msgEl.getMargins('lr'),
196 fw = dlg.getFrameWidth('lr'),
197 bw = dlg.body.getFrameWidth('lr'),
200 if (Ext.isIE && iw > 0){
201 //3 pixels get subtracted in the icon CSS for an IE margin issue,
202 //so we have to add it back here for the overall width to be consistent
205 w = Math.max(Math.min(opt.width || iw+mw+fw+bw, opt.maxWidth || this.maxWidth),
206 Math.max(opt.minWidth || this.minWidth, bwidth || 0));
208 if(opt.prompt === true){
209 activeTextEl.setWidth(w-iw-fw-bw);
211 if(opt.progress === true || opt.wait === true){
212 progressBar.setSize(w-iw-fw-bw);
214 if(Ext.isIE && w == bwidth){
215 w += 4; //Add offset when the content width is smaller than the buttons.
217 dlg.setSize(w, 'auto').center();
221 <div id="method-Ext.MessageBox-updateProgress"></div>/**
222 * Updates a progress-style message box's text and progress bar. Only relevant on message boxes
223 * initiated via {@link Ext.MessageBox#progress} or {@link Ext.MessageBox#wait},
224 * or by calling {@link Ext.MessageBox#show} with progress: true.
225 * @param {Number} value Any number between 0 and 1 (e.g., .5, defaults to 0)
226 * @param {String} progressText The progress text to display inside the progress bar (defaults to '')
227 * @param {String} msg The message box's body text is replaced with the specified string (defaults to undefined
228 * so that any existing body text will not get overwritten by default unless a new value is passed in)
229 * @return {Ext.MessageBox} this
231 updateProgress : function(value, progressText, msg){
232 progressBar.updateProgress(value, progressText);
234 this.updateText(msg);
239 <div id="method-Ext.MessageBox-isVisible"></div>/**
240 * Returns true if the message box is currently displayed
241 * @return {Boolean} True if the message box is visible, else false
243 isVisible : function(){
244 return dlg && dlg.isVisible();
247 <div id="method-Ext.MessageBox-hide"></div>/**
248 * Hides the message box if it is displayed
249 * @return {Ext.MessageBox} this
252 var proxy = dlg ? dlg.activeGhost : null;
253 if(this.isVisible() || proxy){
257 // unghost is a private function, but i saw no better solution
258 // to fix the locking problem when dragging while it closes
259 dlg.unghost(false, false);
265 <div id="method-Ext.MessageBox-show"></div>/**
266 * Displays a new message box, or reinitializes an existing message box, based on the config options
267 * passed in. All display functions (e.g. prompt, alert, etc.) on MessageBox call this function internally,
268 * although those calls are basic shortcuts and do not support all of the config options allowed here.
269 * @param {Object} config The following config options are supported: <ul>
270 * <li><b>animEl</b> : String/Element<div class="sub-desc">An id or Element from which the message box should animate as it
271 * opens and closes (defaults to undefined)</div></li>
272 * <li><b>buttons</b> : Object/Boolean<div class="sub-desc">A button config object (e.g., Ext.MessageBox.OKCANCEL or {ok:'Foo',
273 * cancel:'Bar'}), or false to not show any buttons (defaults to false)</div></li>
274 * <li><b>closable</b> : Boolean<div class="sub-desc">False to hide the top-right close button (defaults to true). Note that
275 * progress and wait dialogs will ignore this property and always hide the close button as they can only
276 * be closed programmatically.</div></li>
277 * <li><b>cls</b> : String<div class="sub-desc">A custom CSS class to apply to the message box's container element</div></li>
278 * <li><b>defaultTextHeight</b> : Number<div class="sub-desc">The default height in pixels of the message box's multiline textarea
279 * if displayed (defaults to 75)</div></li>
280 * <li><b>fn</b> : Function<div class="sub-desc">A callback function which is called when the dialog is dismissed either
281 * by clicking on the configured buttons, or on the dialog close button, or by pressing
282 * the return button to enter input.
283 * <p>Progress and wait dialogs will ignore this option since they do not respond to user
284 * actions and can only be closed programmatically, so any required function should be called
285 * by the same code after it closes the dialog. Parameters passed:<ul>
286 * <li><b>buttonId</b> : String<div class="sub-desc">The ID of the button pressed, one of:<div class="sub-desc"><ul>
287 * <li><tt>ok</tt></li>
288 * <li><tt>yes</tt></li>
289 * <li><tt>no</tt></li>
290 * <li><tt>cancel</tt></li>
291 * </ul></div></div></li>
292 * <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>
293 * or <tt><a href="#show-option-multiline" ext:member="show-option-multiline" ext:cls="Ext.MessageBox">multiline</a></tt> is true</div></li>
294 * <li><b>opt</b> : Object<div class="sub-desc">The config object passed to show.</div></li>
295 * </ul></p></div></li>
296 * <li><b>scope</b> : Object<div class="sub-desc">The scope of the callback function</div></li>
297 * <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
298 * dialog (e.g. Ext.MessageBox.WARNING or 'custom-class') (defaults to '')</div></li>
299 * <li><b>iconCls</b> : String<div class="sub-desc">The standard {@link Ext.Window#iconCls} to
300 * add an optional header icon (defaults to '')</div></li>
301 * <li><b>maxWidth</b> : Number<div class="sub-desc">The maximum width in pixels of the message box (defaults to 600)</div></li>
302 * <li><b>minWidth</b> : Number<div class="sub-desc">The minimum width in pixels of the message box (defaults to 100)</div></li>
303 * <li><b>modal</b> : Boolean<div class="sub-desc">False to allow user interaction with the page while the message box is
304 * displayed (defaults to true)</div></li>
305 * <li><b>msg</b> : String<div class="sub-desc">A string that will replace the existing message box body text (defaults to the
306 * XHTML-compliant non-breaking space character '&#160;')</div></li>
307 * <li><a id="show-option-multiline"></a><b>multiline</b> : Boolean<div class="sub-desc">
308 * True to prompt the user to enter multi-line text (defaults to false)</div></li>
309 * <li><b>progress</b> : Boolean<div class="sub-desc">True to display a progress bar (defaults to false)</div></li>
310 * <li><b>progressText</b> : String<div class="sub-desc">The text to display inside the progress bar if progress = true (defaults to '')</div></li>
311 * <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>
312 * <li><b>proxyDrag</b> : Boolean<div class="sub-desc">True to display a lightweight proxy while dragging (defaults to false)</div></li>
313 * <li><b>title</b> : String<div class="sub-desc">The title text</div></li>
314 * <li><b>value</b> : String<div class="sub-desc">The string value to set into the active textbox element if displayed</div></li>
315 * <li><b>wait</b> : Boolean<div class="sub-desc">True to display a progress bar (defaults to false)</div></li>
316 * <li><b>waitConfig</b> : Object<div class="sub-desc">A {@link Ext.ProgressBar#waitConfig} object (applies only if wait = true)</div></li>
317 * <li><b>width</b> : Number<div class="sub-desc">The width of the dialog in pixels</div></li>
323 msg: 'Please enter your address:',
325 buttons: Ext.MessageBox.OKCANCEL,
328 animEl: 'addAddressBtn',
329 icon: Ext.MessageBox.INFO
332 * @return {Ext.MessageBox} this
334 show : function(options){
335 if(this.isVisible()){
339 var d = this.getDialog(opt.title || " ");
341 d.setTitle(opt.title || " ");
342 var allowClose = (opt.closable !== false && opt.progress !== true && opt.wait !== true);
343 d.tools.close.setDisplayed(allowClose);
344 activeTextEl = textboxEl;
345 opt.prompt = opt.prompt || (opt.multiline ? true : false);
350 textareaEl.setHeight(Ext.isNumber(opt.multiline) ? opt.multiline : this.defaultTextHeight);
351 activeTextEl = textareaEl;
360 activeTextEl.dom.value = opt.value || "";
362 d.focusEl = activeTextEl;
364 var bs = opt.buttons;
368 }else if(bs && bs.yes){
376 d.setIconClass(opt.iconCls);
378 this.setIcon(Ext.isDefined(opt.icon) ? opt.icon : bufferIcon);
379 bwidth = updateButtons(opt.buttons);
380 progressBar.setVisible(opt.progress === true || opt.wait === true);
381 this.updateProgress(0, opt.progressText);
382 this.updateText(opt.msg);
384 d.el.addClass(opt.cls);
386 d.proxyDrag = opt.proxyDrag === true;
387 d.modal = opt.modal !== false;
388 d.mask = opt.modal !== false ? mask : false;
390 // force it to the end of the z-index stack so it gets a cursor in FF
391 document.body.appendChild(dlg.el.dom);
392 d.setAnimateTarget(opt.animEl);
393 //workaround for window internally enabling keymap in afterShow
394 d.on('show', function(){
395 if(allowClose === true){
400 }, this, {single:true});
403 if(opt.wait === true){
404 progressBar.wait(opt.waitConfig);
409 <div id="method-Ext.MessageBox-setIcon"></div>/**
410 * Adds the specified icon to the dialog. By default, the class 'ext-mb-icon' is applied for default
411 * styling, and the class passed in is expected to supply the background image url. Pass in empty string ('')
412 * to clear any existing icon. This method must be called before the MessageBox is shown.
413 * The following built-in icon classes are supported, but you can also pass in a custom class name:
416 Ext.MessageBox.WARNING
417 Ext.MessageBox.QUESTION
420 * @param {String} icon A CSS classname specifying the icon's background image url, or empty string to clear the icon
421 * @return {Ext.MessageBox} this
423 setIcon : function(icon){
428 bufferIcon = undefined;
429 if(icon && icon != ''){
430 iconEl.removeClass('x-hidden');
431 iconEl.replaceClass(iconCls, icon);
432 bodyEl.addClass('x-dlg-icon');
435 iconEl.replaceClass(iconCls, 'x-hidden');
436 bodyEl.removeClass('x-dlg-icon');
442 <div id="method-Ext.MessageBox-progress"></div>/**
443 * Displays a message box with a progress bar. This message box has no buttons and is not closeable by
444 * the user. You are responsible for updating the progress bar as needed via {@link Ext.MessageBox#updateProgress}
445 * and closing the message box when the process is complete.
446 * @param {String} title The title bar text
447 * @param {String} msg The message box body text
448 * @param {String} progressText (optional) The text to display inside the progress bar (defaults to '')
449 * @return {Ext.MessageBox} this
451 progress : function(title, msg, progressText){
458 minWidth: this.minProgressWidth,
459 progressText: progressText
464 <div id="method-Ext.MessageBox-wait"></div>/**
465 * Displays a message box with an infinitely auto-updating progress bar. This can be used to block user
466 * interaction while waiting for a long-running process to complete that does not have defined intervals.
467 * You are responsible for closing the message box when the process is complete.
468 * @param {String} msg The message box body text
469 * @param {String} title (optional) The title bar text
470 * @param {Object} config (optional) A {@link Ext.ProgressBar#waitConfig} object
471 * @return {Ext.MessageBox} this
473 wait : function(msg, title, config){
481 minWidth: this.minProgressWidth,
487 <div id="method-Ext.MessageBox-alert"></div>/**
488 * Displays a standard read-only message box with an OK button (comparable to the basic JavaScript alert prompt).
489 * If a callback function is passed it will be called after the user clicks the button, and the
490 * id of the button that was clicked will be passed as the only parameter to the callback
491 * (could also be the top-right close button).
492 * @param {String} title The title bar text
493 * @param {String} msg The message box body text
494 * @param {Function} fn (optional) The callback function invoked after the message box is closed
495 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to the browser wnidow.
496 * @return {Ext.MessageBox} this
498 alert : function(title, msg, fn, scope){
505 minWidth: this.minWidth
510 <div id="method-Ext.MessageBox-confirm"></div>/**
511 * Displays a confirmation message box with Yes and No buttons (comparable to JavaScript's confirm).
512 * If a callback function is passed it will be called after the user clicks either button,
513 * and the id of the button that was clicked will be passed as the only parameter to the callback
514 * (could also be the top-right close button).
515 * @param {String} title The title bar text
516 * @param {String} msg The message box body text
517 * @param {Function} fn (optional) The callback function invoked after the message box is closed
518 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to the browser wnidow.
519 * @return {Ext.MessageBox} this
521 confirm : function(title, msg, fn, scope){
529 minWidth: this.minWidth
534 <div id="method-Ext.MessageBox-prompt"></div>/**
535 * Displays a message box with OK and Cancel buttons prompting the user to enter some text (comparable to JavaScript's prompt).
536 * The prompt can be a single-line or multi-line textbox. If a callback function is passed it will be called after the user
537 * clicks either button, and the id of the button that was clicked (could also be the top-right
538 * close button) and the text that was entered will be passed as the two parameters to the callback.
539 * @param {String} title The title bar text
540 * @param {String} msg The message box body text
541 * @param {Function} fn (optional) The callback function invoked after the message box is closed
542 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to the browser wnidow.
543 * @param {Boolean/Number} multiline (optional) True to create a multiline textbox using the defaultTextHeight
544 * property, or the height in pixels to create the textbox (defaults to false / single-line)
545 * @param {String} value (optional) Default value of the text input element (defaults to '')
546 * @return {Ext.MessageBox} this
548 prompt : function(title, msg, fn, scope, multiline, value){
552 buttons: this.OKCANCEL,
554 minWidth: this.minPromptWidth,
557 multiline: multiline,
563 <div id="prop-Ext.MessageBox-OK"></div>/**
564 * Button config that displays a single OK button
568 <div id="prop-Ext.MessageBox-CANCEL"></div>/**
569 * Button config that displays a single Cancel button
572 CANCEL : {cancel:true},
573 <div id="prop-Ext.MessageBox-OKCANCEL"></div>/**
574 * Button config that displays OK and Cancel buttons
577 OKCANCEL : {ok:true, cancel:true},
578 <div id="prop-Ext.MessageBox-YESNO"></div>/**
579 * Button config that displays Yes and No buttons
582 YESNO : {yes:true, no:true},
583 <div id="prop-Ext.MessageBox-YESNOCANCEL"></div>/**
584 * Button config that displays Yes, No and Cancel buttons
587 YESNOCANCEL : {yes:true, no:true, cancel:true},
588 <div id="prop-Ext.MessageBox-INFO"></div>/**
589 * The CSS class that provides the INFO icon image
592 INFO : 'ext-mb-info',
593 <div id="prop-Ext.MessageBox-WARNING"></div>/**
594 * The CSS class that provides the WARNING icon image
597 WARNING : 'ext-mb-warning',
598 <div id="prop-Ext.MessageBox-QUESTION"></div>/**
599 * The CSS class that provides the QUESTION icon image
602 QUESTION : 'ext-mb-question',
603 <div id="prop-Ext.MessageBox-ERROR"></div>/**
604 * The CSS class that provides the ERROR icon image
607 ERROR : 'ext-mb-error',
609 <div id="prop-Ext.MessageBox-defaultTextHeight"></div>/**
610 * The default height in pixels of the message box's multiline textarea if displayed (defaults to 75)
613 defaultTextHeight : 75,
614 <div id="prop-Ext.MessageBox-maxWidth"></div>/**
615 * The maximum width in pixels of the message box (defaults to 600)
619 <div id="prop-Ext.MessageBox-minWidth"></div>/**
620 * The minimum width in pixels of the message box (defaults to 100)
624 <div id="prop-Ext.MessageBox-minProgressWidth"></div>/**
625 * The minimum width in pixels of the message box if it is a progress-style dialog. This is useful
626 * for setting a different minimum width than text-only dialogs may need (defaults to 250).
629 minProgressWidth : 250,
630 <div id="prop-Ext.MessageBox-minPromptWidth"></div>/**
631 * The minimum width in pixels of the message box if it is a prompt dialog. This is useful
632 * for setting a different minimum width than text-only dialogs may need (defaults to 250).
636 <div id="prop-Ext.MessageBox-buttonText"></div>/**
637 * An object containing the default button text strings that can be overriden for localized language support.
638 * Supported properties are: ok, cancel, yes and no. Generally you should include a locale-specific
639 * resource file for handling language support across the framework.
640 * Customize the default text like so: Ext.MessageBox.buttonText.yes = "oui"; //french
652 <div id="prop-Ext.MessageBox-Msg"></div>/**
653 * Shorthand for {@link Ext.MessageBox}
655 Ext.Msg = Ext.MessageBox;</pre>