|
|
@@ -1,6 +1,7 @@
|
|
1
|
1
|
/* global $, APP, toastr, Impromptu */
|
|
2
|
2
|
|
|
3
|
3
|
import UIUtil from './UIUtil';
|
|
|
4
|
+import jitsiLocalStorage from '../../util/JitsiLocalStorage';
|
|
4
|
5
|
|
|
5
|
6
|
/**
|
|
6
|
7
|
* Flag for enable/disable of the notifications.
|
|
|
@@ -20,6 +21,91 @@ let popupEnabled = true;
|
|
20
|
21
|
*/
|
|
21
|
22
|
let twoButtonDialog = null;
|
|
22
|
23
|
|
|
|
24
|
+/**
|
|
|
25
|
+ * Generates html for dont show again checkbox.
|
|
|
26
|
+ * @param {object} options options
|
|
|
27
|
+ * @param {string} options.id the id of the checkbox.
|
|
|
28
|
+ * @param {string} options.textKey the key for the text displayed next to
|
|
|
29
|
+ * checkbox
|
|
|
30
|
+ * @param {boolean} options.checked if true the checkbox is foing to be checked
|
|
|
31
|
+ * by default.
|
|
|
32
|
+ * @returns {string}
|
|
|
33
|
+ */
|
|
|
34
|
+function generateDontShowCheckbox(options) {
|
|
|
35
|
+ if(!isDontShowAgainEnabled(options)) {
|
|
|
36
|
+ return "";
|
|
|
37
|
+ }
|
|
|
38
|
+
|
|
|
39
|
+ let checked
|
|
|
40
|
+ = (options.checked === true) ? "checked" : "";
|
|
|
41
|
+ return `<br />
|
|
|
42
|
+ <label>
|
|
|
43
|
+ <input type='checkbox' ${checked} id='${options.id}' />
|
|
|
44
|
+ <span data-i18n='${options.textKey}'></span>
|
|
|
45
|
+ </label>`;
|
|
|
46
|
+}
|
|
|
47
|
+
|
|
|
48
|
+/**
|
|
|
49
|
+ * Checks whether the dont show again checkbox was checked before.
|
|
|
50
|
+ * @param {object} options - options for dont show again checkbox.
|
|
|
51
|
+ * @param {string} options.id the id of the checkbox.
|
|
|
52
|
+ * @param {string} options.localStorageKey the key for the local storage. if
|
|
|
53
|
+ * not provided options.id will be used.
|
|
|
54
|
+ * @returns {boolean} true if the dialog mustn't be displayed and
|
|
|
55
|
+ * false otherwise.
|
|
|
56
|
+ */
|
|
|
57
|
+function dontShowTheDialog(options) {
|
|
|
58
|
+ if(isDontShowAgainEnabled(options)) {
|
|
|
59
|
+ if(jitsiLocalStorage.getItem(options.localStorageKey || options.id)
|
|
|
60
|
+ === "true") {
|
|
|
61
|
+ return true;
|
|
|
62
|
+ }
|
|
|
63
|
+ }
|
|
|
64
|
+ return false;
|
|
|
65
|
+}
|
|
|
66
|
+
|
|
|
67
|
+/**
|
|
|
68
|
+ * Wraps the submit function to process the dont show again status and store
|
|
|
69
|
+ * it.
|
|
|
70
|
+ * @param {object} options - options for dont show again checkbox.
|
|
|
71
|
+ * @param {string} options.id the id of the checkbox.
|
|
|
72
|
+ * @param {Array} options.buttonValues The button values that will trigger
|
|
|
73
|
+ * storing he checkbox value
|
|
|
74
|
+ * @param {string} options.localStorageKey the key for the local storage. if
|
|
|
75
|
+ * not provided options.id will be used.
|
|
|
76
|
+ * @param {Function} submitFunction the submit function to be wrapped
|
|
|
77
|
+ * @returns {Function} wrapped function
|
|
|
78
|
+ */
|
|
|
79
|
+function dontShowAgainSubmitFunctionWrapper(options, submitFunction) {
|
|
|
80
|
+ if(isDontShowAgainEnabled(options)) {
|
|
|
81
|
+ return (...args) => {
|
|
|
82
|
+ console.debug(args, options.buttonValues);
|
|
|
83
|
+ //args[1] is the value associated with the pressed button
|
|
|
84
|
+ if(!options.buttonValues || options.buttonValues.length === 0
|
|
|
85
|
+ || options.buttonValues.indexOf(args[1]) !== -1 ) {
|
|
|
86
|
+ let checkbox = $(`#${options.id}`);
|
|
|
87
|
+ if (checkbox.length) {
|
|
|
88
|
+ jitsiLocalStorage.setItem(
|
|
|
89
|
+ options.localStorageKey || options.id,
|
|
|
90
|
+ checkbox.prop("checked"));
|
|
|
91
|
+ }
|
|
|
92
|
+ }
|
|
|
93
|
+ submitFunction(...args);
|
|
|
94
|
+ };
|
|
|
95
|
+ } else {
|
|
|
96
|
+ return submitFunction;
|
|
|
97
|
+ }
|
|
|
98
|
+}
|
|
|
99
|
+
|
|
|
100
|
+/**
|
|
|
101
|
+ * Check whether dont show again checkbox is enabled or not.
|
|
|
102
|
+ * @param {object} options - options for dont show again checkbox.
|
|
|
103
|
+ * @returns {boolean} true if enabled and false if not.
|
|
|
104
|
+ */
|
|
|
105
|
+function isDontShowAgainEnabled(options) {
|
|
|
106
|
+ return typeof options === "object";
|
|
|
107
|
+}
|
|
|
108
|
+
|
|
23
|
109
|
var messageHandler = {
|
|
24
|
110
|
OK: "dialog.OK",
|
|
25
|
111
|
CANCEL: "dialog.Cancel",
|
|
|
@@ -72,6 +158,16 @@ var messageHandler = {
|
|
72
|
158
|
* the dialog is opened
|
|
73
|
159
|
* @param defaultButton index of default button which will be activated when
|
|
74
|
160
|
* the user press 'enter'. Indexed from 0.
|
|
|
161
|
+ * @param {object} dontShowAgain - options for dont show again checkbox.
|
|
|
162
|
+ * @param {string} dontShowAgain.id the id of the checkbox.
|
|
|
163
|
+ * @param {string} dontShowAgain.textKey the key for the text displayed
|
|
|
164
|
+ * next to checkbox
|
|
|
165
|
+ * @param {boolean} dontShowAgain.checked if true the checkbox is foing to
|
|
|
166
|
+ * be checked
|
|
|
167
|
+ * @param {Array} dontShowAgain.buttonValues The button values that will
|
|
|
168
|
+ * trigger storing the checkbox value
|
|
|
169
|
+ * @param {string} dontShowAgain.localStorageKey the key for the local
|
|
|
170
|
+ * storage. if not provided dontShowAgain.id will be used.
|
|
75
|
171
|
* @return the prompt that was created, or null
|
|
76
|
172
|
*/
|
|
77
|
173
|
openTwoButtonDialog: function(options) {
|
|
|
@@ -87,12 +183,20 @@ var messageHandler = {
|
|
87
|
183
|
size,
|
|
88
|
184
|
defaultButton,
|
|
89
|
185
|
wrapperClass,
|
|
90
|
|
- classes
|
|
|
186
|
+ classes,
|
|
|
187
|
+ dontShowAgain
|
|
91
|
188
|
} = options;
|
|
92
|
189
|
|
|
93
|
190
|
if (!popupEnabled || twoButtonDialog)
|
|
94
|
191
|
return null;
|
|
95
|
192
|
|
|
|
193
|
+ if(dontShowTheDialog(dontShowAgain)) {
|
|
|
194
|
+ // Maybe we should pass some parameters here? I'm not sure
|
|
|
195
|
+ // and currently we don't need any parameters.
|
|
|
196
|
+ submitFunction();
|
|
|
197
|
+ return null;
|
|
|
198
|
+ }
|
|
|
199
|
+
|
|
96
|
200
|
var buttons = [];
|
|
97
|
201
|
|
|
98
|
202
|
var leftButton = leftButtonKey ?
|
|
|
@@ -108,6 +212,7 @@ var messageHandler = {
|
|
108
|
212
|
if (msgKey) {
|
|
109
|
213
|
message = APP.translation.generateTranslationHTML(msgKey);
|
|
110
|
214
|
}
|
|
|
215
|
+ message += generateDontShowCheckbox(dontShowAgain);
|
|
111
|
216
|
classes = classes || this._getDialogClasses(size);
|
|
112
|
217
|
if (wrapperClass) {
|
|
113
|
218
|
classes.prompt += ` ${wrapperClass}`;
|
|
|
@@ -122,13 +227,13 @@ var messageHandler = {
|
|
122
|
227
|
loaded: loadedFunction,
|
|
123
|
228
|
promptspeed: 0,
|
|
124
|
229
|
classes,
|
|
125
|
|
- submit: function (e, v, m, f) {
|
|
126
|
|
- twoButtonDialog = null;
|
|
127
|
|
- if (v){
|
|
128
|
|
- if (submitFunction)
|
|
|
230
|
+ submit: dontShowAgainSubmitFunctionWrapper(dontShowAgain,
|
|
|
231
|
+ function (e, v, m, f) {
|
|
|
232
|
+ twoButtonDialog = null;
|
|
|
233
|
+ if (v && submitFunction) {
|
|
129
|
234
|
submitFunction(e, v, m, f);
|
|
130
|
|
- }
|
|
131
|
|
- },
|
|
|
235
|
+ }
|
|
|
236
|
+ }),
|
|
132
|
237
|
close: function (e, v, m, f) {
|
|
133
|
238
|
twoButtonDialog = null;
|
|
134
|
239
|
if (closeFunction) {
|
|
|
@@ -155,12 +260,29 @@ var messageHandler = {
|
|
155
|
260
|
* @param loadedFunction function to be called after the prompt is fully
|
|
156
|
261
|
* loaded
|
|
157
|
262
|
* @param closeFunction function to be called on dialog close
|
|
|
263
|
+ * @param {object} dontShowAgain - options for dont show again checkbox.
|
|
|
264
|
+ * @param {string} dontShowAgain.id the id of the checkbox.
|
|
|
265
|
+ * @param {string} dontShowAgain.textKey the key for the text displayed
|
|
|
266
|
+ * next to checkbox
|
|
|
267
|
+ * @param {boolean} dontShowAgain.checked if true the checkbox is foing to
|
|
|
268
|
+ * be checked
|
|
|
269
|
+ * @param {Array} dontShowAgain.buttonValues The button values that will
|
|
|
270
|
+ * trigger storing the checkbox value
|
|
|
271
|
+ * @param {string} dontShowAgain.localStorageKey the key for the local
|
|
|
272
|
+ * storage. if not provided dontShowAgain.id will be used.
|
|
158
|
273
|
*/
|
|
159
|
274
|
openDialog: function (titleKey, msgString, persistent, buttons,
|
|
160
|
|
- submitFunction, loadedFunction, closeFunction) {
|
|
|
275
|
+ submitFunction, loadedFunction, closeFunction, dontShowAgain) {
|
|
161
|
276
|
if (!popupEnabled)
|
|
162
|
277
|
return;
|
|
163
|
278
|
|
|
|
279
|
+ if(dontShowTheDialog(dontShowAgain)) {
|
|
|
280
|
+ // Maybe we should pass some parameters here? I'm not sure
|
|
|
281
|
+ // and currently we don't need any parameters.
|
|
|
282
|
+ submitFunction();
|
|
|
283
|
+ return;
|
|
|
284
|
+ }
|
|
|
285
|
+
|
|
164
|
286
|
let args = {
|
|
165
|
287
|
title: this._getFormattedTitleString(titleKey),
|
|
166
|
288
|
persistent: persistent,
|
|
|
@@ -168,7 +290,8 @@ var messageHandler = {
|
|
168
|
290
|
defaultButton: 1,
|
|
169
|
291
|
promptspeed: 0,
|
|
170
|
292
|
loaded: loadedFunction,
|
|
171
|
|
- submit: submitFunction,
|
|
|
293
|
+ submit: dontShowAgainSubmitFunctionWrapper(
|
|
|
294
|
+ dontShowAgain, submitFunction),
|
|
172
|
295
|
close: closeFunction,
|
|
173
|
296
|
classes: this._getDialogClasses()
|
|
174
|
297
|
};
|
|
|
@@ -177,7 +300,8 @@ var messageHandler = {
|
|
177
|
300
|
args.closeText = '';
|
|
178
|
301
|
}
|
|
179
|
302
|
|
|
180
|
|
- let dialog = new Impromptu(msgString, args);
|
|
|
303
|
+ let dialog = new Impromptu(
|
|
|
304
|
+ msgString + generateDontShowCheckbox(dontShowAgain), args);
|
|
181
|
305
|
APP.translation.translateElement(dialog.getPrompt());
|
|
182
|
306
|
return dialog;
|
|
183
|
307
|
},
|