1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 cr.define('options', function() {
6 var OptionsPage = options.OptionsPage;
10 * Encapsulated handling of a generic alert.
13 function AlertOverlay() {
14 OptionsPage.call(this, 'alertOverlay', '', 'alertOverlay');
17 cr.addSingletonGetter(AlertOverlay);
19 AlertOverlay.prototype = {
20 // Inherit AlertOverlay from OptionsPage.
21 __proto__: OptionsPage.prototype,
24 * Whether the page can be shown. Used to make sure the page is only
25 * shown via AlertOverlay.Show(), and not via the address bar.
31 * Initialize the page.
33 initializePage: function() {
34 // Call base class implementation to start preference initialization.
35 OptionsPage.prototype.initializePage.call(this);
38 $('alertOverlayOk').onclick = function(event) {
42 $('alertOverlayCancel').onclick = function(event) {
49 // AlertOverlay is special in that it is not tied to one page or overlay.
50 // Set the nesting level arbitrarily high so as to always be recognized as
51 // the top-most visible page.
56 * Handle the 'ok' button. Clear the overlay and call the ok callback if
60 handleOK_: function() {
61 OptionsPage.closeOverlay();
62 if (this.okCallback != undefined) {
63 this.okCallback.call();
68 * Handle the 'cancel' button. Clear the overlay and call the cancel
69 * callback if available.
72 handleCancel_: function() {
73 OptionsPage.closeOverlay();
74 if (this.cancelCallback != undefined) {
75 this.cancelCallback.call();
80 * The page is getting hidden. Don't let it be shown again.
82 willHidePage: function() {
87 canShowPage: function() {
93 * Show an alert overlay with the given message, button titles, and
95 * @param {string} title The alert title to display to the user.
96 * @param {string} message The alert message to display to the user.
97 * @param {string} okTitle The title of the OK button. If undefined or empty,
99 * @param {string} cancelTitle The title of the cancel button. If undefined or
100 * empty, no button is shown.
101 * @param {function} okCallback A function to be called when the user presses
102 * the ok button. The alert window will be closed automatically. Can be
104 * @param {function} cancelCallback A function to be called when the user
105 * presses the cancel button. The alert window will be closed
106 * automatically. Can be undefined.
108 AlertOverlay.show = function(
109 title, message, okTitle, cancelTitle, okCallback, cancelCallback) {
110 if (title != undefined) {
111 $('alertOverlayTitle').textContent = title;
112 $('alertOverlayTitle').style.display = 'block';
114 $('alertOverlayTitle').style.display = 'none';
117 if (message != undefined) {
118 $('alertOverlayMessage').textContent = message;
119 $('alertOverlayMessage').style.display = 'block';
121 $('alertOverlayMessage').style.display = 'none';
124 if (okTitle != undefined && okTitle != '') {
125 $('alertOverlayOk').textContent = okTitle;
126 $('alertOverlayOk').style.display = 'block';
128 $('alertOverlayOk').style.display = 'none';
131 if (cancelTitle != undefined && cancelTitle != '') {
132 $('alertOverlayCancel').textContent = cancelTitle;
133 $('alertOverlayCancel').style.display = 'inline';
135 $('alertOverlayCancel').style.display = 'none';
138 var alertOverlay = AlertOverlay.getInstance();
139 alertOverlay.okCallback = okCallback;
140 alertOverlay.cancelCallback = cancelCallback;
141 alertOverlay.canShow_ = true;
143 // Intentionally don't show the URL in the location bar as we don't want
144 // people trying to navigate here by hand.
145 OptionsPage.showPageByName('alertOverlay', false);
150 AlertOverlay: AlertOverlay