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 Page
= cr
.ui
.pageManager
.Page
;
7 var PageManager
= cr
.ui
.pageManager
.PageManager
;
11 * Encapsulated handling of a generic alert.
13 * @extends {cr.ui.pageManager.Page}
15 function AlertOverlay() {
16 Page
.call(this, 'alertOverlay', '', 'alertOverlay');
19 cr
.addSingletonGetter(AlertOverlay
);
21 AlertOverlay
.prototype = {
22 // Inherit AlertOverlay from Page.
23 __proto__
: Page
.prototype,
26 * Whether the page can be shown. Used to make sure the page is only
27 * shown via AlertOverlay.Show(), and not via the address bar.
33 initializePage: function() {
34 Page
.prototype.initializePage
.call(this);
36 // AlertOverlay is special in that it is not tied to one page or overlay.
37 this.alwaysOnTop
= true;
40 $('alertOverlayOk').onclick = function(event
) {
44 $('alertOverlayCancel').onclick = function(event
) {
50 * Handle the 'ok' button. Clear the overlay and call the ok callback if
54 handleOK_: function() {
55 PageManager
.closeOverlay();
56 if (this.okCallback
!= undefined) {
57 this.okCallback
.call();
62 * Handle the 'cancel' button. Clear the overlay and call the cancel
63 * callback if available.
66 handleCancel_: function() {
67 PageManager
.closeOverlay();
68 if (this.cancelCallback
!= undefined) {
69 this.cancelCallback
.call();
74 * The page is getting hidden. Don't let it be shown again.
77 willHidePage: function() {
78 this.canShow_
= false;
82 canShowPage: function() {
88 * Show an alert overlay with the given message, button titles, and
90 * @param {string} title The alert title to display to the user.
91 * @param {string} message The alert message to display to the user.
92 * @param {string} okTitle The title of the OK button. If undefined or empty,
94 * @param {string} cancelTitle The title of the cancel button. If undefined or
95 * empty, no button is shown.
96 * @param {function()} okCallback A function to be called when the user
97 * presses the ok button. The alert window will be closed automatically.
99 * @param {function()} cancelCallback A function to be called when the user
100 * presses the cancel button. The alert window will be closed
101 * automatically. Can be undefined.
103 AlertOverlay
.show = function(
104 title
, message
, okTitle
, cancelTitle
, okCallback
, cancelCallback
) {
105 if (title
!= undefined) {
106 $('alertOverlayTitle').textContent
= title
;
107 $('alertOverlayTitle').style
.display
= 'block';
109 $('alertOverlayTitle').style
.display
= 'none';
112 if (message
!= undefined) {
113 $('alertOverlayMessage').textContent
= message
;
114 $('alertOverlayMessage').style
.display
= 'block';
116 $('alertOverlayMessage').style
.display
= 'none';
119 if (okTitle
!= undefined && okTitle
!= '') {
120 $('alertOverlayOk').textContent
= okTitle
;
121 $('alertOverlayOk').style
.display
= 'block';
123 $('alertOverlayOk').style
.display
= 'none';
126 if (cancelTitle
!= undefined && cancelTitle
!= '') {
127 $('alertOverlayCancel').textContent
= cancelTitle
;
128 $('alertOverlayCancel').style
.display
= 'inline';
130 $('alertOverlayCancel').style
.display
= 'none';
133 var alertOverlay
= AlertOverlay
.getInstance();
134 alertOverlay
.okCallback
= okCallback
;
135 alertOverlay
.cancelCallback
= cancelCallback
;
136 alertOverlay
.canShow_
= true;
138 // Intentionally don't show the URL in the location bar as we don't want
139 // people trying to navigate here by hand.
140 PageManager
.showPageByName('alertOverlay', false);
145 AlertOverlay
: AlertOverlay