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
|
// Copyright (c) 2010 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 OptionsPage = options.OptionsPage;
/**
* AlertOverlay class
* Encapsulated handling of a generic alert.
* @class
*/
function AlertOverlay() {
OptionsPage.call(this, 'alertOverlay', '', 'alertOverlay');
}
cr.addSingletonGetter(AlertOverlay);
AlertOverlay.prototype = {
// Inherit AlertOverlay from OptionsPage.
__proto__: OptionsPage.prototype,
/**
* Initialize the page.
*/
initializePage: function() {
// Call base class implementation to start preference initialization.
OptionsPage.prototype.initializePage.call(this);
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() {
OptionsPage.clearOverlays();
if (this.okCallback != undefined) {
this.okCallback.call();
}
},
/**
* Handle the 'cancel' button. Clear the overlay and call the cancel
* callback if available.
* @private
*/
handleCancel_: function() {
OptionsPage.clearOverlays();
if (this.cancelCallback != undefined) {
this.cancelCallback.call();
}
}
};
/**
* 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. Can be undefined.
* @param {string} cancelTitle The title of the cancel button. Can be
* undefined.
* @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';
}
$('alertOverlayOk').textContent =
(okTitle != undefined ? okTitle
: localStrings.getString('ok'));
if (cancelTitle != '') {
$('alertOverlayCancel').textContent =
(cancelTitle != undefined ? cancelTitle
: localStrings.getString('cancel'));
$('alertOverlayCancel').style.display = 'inline';
} else {
$('alertOverlayCancel').style.display = 'none';
}
AlertOverlay.getInstance().okCallback = okCallback;
AlertOverlay.getInstance().cancelCallback = cancelCallback;
OptionsPage.showOverlay('alertOverlay');
}
// Export
return {
AlertOverlay: AlertOverlay
};
});
|