1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
cr.define('options', function() {
var Page = cr.ui.pageManager.Page;
var PageManager = cr.ui.pageManager.PageManager;
/**
* AlertOverlay class
* Encapsulated handling of a generic alert.
* @constructor
* @extends {cr.ui.pageManager.Page}
*/
function AlertOverlay() {
Page.call(this, 'alertOverlay', '', 'alertOverlay');
}
cr.addSingletonGetter(AlertOverlay);
AlertOverlay.prototype = {
// Inherit AlertOverlay from Page.
__proto__: Page.prototype,
/**
* Whether the page can be shown. Used to make sure the page is only
* shown via AlertOverlay.Show(), and not via the address bar.
* @private
*/
canShow_: false,
/** @override */
initializePage: function() {
Page.prototype.initializePage.call(this);
// AlertOverlay is special in that it is not tied to one page or overlay.
this.alwaysOnTop = true;
var self = this;
$('alertOverlayOk').onclick = function(event) {
self.handleOK_();
};
$('alertOverlayCancel').onclick = function(event) {
self.handleCancel_();
};
},
/**
* Handle the 'ok' button. Clear the overlay and call the ok callback if
* available.
* @private
*/
handleOK_: function() {
PageManager.closeOverlay();
if (this.okCallback != undefined) {
this.okCallback.call();
}
},
/**
* Handle the 'cancel' button. Clear the overlay and call the cancel
* callback if available.
* @private
*/
handleCancel_: function() {
PageManager.closeOverlay();
if (this.cancelCallback != undefined) {
this.cancelCallback.call();
}
},
/**
* The page is getting hidden. Don't let it be shown again.
* @override
*/
willHidePage: function() {
this.canShow_ = false;
},
/** @override */
canShowPage: function() {
return this.canShow_;
},
};
/**
* Show an alert overlay with the given message, button titles, and
* callbacks.
* @param {string} title The alert title to display to the user.
* @param {string} message The alert message to display to the user.
* @param {string} okTitle The title of the OK button. If undefined or empty,
* no button is shown.
* @param {string} cancelTitle The title of the cancel button. If undefined or
* empty, no button is shown.
* @param {function()} okCallback A function to be called when the user
* presses the ok button. The alert window will be closed automatically.
* Can be undefined.
* @param {function()} cancelCallback A function to be called when the user
* presses the cancel button. The alert window will be closed
* automatically. Can be undefined.
*/
AlertOverlay.show = function(
title, message, okTitle, cancelTitle, okCallback, cancelCallback) {
if (title != undefined) {
$('alertOverlayTitle').textContent = title;
$('alertOverlayTitle').style.display = 'block';
} else {
$('alertOverlayTitle').style.display = 'none';
}
if (message != undefined) {
$('alertOverlayMessage').textContent = message;
$('alertOverlayMessage').style.display = 'block';
} else {
$('alertOverlayMessage').style.display = 'none';
}
if (okTitle != undefined && okTitle != '') {
$('alertOverlayOk').textContent = okTitle;
$('alertOverlayOk').style.display = 'block';
} else {
$('alertOverlayOk').style.display = 'none';
}
if (cancelTitle != undefined && cancelTitle != '') {
$('alertOverlayCancel').textContent = cancelTitle;
$('alertOverlayCancel').style.display = 'inline';
} else {
$('alertOverlayCancel').style.display = 'none';
}
var alertOverlay = AlertOverlay.getInstance();
alertOverlay.okCallback = okCallback;
alertOverlay.cancelCallback = cancelCallback;
alertOverlay.canShow_ = true;
// Intentionally don't show the URL in the location bar as we don't want
// people trying to navigate here by hand.
PageManager.showPageByName('alertOverlay', false);
};
// Export
return {
AlertOverlay: AlertOverlay
};
});
|