|
@@ -1,8 +1,5 @@
|
1
|
1
|
/* global $, APP */
|
2
|
2
|
|
3
|
|
-import { jitsiLocalStorage } from '@jitsi/js-utils';
|
4
|
|
-import Logger from 'jitsi-meet-logger';
|
5
|
|
-
|
6
|
3
|
import {
|
7
|
4
|
NOTIFICATION_TIMEOUT,
|
8
|
5
|
showErrorNotification,
|
|
@@ -10,223 +7,10 @@ import {
|
10
|
7
|
showWarningNotification
|
11
|
8
|
} from '../../../react/features/notifications';
|
12
|
9
|
|
13
|
|
-const logger = Logger.getLogger(__filename);
|
14
|
|
-
|
15
|
|
-/**
|
16
|
|
- * Currently displayed two button dialog.
|
17
|
|
- * @type {null}
|
18
|
|
- */
|
19
|
|
-let twoButtonDialog = null;
|
20
|
|
-
|
21
|
|
-/**
|
22
|
|
- * Generates html for dont show again checkbox.
|
23
|
|
- * @param {object} options options
|
24
|
|
- * @param {string} options.id the id of the checkbox.
|
25
|
|
- * @param {string} options.textKey the key for the text displayed next to
|
26
|
|
- * checkbox
|
27
|
|
- * @param {boolean} options.checked if true the checkbox is foing to be checked
|
28
|
|
- * by default.
|
29
|
|
- * @returns {string}
|
30
|
|
- */
|
31
|
|
-function generateDontShowCheckbox(options) {
|
32
|
|
- if (!isDontShowAgainEnabled(options)) {
|
33
|
|
- return '';
|
34
|
|
- }
|
35
|
|
-
|
36
|
|
- const checked
|
37
|
|
- = options.checked === true ? 'checked' : '';
|
38
|
|
-
|
39
|
|
-
|
40
|
|
- return `<br />
|
41
|
|
- <label>
|
42
|
|
- <input type='checkbox' ${checked} id='${options.id}' />
|
43
|
|
- <span data-i18n='${options.textKey}'></span>
|
44
|
|
- </label>`;
|
45
|
|
-}
|
46
|
|
-
|
47
|
|
-/**
|
48
|
|
- * Checks whether the dont show again checkbox was checked before.
|
49
|
|
- * @param {object} options - options for dont show again checkbox.
|
50
|
|
- * @param {string} options.id the id of the checkbox.
|
51
|
|
- * @param {string} options.localStorageKey the key for the local storage. if
|
52
|
|
- * not provided options.id will be used.
|
53
|
|
- * @returns {boolean} true if the dialog mustn't be displayed and
|
54
|
|
- * false otherwise.
|
55
|
|
- */
|
56
|
|
-function dontShowTheDialog(options) {
|
57
|
|
- if (isDontShowAgainEnabled(options)) {
|
58
|
|
- if (jitsiLocalStorage.getItem(options.localStorageKey || options.id)
|
59
|
|
- === 'true') {
|
60
|
|
- return true;
|
61
|
|
- }
|
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
|
|
- logger.debug(args, options.buttonValues);
|
83
|
|
-
|
84
|
|
- // args[1] is the value associated with the pressed button
|
85
|
|
- if (!options.buttonValues || options.buttonValues.length === 0
|
86
|
|
- || options.buttonValues.indexOf(args[1]) !== -1) {
|
87
|
|
- const checkbox = $(`#${options.id}`);
|
88
|
|
-
|
89
|
|
- if (checkbox.length) {
|
90
|
|
- jitsiLocalStorage.setItem(
|
91
|
|
- options.localStorageKey || options.id,
|
92
|
|
- checkbox.prop('checked'));
|
93
|
|
- }
|
94
|
|
- }
|
95
|
|
- submitFunction(...args);
|
96
|
|
- };
|
97
|
|
- }
|
98
|
|
-
|
99
|
|
- return submitFunction;
|
100
|
|
-
|
101
|
|
-}
|
102
|
|
-
|
103
|
|
-/**
|
104
|
|
- * Check whether dont show again checkbox is enabled or not.
|
105
|
|
- * @param {object} options - options for dont show again checkbox.
|
106
|
|
- * @returns {boolean} true if enabled and false if not.
|
107
|
|
- */
|
108
|
|
-function isDontShowAgainEnabled(options) {
|
109
|
|
- return typeof options === 'object';
|
110
|
|
-}
|
111
|
|
-
|
112
|
10
|
const messageHandler = {
|
113
|
11
|
OK: 'dialog.OK',
|
114
|
12
|
CANCEL: 'dialog.Cancel',
|
115
|
13
|
|
116
|
|
- /**
|
117
|
|
- * Shows a message to the user with two buttons: first is given as a
|
118
|
|
- * parameter and the second is Cancel.
|
119
|
|
- *
|
120
|
|
- * @param titleKey the key for the title of the message
|
121
|
|
- * @param msgKey the key for the message
|
122
|
|
- * @param msgString the text of the message
|
123
|
|
- * @param persistent boolean value which determines whether the message is
|
124
|
|
- * persistent or not
|
125
|
|
- * @param leftButton the fist button's text
|
126
|
|
- * @param submitFunction function to be called on submit
|
127
|
|
- * @param loadedFunction function to be called after the prompt is fully
|
128
|
|
- * loaded
|
129
|
|
- * @param closeFunction function to be called after the prompt is closed
|
130
|
|
- * @param focus optional focus selector or button index to be focused after
|
131
|
|
- * the dialog is opened
|
132
|
|
- * @param defaultButton index of default button which will be activated when
|
133
|
|
- * the user press 'enter'. Indexed from 0.
|
134
|
|
- * @param {object} dontShowAgain - options for dont show again checkbox.
|
135
|
|
- * @param {string} dontShowAgain.id the id of the checkbox.
|
136
|
|
- * @param {string} dontShowAgain.textKey the key for the text displayed
|
137
|
|
- * next to checkbox
|
138
|
|
- * @param {boolean} dontShowAgain.checked if true the checkbox is foing to
|
139
|
|
- * be checked
|
140
|
|
- * @param {Array} dontShowAgain.buttonValues The button values that will
|
141
|
|
- * trigger storing the checkbox value
|
142
|
|
- * @param {string} dontShowAgain.localStorageKey the key for the local
|
143
|
|
- * storage. if not provided dontShowAgain.id will be used.
|
144
|
|
- * @return the prompt that was created, or null
|
145
|
|
- */
|
146
|
|
- openTwoButtonDialog(options) {
|
147
|
|
- const {
|
148
|
|
- titleKey,
|
149
|
|
- msgKey,
|
150
|
|
- msgString,
|
151
|
|
- leftButtonKey,
|
152
|
|
- submitFunction,
|
153
|
|
- loadedFunction,
|
154
|
|
- closeFunction,
|
155
|
|
- focus,
|
156
|
|
- size,
|
157
|
|
- defaultButton,
|
158
|
|
- wrapperClass,
|
159
|
|
- dontShowAgain
|
160
|
|
- } = options;
|
161
|
|
-
|
162
|
|
- let { classes } = options;
|
163
|
|
-
|
164
|
|
- if (twoButtonDialog) {
|
165
|
|
- return null;
|
166
|
|
- }
|
167
|
|
-
|
168
|
|
- if (dontShowTheDialog(dontShowAgain)) {
|
169
|
|
- // Maybe we should pass some parameters here? I'm not sure
|
170
|
|
- // and currently we don't need any parameters.
|
171
|
|
- submitFunction();
|
172
|
|
-
|
173
|
|
- return null;
|
174
|
|
- }
|
175
|
|
-
|
176
|
|
- const buttons = [];
|
177
|
|
-
|
178
|
|
- const leftButton = leftButtonKey
|
179
|
|
- ? APP.translation.generateTranslationHTML(leftButtonKey)
|
180
|
|
- : APP.translation.generateTranslationHTML('dialog.Submit');
|
181
|
|
-
|
182
|
|
- buttons.push({ title: leftButton,
|
183
|
|
- value: true });
|
184
|
|
-
|
185
|
|
- const cancelButton
|
186
|
|
- = APP.translation.generateTranslationHTML('dialog.Cancel');
|
187
|
|
-
|
188
|
|
- buttons.push({ title: cancelButton,
|
189
|
|
- value: false });
|
190
|
|
-
|
191
|
|
- let message = msgString;
|
192
|
|
-
|
193
|
|
- if (msgKey) {
|
194
|
|
- message = APP.translation.generateTranslationHTML(msgKey);
|
195
|
|
- }
|
196
|
|
- message += generateDontShowCheckbox(dontShowAgain);
|
197
|
|
- classes = classes || this._getDialogClasses(size);
|
198
|
|
- if (wrapperClass) {
|
199
|
|
- classes.prompt += ` ${wrapperClass}`;
|
200
|
|
- }
|
201
|
|
-
|
202
|
|
- twoButtonDialog = $.prompt(message, {
|
203
|
|
- title: this._getFormattedTitleString(titleKey),
|
204
|
|
- persistent: false,
|
205
|
|
- buttons,
|
206
|
|
- defaultButton,
|
207
|
|
- focus,
|
208
|
|
- loaded: loadedFunction,
|
209
|
|
- promptspeed: 0,
|
210
|
|
- classes,
|
211
|
|
- submit: dontShowAgainSubmitFunctionWrapper(dontShowAgain,
|
212
|
|
- (e, v, m, f) => { // eslint-disable-line max-params
|
213
|
|
- twoButtonDialog = null;
|
214
|
|
- if (v && submitFunction) {
|
215
|
|
- submitFunction(e, v, m, f);
|
216
|
|
- }
|
217
|
|
- }),
|
218
|
|
- close(e, v, m, f) { // eslint-disable-line max-params
|
219
|
|
- twoButtonDialog = null;
|
220
|
|
- if (closeFunction) {
|
221
|
|
- closeFunction(e, v, m, f);
|
222
|
|
- }
|
223
|
|
- }
|
224
|
|
- });
|
225
|
|
- APP.translation.translateElement(twoButtonDialog);
|
226
|
|
-
|
227
|
|
- return $.prompt.getApi();
|
228
|
|
- },
|
229
|
|
-
|
230
|
14
|
/**
|
231
|
15
|
* Returns the formatted title string.
|
232
|
16
|
*
|