|
@@ -7,11 +7,18 @@ import UIUtil from './UIUtil';
|
7
|
7
|
* Flag for enable/disable of the notifications.
|
8
|
8
|
* @type {boolean}
|
9
|
9
|
*/
|
10
|
|
-var notificationsEnabled = true;
|
|
10
|
+let notificationsEnabled = true;
|
|
11
|
+
|
|
12
|
+/**
|
|
13
|
+ * Flag for enabling/disabling popups.
|
|
14
|
+ * @type {boolean}
|
|
15
|
+ */
|
|
16
|
+let popupEnabled = true;
|
|
17
|
+
|
|
18
|
+var messageHandler = {
|
|
19
|
+ OK: "dialog.OK",
|
|
20
|
+ CANCEL: "dialog.Cancel",
|
11
|
21
|
|
12
|
|
-var messageHandler = (function(my) {
|
13
|
|
- my.OK = "dialog.OK",
|
14
|
|
- my.CANCEL = "dialog.Cancel",
|
15
|
22
|
/**
|
16
|
23
|
* Shows a message to the user.
|
17
|
24
|
*
|
|
@@ -24,7 +31,10 @@ var messageHandler = (function(my) {
|
24
|
31
|
* @param message the message to show. If a falsy value is provided,
|
25
|
32
|
* messageKey will be used to get a message via the translation API.
|
26
|
33
|
*/
|
27
|
|
- my.openMessageDialog = function(titleKey, messageKey, title, message) {
|
|
34
|
+ openMessageDialog: function(titleKey, messageKey, title, message) {
|
|
35
|
+ if (!popupEnabled)
|
|
36
|
+ return;
|
|
37
|
+
|
28
|
38
|
if (!title) {
|
29
|
39
|
title = APP.translation.generateTranslationHTML(titleKey);
|
30
|
40
|
}
|
|
@@ -35,8 +45,7 @@ var messageHandler = (function(my) {
|
35
|
45
|
$.prompt(message,
|
36
|
46
|
{title: title, persistent: false}
|
37
|
47
|
);
|
38
|
|
- };
|
39
|
|
-
|
|
48
|
+ },
|
40
|
49
|
/**
|
41
|
50
|
* Shows a message to the user with two buttons: first is given as a
|
42
|
51
|
* parameter and the second is Cancel.
|
|
@@ -55,9 +64,13 @@ var messageHandler = (function(my) {
|
55
|
64
|
* @param defaultButton index of default button which will be activated when
|
56
|
65
|
* the user press 'enter'. Indexed from 0.
|
57
|
66
|
*/
|
58
|
|
- my.openTwoButtonDialog = function(titleKey, titleString, msgKey, msgString,
|
|
67
|
+ openTwoButtonDialog: function(titleKey, titleString, msgKey, msgString,
|
59
|
68
|
persistent, leftButtonKey, submitFunction, loadedFunction,
|
60
|
69
|
closeFunction, focus, defaultButton) {
|
|
70
|
+
|
|
71
|
+ if (!popupEnabled)
|
|
72
|
+ return;
|
|
73
|
+
|
61
|
74
|
var buttons = [];
|
62
|
75
|
|
63
|
76
|
var leftButton = APP.translation.generateTranslationHTML(leftButtonKey);
|
|
@@ -84,7 +97,7 @@ var messageHandler = (function(my) {
|
84
|
97
|
submit: submitFunction,
|
85
|
98
|
close: closeFunction
|
86
|
99
|
});
|
87
|
|
- };
|
|
100
|
+ },
|
88
|
101
|
|
89
|
102
|
/**
|
90
|
103
|
* Shows a message to the user with two buttons: first is given as a
|
|
@@ -101,8 +114,11 @@ var messageHandler = (function(my) {
|
101
|
114
|
* @param loadedFunction function to be called after the prompt is fully
|
102
|
115
|
* loaded
|
103
|
116
|
*/
|
104
|
|
- my.openDialog = function (titleString, msgString, persistent, buttons,
|
|
117
|
+ openDialog: function (titleString, msgString, persistent, buttons,
|
105
|
118
|
submitFunction, loadedFunction) {
|
|
119
|
+ if (!popupEnabled)
|
|
120
|
+ return;
|
|
121
|
+
|
106
|
122
|
var args = {
|
107
|
123
|
title: titleString,
|
108
|
124
|
persistent: persistent,
|
|
@@ -115,23 +131,26 @@ var messageHandler = (function(my) {
|
115
|
131
|
args.closeText = '';
|
116
|
132
|
}
|
117
|
133
|
return new Impromptu(msgString, args);
|
118
|
|
- };
|
|
134
|
+ },
|
119
|
135
|
|
120
|
136
|
/**
|
121
|
137
|
* Closes currently opened dialog.
|
122
|
138
|
*/
|
123
|
|
- my.closeDialog = function () {
|
|
139
|
+ closeDialog: function () {
|
124
|
140
|
$.prompt.close();
|
125
|
|
- };
|
|
141
|
+ },
|
126
|
142
|
|
127
|
143
|
/**
|
128
|
144
|
* Shows a dialog with different states to the user.
|
129
|
145
|
*
|
130
|
146
|
* @param statesObject object containing all the states of the dialog.
|
131
|
147
|
*/
|
132
|
|
- my.openDialogWithStates = function (statesObject, options) {
|
|
148
|
+ openDialogWithStates: function (statesObject, options) {
|
|
149
|
+ if (!popupEnabled)
|
|
150
|
+ return;
|
|
151
|
+
|
133
|
152
|
return new Impromptu(statesObject, options);
|
134
|
|
- };
|
|
153
|
+ },
|
135
|
154
|
|
136
|
155
|
/**
|
137
|
156
|
* Opens new popup window for given <tt>url</tt> centered over current
|
|
@@ -146,7 +165,10 @@ var messageHandler = (function(my) {
|
146
|
165
|
* @returns {object} popup window object if opened successfully or undefined
|
147
|
166
|
* in case we failed to open it(popup blocked)
|
148
|
167
|
*/
|
149
|
|
- my.openCenteredPopup = function (url, w, h, onPopupClosed) {
|
|
168
|
+ openCenteredPopup: function (url, w, h, onPopupClosed) {
|
|
169
|
+ if (!popupEnabled)
|
|
170
|
+ return;
|
|
171
|
+
|
150
|
172
|
var l = window.screenX + (window.innerWidth / 2) - (w / 2);
|
151
|
173
|
var t = window.screenY + (window.innerHeight / 2) - (h / 2);
|
152
|
174
|
var popup = window.open(
|
|
@@ -161,7 +183,7 @@ var messageHandler = (function(my) {
|
161
|
183
|
}, 200);
|
162
|
184
|
}
|
163
|
185
|
return popup;
|
164
|
|
- };
|
|
186
|
+ },
|
165
|
187
|
|
166
|
188
|
/**
|
167
|
189
|
* Shows a dialog prompting the user to send an error report.
|
|
@@ -170,18 +192,18 @@ var messageHandler = (function(my) {
|
170
|
192
|
* @param msgKey the text of the message
|
171
|
193
|
* @param error the error that is being reported
|
172
|
194
|
*/
|
173
|
|
- my.openReportDialog = function(titleKey, msgKey, error) {
|
174
|
|
- my.openMessageDialog(titleKey, msgKey);
|
|
195
|
+ openReportDialog: function(titleKey, msgKey, error) {
|
|
196
|
+ this.openMessageDialog(titleKey, msgKey);
|
175
|
197
|
console.log(error);
|
176
|
198
|
//FIXME send the error to the server
|
177
|
|
- };
|
|
199
|
+ },
|
178
|
200
|
|
179
|
201
|
/**
|
180
|
202
|
* Shows an error dialog to the user.
|
181
|
203
|
* @param titleKey the title of the message.
|
182
|
204
|
* @param msgKey the text of the message.
|
183
|
205
|
*/
|
184
|
|
- my.showError = function(titleKey, msgKey) {
|
|
206
|
+ showError: function(titleKey, msgKey) {
|
185
|
207
|
|
186
|
208
|
if (!titleKey) {
|
187
|
209
|
titleKey = "dialog.oops";
|
|
@@ -190,7 +212,7 @@ var messageHandler = (function(my) {
|
190
|
212
|
msgKey = "dialog.defaultError";
|
191
|
213
|
}
|
192
|
214
|
messageHandler.openMessageDialog(titleKey, msgKey);
|
193
|
|
- };
|
|
215
|
+ },
|
194
|
216
|
|
195
|
217
|
/**
|
196
|
218
|
* Displayes notification.
|
|
@@ -201,10 +223,12 @@ var messageHandler = (function(my) {
|
201
|
223
|
* @param messageArguments object with the arguments for the message.
|
202
|
224
|
* @param options object with language options.
|
203
|
225
|
*/
|
204
|
|
- my.notify = function(displayName, displayNameKey,
|
|
226
|
+ notify: function(displayName, displayNameKey,
|
205
|
227
|
cls, messageKey, messageArguments, options) {
|
|
228
|
+
|
206
|
229
|
if(!notificationsEnabled)
|
207
|
230
|
return;
|
|
231
|
+
|
208
|
232
|
var displayNameSpan = '<span class="nickname" ';
|
209
|
233
|
if (displayName) {
|
210
|
234
|
displayNameSpan += ">" + UIUtil.escapeHtml(displayName);
|
|
@@ -222,31 +246,26 @@ var messageHandler = (function(my) {
|
222
|
246
|
APP.translation.translateString(messageKey,
|
223
|
247
|
messageArguments) +
|
224
|
248
|
'</span>', null, options);
|
225
|
|
- };
|
|
249
|
+ },
|
226
|
250
|
|
227
|
251
|
/**
|
228
|
252
|
* Removes the toaster.
|
229
|
253
|
* @param toasterElement
|
230
|
254
|
*/
|
231
|
|
- my.remove = function(toasterElement) {
|
|
255
|
+ remove: function(toasterElement) {
|
232
|
256
|
toasterElement.remove();
|
233
|
|
- };
|
234
|
|
-
|
235
|
|
- /**
|
236
|
|
- * Disables notifications.
|
237
|
|
- */
|
238
|
|
- my.disableNotifications = function () {
|
239
|
|
- notificationsEnabled = false;
|
240
|
|
- };
|
|
257
|
+ },
|
241
|
258
|
|
242
|
259
|
/**
|
243
|
|
- * Enables notifications.
|
|
260
|
+ * Enables / disables notifications.
|
244
|
261
|
*/
|
245
|
|
- my.enableNotifications = function () {
|
246
|
|
- notificationsEnabled = true;
|
247
|
|
- };
|
|
262
|
+ enableNotifications: function (enable) {
|
|
263
|
+ notificationsEnabled = enable;
|
|
264
|
+ },
|
248
|
265
|
|
249
|
|
- return my;
|
250
|
|
-}(messageHandler || {}));
|
|
266
|
+ enablePopups: function (enable) {
|
|
267
|
+ popupEnabled = enable;
|
|
268
|
+ }
|
|
269
|
+};
|
251
|
270
|
|
252
|
271
|
module.exports = messageHandler;
|