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.3.1
11 * Copyright(c) 2006-2010 Sencha Inc.
12 * licensing@sencha.com
13 * http://www.sencha.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 // Append a space here for sizing. In IE, for some reason, it wraps text incorrectly without one in some cases
193 msgEl.update(text ? text + ' ' : ' ');
195 var iw = iconCls != '' ? (iconEl.getWidth() + iconEl.getMargins('lr')) : 0,
196 mw = msgEl.getWidth() + msgEl.getMargins('lr'),
197 fw = dlg.getFrameWidth('lr'),
198 bw = dlg.body.getFrameWidth('lr'),
201 w = Math.max(Math.min(opt.width || iw+mw+fw+bw, opt.maxWidth || this.maxWidth),
202 Math.max(opt.minWidth || this.minWidth, bwidth || 0));
204 if(opt.prompt === true){
205 activeTextEl.setWidth(w-iw-fw-bw);
207 if(opt.progress === true || opt.wait === true){
208 progressBar.setSize(w-iw-fw-bw);
210 if(Ext.isIE && w == bwidth){
211 w += 4; //Add offset when the content width is smaller than the buttons.
213 msgEl.update(text || ' ');
214 dlg.setSize(w, 'auto').center();
218 <div id="method-Ext.MessageBox-updateProgress"></div>/**
219 * Updates a progress-style message box's text and progress bar. Only relevant on message boxes
220 * initiated via {@link Ext.MessageBox#progress} or {@link Ext.MessageBox#wait},
221 * or by calling {@link Ext.MessageBox#show} with progress: true.
222 * @param {Number} value Any number between 0 and 1 (e.g., .5, defaults to 0)
223 * @param {String} progressText The progress text to display inside the progress bar (defaults to '')
224 * @param {String} msg The message box's body text is replaced with the specified string (defaults to undefined
225 * so that any existing body text will not get overwritten by default unless a new value is passed in)
226 * @return {Ext.MessageBox} this
228 updateProgress : function(value, progressText, msg){
229 progressBar.updateProgress(value, progressText);
231 this.updateText(msg);
236 <div id="method-Ext.MessageBox-isVisible"></div>/**
237 * Returns true if the message box is currently displayed
238 * @return {Boolean} True if the message box is visible, else false
240 isVisible : function(){
241 return dlg && dlg.isVisible();
244 <div id="method-Ext.MessageBox-hide"></div>/**
245 * Hides the message box if it is displayed
246 * @return {Ext.MessageBox} this
249 var proxy = dlg ? dlg.activeGhost : null;
250 if(this.isVisible() || proxy){
254 // unghost is a private function, but i saw no better solution
255 // to fix the locking problem when dragging while it closes
256 dlg.unghost(false, false);
262 <div id="method-Ext.MessageBox-show"></div>/**
263 * Displays a new message box, or reinitializes an existing message box, based on the config options
264 * passed in. All display functions (e.g. prompt, alert, etc.) on MessageBox call this function internally,
265 * although those calls are basic shortcuts and do not support all of the config options allowed here.
266 * @param {Object} config The following config options are supported: <ul>
267 * <li><b>animEl</b> : String/Element<div class="sub-desc">An id or Element from which the message box should animate as it
268 * opens and closes (defaults to undefined)</div></li>
269 * <li><b>buttons</b> : Object/Boolean<div class="sub-desc">A button config object (e.g., Ext.MessageBox.OKCANCEL or {ok:'Foo',
270 * cancel:'Bar'}), or false to not show any buttons (defaults to false)</div></li>
271 * <li><b>closable</b> : Boolean<div class="sub-desc">False to hide the top-right close button (defaults to true). Note that
272 * progress and wait dialogs will ignore this property and always hide the close button as they can only
273 * be closed programmatically.</div></li>
274 * <li><b>cls</b> : String<div class="sub-desc">A custom CSS class to apply to the message box's container element</div></li>
275 * <li><b>defaultTextHeight</b> : Number<div class="sub-desc">The default height in pixels of the message box's multiline textarea
276 * if displayed (defaults to 75)</div></li>
277 * <li><b>fn</b> : Function<div class="sub-desc">A callback function which is called when the dialog is dismissed either
278 * by clicking on the configured buttons, or on the dialog close button, or by pressing
279 * the return button to enter input.
280 * <p>Progress and wait dialogs will ignore this option since they do not respond to user
281 * actions and can only be closed programmatically, so any required function should be called
282 * by the same code after it closes the dialog. Parameters passed:<ul>
283 * <li><b>buttonId</b> : String<div class="sub-desc">The ID of the button pressed, one of:<div class="sub-desc"><ul>
284 * <li><tt>ok</tt></li>
285 * <li><tt>yes</tt></li>
286 * <li><tt>no</tt></li>
287 * <li><tt>cancel</tt></li>
288 * </ul></div></div></li>
289 * <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>
290 * or <tt><a href="#show-option-multiline" ext:member="show-option-multiline" ext:cls="Ext.MessageBox">multiline</a></tt> is true</div></li>
291 * <li><b>opt</b> : Object<div class="sub-desc">The config object passed to show.</div></li>
292 * </ul></p></div></li>
293 * <li><b>scope</b> : Object<div class="sub-desc">The scope of the callback function</div></li>
294 * <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
295 * dialog (e.g. Ext.MessageBox.WARNING or 'custom-class') (defaults to '')</div></li>
296 * <li><b>iconCls</b> : String<div class="sub-desc">The standard {@link Ext.Window#iconCls} to
297 * add an optional header icon (defaults to '')</div></li>
298 * <li><b>maxWidth</b> : Number<div class="sub-desc">The maximum width in pixels of the message box (defaults to 600)</div></li>
299 * <li><b>minWidth</b> : Number<div class="sub-desc">The minimum width in pixels of the message box (defaults to 100)</div></li>
300 * <li><b>modal</b> : Boolean<div class="sub-desc">False to allow user interaction with the page while the message box is
301 * displayed (defaults to true)</div></li>
302 * <li><b>msg</b> : String<div class="sub-desc">A string that will replace the existing message box body text (defaults to the
303 * XHTML-compliant non-breaking space character '&#160;')</div></li>
304 * <li><a id="show-option-multiline"></a><b>multiline</b> : Boolean<div class="sub-desc">
305 * True to prompt the user to enter multi-line text (defaults to false)</div></li>
306 * <li><b>progress</b> : Boolean<div class="sub-desc">True to display a progress bar (defaults to false)</div></li>
307 * <li><b>progressText</b> : String<div class="sub-desc">The text to display inside the progress bar if progress = true (defaults to '')</div></li>
308 * <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>
309 * <li><b>proxyDrag</b> : Boolean<div class="sub-desc">True to display a lightweight proxy while dragging (defaults to false)</div></li>
310 * <li><b>title</b> : String<div class="sub-desc">The title text</div></li>
311 * <li><b>value</b> : String<div class="sub-desc">The string value to set into the active textbox element if displayed</div></li>
312 * <li><b>wait</b> : Boolean<div class="sub-desc">True to display a progress bar (defaults to false)</div></li>
313 * <li><b>waitConfig</b> : Object<div class="sub-desc">A {@link Ext.ProgressBar#waitConfig} object (applies only if wait = true)</div></li>
314 * <li><b>width</b> : Number<div class="sub-desc">The width of the dialog in pixels</div></li>
320 msg: 'Please enter your address:',
322 buttons: Ext.MessageBox.OKCANCEL,
325 animEl: 'addAddressBtn',
326 icon: Ext.MessageBox.INFO
329 * @return {Ext.MessageBox} this
331 show : function(options){
332 if(this.isVisible()){
336 var d = this.getDialog(opt.title || " ");
338 d.setTitle(opt.title || " ");
339 var allowClose = (opt.closable !== false && opt.progress !== true && opt.wait !== true);
340 d.tools.close.setDisplayed(allowClose);
341 activeTextEl = textboxEl;
342 opt.prompt = opt.prompt || (opt.multiline ? true : false);
347 textareaEl.setHeight(Ext.isNumber(opt.multiline) ? opt.multiline : this.defaultTextHeight);
348 activeTextEl = textareaEl;
357 activeTextEl.dom.value = opt.value || "";
359 d.focusEl = activeTextEl;
361 var bs = opt.buttons;
365 }else if(bs && bs.yes){
372 if(Ext.isDefined(opt.iconCls)){
373 d.setIconClass(opt.iconCls);
375 this.setIcon(Ext.isDefined(opt.icon) ? opt.icon : bufferIcon);
376 bwidth = updateButtons(opt.buttons);
377 progressBar.setVisible(opt.progress === true || opt.wait === true);
378 this.updateProgress(0, opt.progressText);
379 this.updateText(opt.msg);
381 d.el.addClass(opt.cls);
383 d.proxyDrag = opt.proxyDrag === true;
384 d.modal = opt.modal !== false;
385 d.mask = opt.modal !== false ? mask : false;
387 // force it to the end of the z-index stack so it gets a cursor in FF
388 document.body.appendChild(dlg.el.dom);
389 d.setAnimateTarget(opt.animEl);
390 //workaround for window internally enabling keymap in afterShow
391 d.on('show', function(){
392 if(allowClose === true){
397 }, this, {single:true});
400 if(opt.wait === true){
401 progressBar.wait(opt.waitConfig);
406 <div id="method-Ext.MessageBox-setIcon"></div>/**
407 * Adds the specified icon to the dialog. By default, the class 'ext-mb-icon' is applied for default
408 * styling, and the class passed in is expected to supply the background image url. Pass in empty string ('')
409 * to clear any existing icon. This method must be called before the MessageBox is shown.
410 * The following built-in icon classes are supported, but you can also pass in a custom class name:
413 Ext.MessageBox.WARNING
414 Ext.MessageBox.QUESTION
417 * @param {String} icon A CSS classname specifying the icon's background image url, or empty string to clear the icon
418 * @return {Ext.MessageBox} this
420 setIcon : function(icon){
425 bufferIcon = undefined;
426 if(icon && icon != ''){
427 iconEl.removeClass('x-hidden');
428 iconEl.replaceClass(iconCls, icon);
429 bodyEl.addClass('x-dlg-icon');
432 iconEl.replaceClass(iconCls, 'x-hidden');
433 bodyEl.removeClass('x-dlg-icon');
439 <div id="method-Ext.MessageBox-progress"></div>/**
440 * Displays a message box with a progress bar. This message box has no buttons and is not closeable by
441 * the user. You are responsible for updating the progress bar as needed via {@link Ext.MessageBox#updateProgress}
442 * and closing the message box when the process is complete.
443 * @param {String} title The title bar text
444 * @param {String} msg The message box body text
445 * @param {String} progressText (optional) The text to display inside the progress bar (defaults to '')
446 * @return {Ext.MessageBox} this
448 progress : function(title, msg, progressText){
455 minWidth: this.minProgressWidth,
456 progressText: progressText
461 <div id="method-Ext.MessageBox-wait"></div>/**
462 * Displays a message box with an infinitely auto-updating progress bar. This can be used to block user
463 * interaction while waiting for a long-running process to complete that does not have defined intervals.
464 * You are responsible for closing the message box when the process is complete.
465 * @param {String} msg The message box body text
466 * @param {String} title (optional) The title bar text
467 * @param {Object} config (optional) A {@link Ext.ProgressBar#waitConfig} object
468 * @return {Ext.MessageBox} this
470 wait : function(msg, title, config){
478 minWidth: this.minProgressWidth,
484 <div id="method-Ext.MessageBox-alert"></div>/**
485 * Displays a standard read-only message box with an OK button (comparable to the basic JavaScript alert prompt).
486 * If a callback function is passed it will be called after the user clicks the button, and the
487 * id of the button that was clicked will be passed as the only parameter to the callback
488 * (could also be the top-right close button).
489 * @param {String} title The title bar text
490 * @param {String} msg The message box body text
491 * @param {Function} fn (optional) The callback function invoked after the message box is closed
492 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to the browser wnidow.
493 * @return {Ext.MessageBox} this
495 alert : function(title, msg, fn, scope){
502 minWidth: this.minWidth
507 <div id="method-Ext.MessageBox-confirm"></div>/**
508 * Displays a confirmation message box with Yes and No buttons (comparable to JavaScript's confirm).
509 * If a callback function is passed it will be called after the user clicks either button,
510 * and the id of the button that was clicked will be passed as the only parameter to the callback
511 * (could also be the top-right close button).
512 * @param {String} title The title bar text
513 * @param {String} msg The message box body text
514 * @param {Function} fn (optional) The callback function invoked after the message box is closed
515 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to the browser wnidow.
516 * @return {Ext.MessageBox} this
518 confirm : function(title, msg, fn, scope){
526 minWidth: this.minWidth
531 <div id="method-Ext.MessageBox-prompt"></div>/**
532 * Displays a message box with OK and Cancel buttons prompting the user to enter some text (comparable to JavaScript's prompt).
533 * The prompt can be a single-line or multi-line textbox. If a callback function is passed it will be called after the user
534 * clicks either button, and the id of the button that was clicked (could also be the top-right
535 * close button) and the text that was entered will be passed as the two parameters to the callback.
536 * @param {String} title The title bar text
537 * @param {String} msg The message box body text
538 * @param {Function} fn (optional) The callback function invoked after the message box is closed
539 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to the browser wnidow.
540 * @param {Boolean/Number} multiline (optional) True to create a multiline textbox using the defaultTextHeight
541 * property, or the height in pixels to create the textbox (defaults to false / single-line)
542 * @param {String} value (optional) Default value of the text input element (defaults to '')
543 * @return {Ext.MessageBox} this
545 prompt : function(title, msg, fn, scope, multiline, value){
549 buttons: this.OKCANCEL,
551 minWidth: this.minPromptWidth,
554 multiline: multiline,
560 <div id="prop-Ext.MessageBox-OK"></div>/**
561 * Button config that displays a single OK button
565 <div id="prop-Ext.MessageBox-CANCEL"></div>/**
566 * Button config that displays a single Cancel button
569 CANCEL : {cancel:true},
570 <div id="prop-Ext.MessageBox-OKCANCEL"></div>/**
571 * Button config that displays OK and Cancel buttons
574 OKCANCEL : {ok:true, cancel:true},
575 <div id="prop-Ext.MessageBox-YESNO"></div>/**
576 * Button config that displays Yes and No buttons
579 YESNO : {yes:true, no:true},
580 <div id="prop-Ext.MessageBox-YESNOCANCEL"></div>/**
581 * Button config that displays Yes, No and Cancel buttons
584 YESNOCANCEL : {yes:true, no:true, cancel:true},
585 <div id="prop-Ext.MessageBox-INFO"></div>/**
586 * The CSS class that provides the INFO icon image
589 INFO : 'ext-mb-info',
590 <div id="prop-Ext.MessageBox-WARNING"></div>/**
591 * The CSS class that provides the WARNING icon image
594 WARNING : 'ext-mb-warning',
595 <div id="prop-Ext.MessageBox-QUESTION"></div>/**
596 * The CSS class that provides the QUESTION icon image
599 QUESTION : 'ext-mb-question',
600 <div id="prop-Ext.MessageBox-ERROR"></div>/**
601 * The CSS class that provides the ERROR icon image
604 ERROR : 'ext-mb-error',
606 <div id="prop-Ext.MessageBox-defaultTextHeight"></div>/**
607 * The default height in pixels of the message box's multiline textarea if displayed (defaults to 75)
610 defaultTextHeight : 75,
611 <div id="prop-Ext.MessageBox-maxWidth"></div>/**
612 * The maximum width in pixels of the message box (defaults to 600)
616 <div id="prop-Ext.MessageBox-minWidth"></div>/**
617 * The minimum width in pixels of the message box (defaults to 100)
621 <div id="prop-Ext.MessageBox-minProgressWidth"></div>/**
622 * The minimum width in pixels of the message box if it is a progress-style dialog. This is useful
623 * for setting a different minimum width than text-only dialogs may need (defaults to 250).
626 minProgressWidth : 250,
627 <div id="prop-Ext.MessageBox-minPromptWidth"></div>/**
628 * The minimum width in pixels of the message box if it is a prompt dialog. This is useful
629 * for setting a different minimum width than text-only dialogs may need (defaults to 250).
633 <div id="prop-Ext.MessageBox-buttonText"></div>/**
634 * An object containing the default button text strings that can be overriden for localized language support.
635 * Supported properties are: ok, cancel, yes and no. Generally you should include a locale-specific
636 * resource file for handling language support across the framework.
637 * Customize the default text like so: Ext.MessageBox.buttonText.yes = "oui"; //french
649 <div id="prop-Ext.MessageBox-Msg"></div>/**
650 * Shorthand for {@link Ext.MessageBox}
652 Ext.Msg = Ext.MessageBox;</pre>