// ========================================================================== // Project: SproutCore - JavaScript Application Framework // Copyright: ©2006-2009 Sprout Systems, Inc. and contributors. // Portions ©2008-2009 Apple, Inc. All rights reserved. // License: Licened under MIT license (see license.js) // ========================================================================== sc_require('panes/panel'); sc_require('views/button'); /** button1 : 1st button from the right. default:OK button2 : 2nd button from the right. Optional. Could be Cancel or 2nd action. button3 : 1st button from the left. Optional. Could be Cancel or alternative option. */ /** Passed to delegate when alert pane is dismissed by pressing button 1 */ SC.BUTTON1_STATUS = 'button1'; /** Passed to delegate when alert pane is dismissed by pressing button 2 */ SC.BUTTON2_STATUS = 'button2'; /** Passed to delegate when alert pane is dismissed by pressing button 3 */ SC.BUTTON3_STATUS = 'button3'; /** Displays a preformatted modal alert pane. Alert panes are a simple way to provide modal messaging that otherwise blocks the user's interaction with your application. Alert panes are useful for showing important error messages and confirmation dialogs. They provide a better user experience than using the OS-level alert dialogs. h1. Displaying an Alert Pane The easiest way to display an alert pane is to use one of the various class methods defined on SC.AlertPane, passing the message and an optional detailed description and caption. There are four variations of this method can you can invoke: - *warn()* - displays an alert pane with a warning icon to the left. - *error()* - displays an alert with an error icon to the left - *info()* - displays an alert with an info icon to the left - *plain()* - displays an alert w/o any icon - *show()* - displays an alert with a customizable icon to the left In addition to passing a message, description and caption, you can also customize the title of the button 1 (OK) and add an optional button 2 and 3 (Cancel or Extra). Just pass these titles of these buttons to enable them or null to disable then. Additionally, you can pass a delegate object as the last parameter. This delegate's 'alertPaneDidDismiss()' method will be called when the pane is dismissed, passing the pane instance and a key indicating which button was pressed. h1. Examples Show a simple AlertPane with an OK button: {{{ SC.AlertPane.warn("Could not load calendar", "Your internet connection may be unavailable or our servers may be down. Try again in a few minutes."); }}} Show an AlertPane with a customized OK title (title will be 'Try Again'): {{{ SC.AlertPane.warn("Could not load calendar", "Your internet connection may be unavailable or our servers may be down. Try again in a few minutes.", "Try Again"); }}} Show an AlertPane with a custom OK, a Cancel button and an Extra button, each with custom titles. Also, pass a delegate that will be invoked when the user's dismisses the dialog. {{{ MyApp.calendarController = SC.Object.create({ alertPaneDidDismiss: function(pane, status) { switch(status) { case SC.BUTTON1_STATUS: this.tryAgain(); break; case SC.BUTTON2_STATUS: // do nothing break; case SC.BUTTON3_STATUS: this.showMoreInfo(); break; } }, ... }); SC.AlertPane.warn("Could not load calendar", "Your internet connection may be unavailable or our servers may be down. Try again in a few minutes.", "Try Again", "Cancel", "More Info...", MyApp.calendarController); }}} @extends SC.PanelPane @since SproutCore 1.0 */ SC.AlertPane = SC.PanelPane.extend({ classNames: 'sc-alert', /** The delegate to notify when the pane is dismissed. If you set a delegate, it should respond to the method: {{{ alertPaneDidDismiss: function(pane, status) }}} The status will be on of SC.BUTTON1_STATUS, SC.BUTTON2_STATUS or SC.BUTTON3_STATUS depending on which button was clicked. @property {Object} */ delegate: null, /** The icon URL or class name. If you do not set this, an alert icon will be shown instead. @property {String} */ icon: 'sc-icon-alert-48', /** The primary message to display. This message will appear in large bold type at the top of the alert. @property {String} */ message: "", /** An optional detailed decription. Use this string to provide further explanation of the condition and, optionally, ways the user can resolve the problem. @property {String} */ description: "", displayDescription: function() { var desc = this.get('description'); if (!desc || desc.length === 0) return desc ; desc = SC.RenderContext.escapeHTML(desc); // remove HTML return '
' + desc.split('\n').join('
') + '
'; }.property('description').cacheable(), /** An optional detailed caption. Use this string to provide further fine print explanation of the condition and, optionally, ways the user can resolve the problem. @property {String} */ caption: "", displayCaption: function() { var caption = this.get('caption'); if (!caption || caption.length === 0) return caption ; caption = SC.RenderContext.escapeHTML(caption); // remove HTML return '' + caption.split('\n').join('
') + '
'; }.property('caption').cacheable(), /** The button view for the button 1 (OK). @property {SC.ButtonView} */ buttonOne: SC.outlet('contentView.childViews.1.childViews.1'), /** The button view for the button 2 (Cancel). @property {SC.ButtonView} */ buttonTwo: SC.outlet('contentView.childViews.1.childViews.0'), /** The button view for the button 3 (Extra). @property {SC.ButtonView} */ buttonThree: SC.outlet('contentView.childViews.2.childViews.0'), /** The view for the button 3 (Extra) wrapper. @property {SC.View} */ buttonThreeWrapper: SC.outlet('contentView.childViews.2'), layout: { centerX: 0, width: 500, top: 55 }, /** @private - internal view that is actually displayed */ contentView: SC.View.extend({ useStaticLayout: YES, layout: { left: 0, right: 0, top: 0, height: "auto" }, childViews: [ SC.View.extend(SC.StaticLayout, { classNames: ['info'], render: function(context, firstTime) { var pane = this.get('pane'); var blank = sc_static('blank') ; if(pane.get('icon') == 'blank') context.addClass('plain'); context.push('