2017-07-28 17:56:49 +00:00
|
|
|
/* global $, APP */
|
2017-10-12 23:02:29 +00:00
|
|
|
const logger = require('jitsi-meet-logger').getLogger(__filename);
|
2015-08-06 23:34:40 +00:00
|
|
|
|
2016-10-27 23:31:00 +00:00
|
|
|
import jitsiLocalStorage from '../../util/JitsiLocalStorage';
|
2016-02-12 12:48:57 +00:00
|
|
|
|
2017-07-28 17:56:49 +00:00
|
|
|
import {
|
2019-03-29 13:37:50 +00:00
|
|
|
NOTIFICATION_TIMEOUT,
|
2017-11-03 19:05:03 +00:00
|
|
|
showErrorNotification,
|
|
|
|
showNotification,
|
|
|
|
showWarningNotification
|
2017-07-28 17:56:49 +00:00
|
|
|
} from '../../../react/features/notifications';
|
|
|
|
|
2016-06-08 19:34:02 +00:00
|
|
|
/**
|
|
|
|
* Flag for enabling/disabling popups.
|
|
|
|
* @type {boolean}
|
|
|
|
*/
|
|
|
|
let popupEnabled = true;
|
|
|
|
|
2016-07-06 16:00:04 +00:00
|
|
|
/**
|
|
|
|
* Currently displayed two button dialog.
|
|
|
|
* @type {null}
|
|
|
|
*/
|
|
|
|
let twoButtonDialog = null;
|
|
|
|
|
2016-10-27 23:31:00 +00:00
|
|
|
/**
|
|
|
|
* Generates html for dont show again checkbox.
|
|
|
|
* @param {object} options options
|
|
|
|
* @param {string} options.id the id of the checkbox.
|
|
|
|
* @param {string} options.textKey the key for the text displayed next to
|
|
|
|
* checkbox
|
|
|
|
* @param {boolean} options.checked if true the checkbox is foing to be checked
|
|
|
|
* by default.
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
function generateDontShowCheckbox(options) {
|
2017-10-12 23:02:29 +00:00
|
|
|
if (!isDontShowAgainEnabled(options)) {
|
|
|
|
return '';
|
2016-10-27 23:31:00 +00:00
|
|
|
}
|
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
const checked
|
|
|
|
= options.checked === true ? 'checked' : '';
|
|
|
|
|
|
|
|
|
2016-10-27 23:31:00 +00:00
|
|
|
return `<br />
|
|
|
|
<label>
|
|
|
|
<input type='checkbox' ${checked} id='${options.id}' />
|
|
|
|
<span data-i18n='${options.textKey}'></span>
|
|
|
|
</label>`;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks whether the dont show again checkbox was checked before.
|
|
|
|
* @param {object} options - options for dont show again checkbox.
|
|
|
|
* @param {string} options.id the id of the checkbox.
|
|
|
|
* @param {string} options.localStorageKey the key for the local storage. if
|
|
|
|
* not provided options.id will be used.
|
|
|
|
* @returns {boolean} true if the dialog mustn't be displayed and
|
|
|
|
* false otherwise.
|
|
|
|
*/
|
|
|
|
function dontShowTheDialog(options) {
|
2017-10-12 23:02:29 +00:00
|
|
|
if (isDontShowAgainEnabled(options)) {
|
|
|
|
if (jitsiLocalStorage.getItem(options.localStorageKey || options.id)
|
|
|
|
=== 'true') {
|
2016-10-27 23:31:00 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2017-10-12 23:02:29 +00:00
|
|
|
|
2016-10-27 23:31:00 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wraps the submit function to process the dont show again status and store
|
|
|
|
* it.
|
|
|
|
* @param {object} options - options for dont show again checkbox.
|
|
|
|
* @param {string} options.id the id of the checkbox.
|
|
|
|
* @param {Array} options.buttonValues The button values that will trigger
|
|
|
|
* storing he checkbox value
|
|
|
|
* @param {string} options.localStorageKey the key for the local storage. if
|
|
|
|
* not provided options.id will be used.
|
|
|
|
* @param {Function} submitFunction the submit function to be wrapped
|
|
|
|
* @returns {Function} wrapped function
|
|
|
|
*/
|
|
|
|
function dontShowAgainSubmitFunctionWrapper(options, submitFunction) {
|
2017-10-12 23:02:29 +00:00
|
|
|
if (isDontShowAgainEnabled(options)) {
|
2016-10-27 23:31:00 +00:00
|
|
|
return (...args) => {
|
2016-11-11 15:00:54 +00:00
|
|
|
logger.debug(args, options.buttonValues);
|
2017-10-12 23:02:29 +00:00
|
|
|
|
|
|
|
// args[1] is the value associated with the pressed button
|
|
|
|
if (!options.buttonValues || options.buttonValues.length === 0
|
|
|
|
|| options.buttonValues.indexOf(args[1]) !== -1) {
|
|
|
|
const checkbox = $(`#${options.id}`);
|
|
|
|
|
2016-10-27 23:31:00 +00:00
|
|
|
if (checkbox.length) {
|
|
|
|
jitsiLocalStorage.setItem(
|
|
|
|
options.localStorageKey || options.id,
|
2017-10-12 23:02:29 +00:00
|
|
|
checkbox.prop('checked'));
|
2016-10-27 23:31:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
submitFunction(...args);
|
|
|
|
};
|
|
|
|
}
|
2017-10-12 23:02:29 +00:00
|
|
|
|
|
|
|
return submitFunction;
|
|
|
|
|
2016-10-27 23:31:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether dont show again checkbox is enabled or not.
|
|
|
|
* @param {object} options - options for dont show again checkbox.
|
|
|
|
* @returns {boolean} true if enabled and false if not.
|
|
|
|
*/
|
|
|
|
function isDontShowAgainEnabled(options) {
|
2017-10-12 23:02:29 +00:00
|
|
|
return typeof options === 'object';
|
2016-10-27 23:31:00 +00:00
|
|
|
}
|
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
const messageHandler = {
|
|
|
|
OK: 'dialog.OK',
|
|
|
|
CANCEL: 'dialog.Cancel',
|
2015-08-06 23:34:40 +00:00
|
|
|
|
2014-08-14 15:29:28 +00:00
|
|
|
/**
|
2015-07-28 21:52:32 +00:00
|
|
|
* Shows a message to the user with two buttons: first is given as a
|
|
|
|
* parameter and the second is Cancel.
|
2014-08-14 15:29:28 +00:00
|
|
|
*
|
2016-10-17 22:43:57 +00:00
|
|
|
* @param titleKey the key for the title of the message
|
2016-10-26 21:08:55 +00:00
|
|
|
* @param msgKey the key for the message
|
2014-08-14 15:29:28 +00:00
|
|
|
* @param msgString the text of the message
|
2015-07-28 21:52:32 +00:00
|
|
|
* @param persistent boolean value which determines whether the message is
|
|
|
|
* persistent or not
|
2014-08-14 15:29:28 +00:00
|
|
|
* @param leftButton the fist button's text
|
|
|
|
* @param submitFunction function to be called on submit
|
2015-07-28 21:52:32 +00:00
|
|
|
* @param loadedFunction function to be called after the prompt is fully
|
|
|
|
* loaded
|
2014-10-24 13:33:48 +00:00
|
|
|
* @param closeFunction function to be called after the prompt is closed
|
2015-03-11 09:03:32 +00:00
|
|
|
* @param focus optional focus selector or button index to be focused after
|
|
|
|
* the dialog is opened
|
|
|
|
* @param defaultButton index of default button which will be activated when
|
|
|
|
* the user press 'enter'. Indexed from 0.
|
2016-10-27 23:31:00 +00:00
|
|
|
* @param {object} dontShowAgain - options for dont show again checkbox.
|
|
|
|
* @param {string} dontShowAgain.id the id of the checkbox.
|
|
|
|
* @param {string} dontShowAgain.textKey the key for the text displayed
|
|
|
|
* next to checkbox
|
|
|
|
* @param {boolean} dontShowAgain.checked if true the checkbox is foing to
|
|
|
|
* be checked
|
|
|
|
* @param {Array} dontShowAgain.buttonValues The button values that will
|
|
|
|
* trigger storing the checkbox value
|
|
|
|
* @param {string} dontShowAgain.localStorageKey the key for the local
|
|
|
|
* storage. if not provided dontShowAgain.id will be used.
|
2016-07-06 18:10:45 +00:00
|
|
|
* @return the prompt that was created, or null
|
2014-08-14 15:29:28 +00:00
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
openTwoButtonDialog(options) {
|
|
|
|
const {
|
2016-10-12 00:08:24 +00:00
|
|
|
titleKey,
|
|
|
|
msgKey,
|
|
|
|
msgString,
|
|
|
|
leftButtonKey,
|
|
|
|
submitFunction,
|
|
|
|
loadedFunction,
|
|
|
|
closeFunction,
|
|
|
|
focus,
|
|
|
|
size,
|
|
|
|
defaultButton,
|
|
|
|
wrapperClass,
|
2016-10-27 23:31:00 +00:00
|
|
|
dontShowAgain
|
2016-10-12 00:08:24 +00:00
|
|
|
} = options;
|
2016-06-08 19:34:02 +00:00
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
let { classes } = options;
|
|
|
|
|
|
|
|
if (!popupEnabled || twoButtonDialog) {
|
2016-07-06 18:10:45 +00:00
|
|
|
return null;
|
2017-10-12 23:02:29 +00:00
|
|
|
}
|
2016-06-08 19:34:02 +00:00
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
if (dontShowTheDialog(dontShowAgain)) {
|
2016-10-27 23:31:00 +00:00
|
|
|
// Maybe we should pass some parameters here? I'm not sure
|
|
|
|
// and currently we don't need any parameters.
|
|
|
|
submitFunction();
|
2017-10-12 23:02:29 +00:00
|
|
|
|
2016-10-27 23:31:00 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
const buttons = [];
|
|
|
|
|
|
|
|
const leftButton = leftButtonKey
|
|
|
|
? APP.translation.generateTranslationHTML(leftButtonKey)
|
|
|
|
: APP.translation.generateTranslationHTML('dialog.Submit');
|
2015-03-10 12:47:47 +00:00
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
buttons.push({ title: leftButton,
|
|
|
|
value: true });
|
2015-03-10 12:47:47 +00:00
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
const cancelButton
|
|
|
|
= APP.translation.generateTranslationHTML('dialog.Cancel');
|
|
|
|
|
|
|
|
buttons.push({ title: cancelButton,
|
|
|
|
value: false });
|
|
|
|
|
|
|
|
let message = msgString;
|
2015-03-10 12:47:47 +00:00
|
|
|
|
|
|
|
if (msgKey) {
|
2015-07-03 09:34:05 +00:00
|
|
|
message = APP.translation.generateTranslationHTML(msgKey);
|
2015-02-20 16:17:46 +00:00
|
|
|
}
|
2016-10-27 23:31:00 +00:00
|
|
|
message += generateDontShowCheckbox(dontShowAgain);
|
2016-10-12 00:08:24 +00:00
|
|
|
classes = classes || this._getDialogClasses(size);
|
|
|
|
if (wrapperClass) {
|
|
|
|
classes.prompt += ` ${wrapperClass}`;
|
|
|
|
}
|
|
|
|
|
2016-11-08 15:16:00 +00:00
|
|
|
twoButtonDialog = $.prompt(message, {
|
2016-10-17 23:14:38 +00:00
|
|
|
title: this._getFormattedTitleString(titleKey),
|
2014-08-14 15:29:28 +00:00
|
|
|
persistent: false,
|
2017-10-12 23:02:29 +00:00
|
|
|
buttons,
|
|
|
|
defaultButton,
|
|
|
|
focus,
|
2014-08-14 15:29:28 +00:00
|
|
|
loaded: loadedFunction,
|
2016-10-12 00:08:24 +00:00
|
|
|
promptspeed: 0,
|
|
|
|
classes,
|
2016-10-27 23:31:00 +00:00
|
|
|
submit: dontShowAgainSubmitFunctionWrapper(dontShowAgain,
|
2017-10-12 23:02:29 +00:00
|
|
|
(e, v, m, f) => { // eslint-disable-line max-params
|
2016-10-27 23:31:00 +00:00
|
|
|
twoButtonDialog = null;
|
|
|
|
if (v && submitFunction) {
|
2016-10-12 00:08:24 +00:00
|
|
|
submitFunction(e, v, m, f);
|
2016-10-27 23:31:00 +00:00
|
|
|
}
|
|
|
|
}),
|
2017-10-12 23:02:29 +00:00
|
|
|
close(e, v, m, f) { // eslint-disable-line max-params
|
2016-07-06 16:00:04 +00:00
|
|
|
twoButtonDialog = null;
|
2016-10-12 00:08:24 +00:00
|
|
|
if (closeFunction) {
|
2016-07-06 18:52:59 +00:00
|
|
|
closeFunction(e, v, m, f);
|
2016-10-12 00:08:24 +00:00
|
|
|
}
|
2016-07-06 16:00:04 +00:00
|
|
|
}
|
2014-08-14 15:29:28 +00:00
|
|
|
});
|
2016-10-21 17:11:22 +00:00
|
|
|
APP.translation.translateElement(twoButtonDialog);
|
2017-10-12 23:02:29 +00:00
|
|
|
|
2016-11-08 15:16:00 +00:00
|
|
|
return $.prompt.getApi();
|
2016-06-08 19:34:02 +00:00
|
|
|
},
|
2014-08-14 15:29:28 +00:00
|
|
|
|
2014-09-24 14:35:35 +00:00
|
|
|
/**
|
2015-11-05 17:27:26 +00:00
|
|
|
* Shows a message to the user with two buttons: first is given as a
|
|
|
|
* parameter and the second is Cancel.
|
2014-09-24 14:35:35 +00:00
|
|
|
*
|
2016-10-17 23:14:38 +00:00
|
|
|
* @param titleKey the key for the title of the message
|
2014-09-24 14:35:35 +00:00
|
|
|
* @param msgString the text of the message
|
2015-07-28 21:52:32 +00:00
|
|
|
* @param persistent boolean value which determines whether the message is
|
|
|
|
* persistent or not
|
|
|
|
* @param buttons object with the buttons. The keys must be the name of the
|
|
|
|
* button and value is the value that will be passed to
|
|
|
|
* submitFunction
|
2014-09-24 14:35:35 +00:00
|
|
|
* @param submitFunction function to be called on submit
|
2015-07-28 21:52:32 +00:00
|
|
|
* @param loadedFunction function to be called after the prompt is fully
|
|
|
|
* loaded
|
2016-06-21 14:39:00 +00:00
|
|
|
* @param closeFunction function to be called on dialog close
|
2016-10-27 23:31:00 +00:00
|
|
|
* @param {object} dontShowAgain - options for dont show again checkbox.
|
|
|
|
* @param {string} dontShowAgain.id the id of the checkbox.
|
|
|
|
* @param {string} dontShowAgain.textKey the key for the text displayed
|
|
|
|
* next to checkbox
|
|
|
|
* @param {boolean} dontShowAgain.checked if true the checkbox is foing to
|
|
|
|
* be checked
|
|
|
|
* @param {Array} dontShowAgain.buttonValues The button values that will
|
|
|
|
* trigger storing the checkbox value
|
|
|
|
* @param {string} dontShowAgain.localStorageKey the key for the local
|
|
|
|
* storage. if not provided dontShowAgain.id will be used.
|
2014-09-24 14:35:35 +00:00
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
openDialog(// eslint-disable-line max-params
|
2017-10-02 23:08:07 +00:00
|
|
|
titleKey,
|
|
|
|
msgString,
|
|
|
|
persistent,
|
|
|
|
buttons,
|
|
|
|
submitFunction,
|
|
|
|
loadedFunction,
|
|
|
|
closeFunction,
|
|
|
|
dontShowAgain) {
|
2017-10-12 23:02:29 +00:00
|
|
|
if (!popupEnabled) {
|
2016-06-08 19:34:02 +00:00
|
|
|
return;
|
2017-10-12 23:02:29 +00:00
|
|
|
}
|
2016-06-08 19:34:02 +00:00
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
if (dontShowTheDialog(dontShowAgain)) {
|
2016-10-27 23:31:00 +00:00
|
|
|
// Maybe we should pass some parameters here? I'm not sure
|
|
|
|
// and currently we don't need any parameters.
|
|
|
|
submitFunction();
|
2017-10-12 23:02:29 +00:00
|
|
|
|
2016-10-27 23:31:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
const args = {
|
2016-10-17 23:14:38 +00:00
|
|
|
title: this._getFormattedTitleString(titleKey),
|
2017-10-12 23:02:29 +00:00
|
|
|
persistent,
|
|
|
|
buttons,
|
2014-09-24 14:35:35 +00:00
|
|
|
defaultButton: 1,
|
2016-10-12 00:08:24 +00:00
|
|
|
promptspeed: 0,
|
2017-10-12 23:02:29 +00:00
|
|
|
loaded() {
|
2016-11-28 16:57:27 +00:00
|
|
|
if (loadedFunction) {
|
2017-10-12 23:02:29 +00:00
|
|
|
// eslint-disable-next-line prefer-rest-params
|
2016-11-28 16:57:27 +00:00
|
|
|
loadedFunction.apply(this, arguments);
|
|
|
|
}
|
2017-10-12 23:02:29 +00:00
|
|
|
|
2016-11-28 16:57:27 +00:00
|
|
|
// Hide the close button
|
|
|
|
if (persistent) {
|
2017-10-12 23:02:29 +00:00
|
|
|
$('.jqiclose', this).hide();
|
2016-11-28 16:57:27 +00:00
|
|
|
}
|
|
|
|
},
|
2016-10-27 23:31:00 +00:00
|
|
|
submit: dontShowAgainSubmitFunctionWrapper(
|
|
|
|
dontShowAgain, submitFunction),
|
2016-10-12 00:08:24 +00:00
|
|
|
close: closeFunction,
|
|
|
|
classes: this._getDialogClasses()
|
2015-01-07 11:28:16 +00:00
|
|
|
};
|
2016-06-21 14:39:00 +00:00
|
|
|
|
2015-01-07 11:28:16 +00:00
|
|
|
if (persistent) {
|
|
|
|
args.closeText = '';
|
|
|
|
}
|
2016-07-06 16:00:04 +00:00
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
const dialog = $.prompt(
|
2016-10-27 23:31:00 +00:00
|
|
|
msgString + generateDontShowCheckbox(dontShowAgain), args);
|
2017-10-12 23:02:29 +00:00
|
|
|
|
2016-11-08 15:16:00 +00:00
|
|
|
APP.translation.translateElement(dialog);
|
2017-10-12 23:02:29 +00:00
|
|
|
|
2016-11-08 15:16:00 +00:00
|
|
|
return $.prompt.getApi();
|
2016-06-08 19:34:02 +00:00
|
|
|
},
|
2015-01-07 11:28:16 +00:00
|
|
|
|
2016-10-12 00:08:24 +00:00
|
|
|
/**
|
|
|
|
* Returns the formatted title string.
|
|
|
|
*
|
|
|
|
* @return the title string formatted as a div.
|
|
|
|
*/
|
2016-10-17 23:14:38 +00:00
|
|
|
_getFormattedTitleString(titleKey) {
|
2017-10-12 23:02:29 +00:00
|
|
|
const $titleString = $('<h2>');
|
|
|
|
|
2016-10-12 00:08:24 +00:00
|
|
|
$titleString.addClass('aui-dialog2-header-main');
|
2017-10-12 23:02:29 +00:00
|
|
|
$titleString.attr('data-i18n', titleKey);
|
|
|
|
|
|
|
|
return $('<div>').append($titleString)
|
2017-11-21 17:38:40 +00:00
|
|
|
.html();
|
2016-10-12 00:08:24 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the dialog css classes.
|
|
|
|
*
|
|
|
|
* @return the dialog css classes
|
|
|
|
*/
|
|
|
|
_getDialogClasses(size = 'small') {
|
|
|
|
return {
|
|
|
|
box: '',
|
|
|
|
form: '',
|
|
|
|
prompt: `dialog aui-layer aui-dialog2 aui-dialog2-${size}`,
|
2018-11-29 11:36:22 +00:00
|
|
|
close: 'aui-hide',
|
2016-10-12 00:08:24 +00:00
|
|
|
fade: 'aui-blanket',
|
|
|
|
button: 'button-control',
|
|
|
|
message: 'aui-dialog2-content',
|
|
|
|
buttons: 'aui-dialog2-footer',
|
|
|
|
defaultButton: 'button-control_primary',
|
|
|
|
title: 'aui-dialog2-header'
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2014-08-14 15:29:28 +00:00
|
|
|
/**
|
|
|
|
* Shows a dialog with different states to the user.
|
|
|
|
*
|
2015-07-28 21:52:32 +00:00
|
|
|
* @param statesObject object containing all the states of the dialog.
|
2016-10-21 17:11:22 +00:00
|
|
|
* @param options impromptu options
|
|
|
|
* @param translateOptions options passed to translation
|
2014-08-14 15:29:28 +00:00
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
openDialogWithStates(statesObject, options, translateOptions) {
|
|
|
|
if (!popupEnabled) {
|
2016-06-08 19:34:02 +00:00
|
|
|
return;
|
2017-10-12 23:02:29 +00:00
|
|
|
}
|
|
|
|
const { classes, size } = options;
|
|
|
|
const defaultClasses = this._getDialogClasses(size);
|
|
|
|
|
2016-10-12 00:08:24 +00:00
|
|
|
options.classes = Object.assign({}, defaultClasses, classes);
|
|
|
|
options.promptspeed = options.promptspeed || 0;
|
2016-06-08 19:34:02 +00:00
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
for (const state in statesObject) { // eslint-disable-line guard-for-in
|
|
|
|
const currentState = statesObject[state];
|
|
|
|
|
|
|
|
if (currentState.titleKey) {
|
2016-10-17 23:14:38 +00:00
|
|
|
currentState.title
|
|
|
|
= this._getFormattedTitleString(currentState.titleKey);
|
2016-10-12 00:08:24 +00:00
|
|
|
}
|
|
|
|
}
|
2017-10-12 23:02:29 +00:00
|
|
|
const dialog = $.prompt(statesObject, options);
|
|
|
|
|
2016-11-08 15:16:00 +00:00
|
|
|
APP.translation.translateElement(dialog, translateOptions);
|
2017-10-12 23:02:29 +00:00
|
|
|
|
2016-11-08 15:16:00 +00:00
|
|
|
return $.prompt.getApi();
|
2016-06-08 19:34:02 +00:00
|
|
|
},
|
2014-08-14 15:29:28 +00:00
|
|
|
|
2014-12-16 13:54:13 +00:00
|
|
|
/**
|
|
|
|
* Opens new popup window for given <tt>url</tt> centered over current
|
|
|
|
* window.
|
|
|
|
*
|
|
|
|
* @param url the URL to be displayed in the popup window
|
|
|
|
* @param w the width of the popup window
|
|
|
|
* @param h the height of the popup window
|
|
|
|
* @param onPopupClosed optional callback function called when popup window
|
|
|
|
* has been closed.
|
2014-12-16 18:04:22 +00:00
|
|
|
*
|
2015-07-28 21:52:32 +00:00
|
|
|
* @returns {object} popup window object if opened successfully or undefined
|
2014-12-16 18:04:22 +00:00
|
|
|
* in case we failed to open it(popup blocked)
|
2014-12-16 13:54:13 +00:00
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
// eslint-disable-next-line max-params
|
|
|
|
openCenteredPopup(url, w, h, onPopupClosed) {
|
|
|
|
if (!popupEnabled) {
|
2016-06-08 19:34:02 +00:00
|
|
|
return;
|
2017-10-12 23:02:29 +00:00
|
|
|
}
|
2016-06-08 19:34:02 +00:00
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
const l = window.screenX + (window.innerWidth / 2) - (w / 2);
|
|
|
|
const t = window.screenY + (window.innerHeight / 2) - (h / 2);
|
|
|
|
const popup = window.open(
|
2014-12-16 13:54:13 +00:00
|
|
|
url, '_blank',
|
2017-10-12 23:02:29 +00:00
|
|
|
String(`top=${t}, left=${l}, width=${w}, height=${h}`));
|
|
|
|
|
2014-12-16 18:04:22 +00:00
|
|
|
if (popup && onPopupClosed) {
|
2017-10-12 23:02:29 +00:00
|
|
|
const pollTimer = window.setInterval(() => {
|
2014-12-16 13:54:13 +00:00
|
|
|
if (popup.closed !== false) {
|
|
|
|
window.clearInterval(pollTimer);
|
|
|
|
onPopupClosed();
|
|
|
|
}
|
|
|
|
}, 200);
|
|
|
|
}
|
2016-10-12 00:08:24 +00:00
|
|
|
|
2014-12-16 18:04:22 +00:00
|
|
|
return popup;
|
2016-06-08 19:34:02 +00:00
|
|
|
},
|
2014-12-16 13:54:13 +00:00
|
|
|
|
2014-08-14 15:29:28 +00:00
|
|
|
/**
|
2017-11-03 19:05:03 +00:00
|
|
|
* Shows an error dialog to the user.
|
2014-08-14 15:29:28 +00:00
|
|
|
*
|
2017-11-03 19:05:03 +00:00
|
|
|
* @param {object} props - The properties to pass to the
|
|
|
|
* showErrorNotification action.
|
2014-08-14 15:29:28 +00:00
|
|
|
*/
|
2017-11-03 19:05:03 +00:00
|
|
|
showError(props) {
|
|
|
|
APP.store.dispatch(showErrorNotification(props));
|
2016-06-08 19:34:02 +00:00
|
|
|
},
|
2014-08-14 15:29:28 +00:00
|
|
|
|
|
|
|
/**
|
2017-11-03 19:05:03 +00:00
|
|
|
* Shows a warning dialog to the user.
|
|
|
|
*
|
|
|
|
* @param {object} props - The properties to pass to the
|
|
|
|
* showWarningNotification action.
|
2014-08-14 15:29:28 +00:00
|
|
|
*/
|
2017-11-03 19:05:03 +00:00
|
|
|
showWarning(props) {
|
|
|
|
APP.store.dispatch(showWarningNotification(props));
|
2016-06-08 19:34:02 +00:00
|
|
|
},
|
2014-08-14 15:29:28 +00:00
|
|
|
|
2015-08-06 23:34:40 +00:00
|
|
|
/**
|
2017-07-10 03:01:48 +00:00
|
|
|
* Displays a notification about participant action.
|
2016-06-20 21:13:17 +00:00
|
|
|
* @param displayName the display name of the participant that is
|
|
|
|
* associated with the notification.
|
|
|
|
* @param displayNameKey the key from the language file for the display
|
2017-11-21 17:38:40 +00:00
|
|
|
* name. Only used if displayName is not provided.
|
2015-08-06 23:34:40 +00:00
|
|
|
* @param cls css class for the notification
|
2016-06-20 21:13:17 +00:00
|
|
|
* @param messageKey the key from the language file for the text of the
|
|
|
|
* message.
|
2015-08-06 23:34:40 +00:00
|
|
|
* @param messageArguments object with the arguments for the message.
|
2017-07-28 17:56:49 +00:00
|
|
|
* @param optional configurations for the notification (e.g. timeout)
|
2015-08-06 23:34:40 +00:00
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
participantNotification( // eslint-disable-line max-params
|
2017-10-02 23:08:07 +00:00
|
|
|
displayName,
|
|
|
|
displayNameKey,
|
|
|
|
cls,
|
|
|
|
messageKey,
|
|
|
|
messageArguments,
|
2019-03-29 13:37:50 +00:00
|
|
|
timeout = NOTIFICATION_TIMEOUT) {
|
2017-12-11 18:33:09 +00:00
|
|
|
APP.store.dispatch(showNotification({
|
|
|
|
descriptionArguments: messageArguments,
|
|
|
|
descriptionKey: messageKey,
|
|
|
|
titleKey: displayNameKey,
|
|
|
|
title: displayName
|
|
|
|
},
|
|
|
|
timeout));
|
2016-06-08 19:34:02 +00:00
|
|
|
},
|
2014-10-30 16:07:11 +00:00
|
|
|
|
2017-07-10 03:01:48 +00:00
|
|
|
/**
|
|
|
|
* Displays a notification.
|
|
|
|
*
|
|
|
|
* @param {string} titleKey - The key from the language file for the title
|
|
|
|
* of the notification.
|
|
|
|
* @param {string} messageKey - The key from the language file for the text
|
|
|
|
* of the message.
|
|
|
|
* @param {Object} messageArguments - The arguments for the message
|
|
|
|
* translation.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
notify(titleKey, messageKey, messageArguments) {
|
2017-07-28 17:56:49 +00:00
|
|
|
this.participantNotification(
|
|
|
|
null, titleKey, null, messageKey, messageArguments);
|
2016-06-08 19:34:02 +00:00
|
|
|
},
|
2015-08-06 23:34:40 +00:00
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
enablePopups(enable) {
|
2016-06-08 19:34:02 +00:00
|
|
|
popupEnabled = enable;
|
2016-10-17 13:35:47 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if dialog is opened
|
|
|
|
* false otherwise
|
|
|
|
* @returns {boolean} isOpened
|
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
isDialogOpened() {
|
|
|
|
return Boolean($.prompt.getCurrentStateName());
|
2016-06-08 19:34:02 +00:00
|
|
|
}
|
|
|
|
};
|
2014-08-14 15:29:28 +00:00
|
|
|
|
2017-06-14 18:13:41 +00:00
|
|
|
export default messageHandler;
|