Unifrms messageHandler access and adds enable disable

This commit is contained in:
yanas 2016-06-08 14:34:02 -05:00
parent 346ff889ea
commit 57815cb2fe
8 changed files with 87 additions and 72 deletions

View File

@ -1,11 +1,6 @@
/* global $, APP, config, interfaceConfig */ /* global $, APP, config, interfaceConfig */
import UIEvents from "../../service/UI/UIEvents"; import UIEvents from "../../service/UI/UIEvents";
/*
* Created by Yana Stamcheva on 2/10/15.
*/
var messageHandler = require("./util/MessageHandler");
/** /**
* Constructs the html for the overall feedback window. * Constructs the html for the overall feedback window.
* *

View File

@ -430,7 +430,7 @@ UI.start = function () {
$("#downloadlog").css("display", "none"); $("#downloadlog").css("display", "none");
BottomToolbar.hide(); BottomToolbar.hide();
FilmStrip.setupFilmStripOnly(); FilmStrip.setupFilmStripOnly();
messageHandler.disableNotifications(); messageHandler.enableNotifications(false);
$('body').popover("disable"); $('body').popover("disable");
JitsiPopover.enabled = false; JitsiPopover.enabled = false;
} }

View File

@ -1,7 +1,5 @@
/* global $, APP, config*/ /* global $, APP, config*/
var messageHandler = require('../util/MessageHandler');
/** /**
* Build html for "password required" dialog. * Build html for "password required" dialog.
* @returns {string} html string * @returns {string} html string
@ -123,7 +121,7 @@ function LoginDialog(successCallback, cancelCallback) {
} }
}; };
var connDialog = messageHandler.openDialogWithStates( var connDialog = APP.UI.messageHandler.openDialogWithStates(
states, { persistent: true, closeText: '' }, null states, { persistent: true, closeText: '' }, null
); );
@ -182,14 +180,14 @@ export default {
* @returns auth dialog * @returns auth dialog
*/ */
showExternalAuthDialog: function (url, callback) { showExternalAuthDialog: function (url, callback) {
var dialog = messageHandler.openCenteredPopup( var dialog = APP.UI.messageHandler.openCenteredPopup(
url, 910, 660, url, 910, 660,
// On closed // On closed
callback callback
); );
if (!dialog) { if (!dialog) {
messageHandler.openMessageDialog(null, "dialog.popupError"); APP.UI.messageHandler.openMessageDialog(null, "dialog.popupError");
} }
return dialog; return dialog;

View File

@ -1,5 +1,4 @@
/* global APP, JitsiMeetJS */ /* global APP, JitsiMeetJS */
import messageHandler from '../util/MessageHandler';
import UIUtil from '../util/UIUtil'; import UIUtil from '../util/UIUtil';
//FIXME: //FIXME:
import AnalyticsAdapter from '../../statistics/AnalyticsAdapter'; import AnalyticsAdapter from '../../statistics/AnalyticsAdapter';
@ -19,7 +18,7 @@ function askForNewPassword () {
`; `;
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
messageHandler.openTwoButtonDialog( APP.UI.messageHandler.openTwoButtonDialog(
null, null, null, null, null, null,
msg, false, "dialog.Save", msg, false, "dialog.Save",
function (e, v, m, f) { function (e, v, m, f) {
@ -27,7 +26,7 @@ function askForNewPassword () {
resolve(UIUtil.escapeHtml(f.lockKey)); resolve(UIUtil.escapeHtml(f.lockKey));
} }
else { else {
reject(messageHandler.CANCEL); reject(APP.UI.messageHandler.CANCEL);
} }
}, },
null, null, 'input:first' null, null, 'input:first'
@ -51,7 +50,7 @@ function askForPassword () {
placeholder="${passMsg}" autofocus> placeholder="${passMsg}" autofocus>
`; `;
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
messageHandler.openTwoButtonDialog( APP.UI.messageHandler.openTwoButtonDialog(
null, null, null, msg, null, null, null, msg,
true, "dialog.Ok", true, "dialog.Ok",
function (e, v, m, f) {}, null, function (e, v, m, f) {}, null,
@ -59,7 +58,7 @@ function askForPassword () {
if (v && f.lockKey) { if (v && f.lockKey) {
resolve(UIUtil.escapeHtml(f.lockKey)); resolve(UIUtil.escapeHtml(f.lockKey));
} else { } else {
reject(messageHandler.CANCEL); reject(APP.UI.messageHandler.CANCEL);
} }
}, },
':input:first' ':input:first'
@ -73,14 +72,14 @@ function askForPassword () {
*/ */
function askToUnlock () { function askToUnlock () {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
messageHandler.openTwoButtonDialog( APP.UI.messageHandler.openTwoButtonDialog(
null, null, "dialog.passwordCheck", null, null, "dialog.passwordCheck",
null, false, "dialog.Remove", null, false, "dialog.Remove",
function (e, v) { function (e, v) {
if (v) { if (v) {
resolve(); resolve();
} else { } else {
reject(messageHandler.CANCEL); reject(APP.UI.messageHandler.CANCEL);
} }
} }
); );
@ -93,7 +92,8 @@ function askToUnlock () {
*/ */
function notifyPasswordNotSupported () { function notifyPasswordNotSupported () {
console.warn('room passwords not supported'); console.warn('room passwords not supported');
messageHandler.showError("dialog.warning", "dialog.passwordNotSupported"); APP.UI.messageHandler.showError(
"dialog.warning", "dialog.passwordNotSupported");
} }
/** /**
@ -102,7 +102,8 @@ function notifyPasswordNotSupported () {
*/ */
function notifyPasswordFailed(err) { function notifyPasswordFailed(err) {
console.warn('setting password failed', err); console.warn('setting password failed', err);
messageHandler.showError("dialog.lockTitle", "dialog.lockMessage"); APP.UI.messageHandler.showError(
"dialog.lockTitle", "dialog.lockMessage");
} }
const ConferenceErrors = JitsiMeetJS.errors.conference; const ConferenceErrors = JitsiMeetJS.errors.conference;
@ -153,7 +154,7 @@ export default function createRoomLocker (room) {
AnalyticsAdapter.sendEvent('toolbar.lock.disabled'); AnalyticsAdapter.sendEvent('toolbar.lock.disabled');
}).catch( }).catch(
reason => { reason => {
if (reason !== messageHandler.CANCEL) if (reason !== APP.UI.messageHandler.CANCEL)
console.error(reason); console.error(reason);
} }
); );
@ -171,7 +172,7 @@ export default function createRoomLocker (room) {
AnalyticsAdapter.sendEvent('toolbar.lock.enabled'); AnalyticsAdapter.sendEvent('toolbar.lock.enabled');
}).catch( }).catch(
reason => { reason => {
if (reason !== messageHandler.CANCEL) if (reason !== APP.UI.messageHandler.CANCEL)
console.error(reason); console.error(reason);
} }
); );
@ -185,7 +186,7 @@ export default function createRoomLocker (room) {
newPass => { password = newPass; } newPass => { password = newPass; }
).catch( ).catch(
reason => { reason => {
if (reason !== messageHandler.CANCEL) if (reason !== APP.UI.messageHandler.CANCEL)
console.error(reason); console.error(reason);
} }
); );
@ -196,9 +197,11 @@ export default function createRoomLocker (room) {
*/ */
notifyModeratorRequired () { notifyModeratorRequired () {
if (password) { if (password) {
messageHandler.openMessageDialog(null, "dialog.passwordError"); APP.UI.messageHandler
.openMessageDialog(null, "dialog.passwordError");
} else { } else {
messageHandler.openMessageDialog(null, "dialog.passwordError2"); APP.UI.messageHandler
.openMessageDialog(null, "dialog.passwordError2");
} }
} }
}; };

View File

@ -236,6 +236,8 @@ var Recording = {
Feedback.enableFeedback(false); Feedback.enableFeedback(false);
Toolbar.enable(false); Toolbar.enable(false);
BottomToolbar.enable(false); BottomToolbar.enable(false);
APP.UI.messageHandler.enableNotifications(false);
APP.UI.messageHandler.enablePopups(false);
} }
}, },

View File

@ -1,6 +1,5 @@
/* global $, APP, YT, onPlayerReady, onPlayerStateChange, onPlayerError */ /* global $, APP, YT, onPlayerReady, onPlayerStateChange, onPlayerError */
import messageHandler from '../util/MessageHandler';
import UIUtil from '../util/UIUtil'; import UIUtil from '../util/UIUtil';
import UIEvents from '../../../service/UI/UIEvents'; import UIEvents from '../../../service/UI/UIEvents';
@ -71,7 +70,7 @@ export default class SharedVideoManager {
this.emitter.emit( this.emitter.emit(
UIEvents.UPDATE_SHARED_VIDEO, this.url, 'stop')); UIEvents.UPDATE_SHARED_VIDEO, this.url, 'stop'));
} else { } else {
messageHandler.openMessageDialog( APP.UI.messageHandler.openMessageDialog(
"dialog.shareVideoTitle", "dialog.shareVideoTitle",
"dialog.alreadySharedVideoMsg" "dialog.alreadySharedVideoMsg"
); );
@ -701,7 +700,7 @@ function getYoutubeLink(url) {
*/ */
function showStopVideoPropmpt() { function showStopVideoPropmpt() {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
messageHandler.openTwoButtonDialog( APP.UI.messageHandler.openTwoButtonDialog(
"dialog.removeSharedVideoTitle", "dialog.removeSharedVideoTitle",
null, null,
"dialog.removeSharedVideoMsg", "dialog.removeSharedVideoMsg",
@ -736,7 +735,7 @@ function requestVideoLink() {
const defaultUrl = i18n.translateString("defaultLink", i18nOptions); const defaultUrl = i18n.translateString("defaultLink", i18nOptions);
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
let dialog = messageHandler.openDialogWithStates({ let dialog = APP.UI.messageHandler.openDialogWithStates({
state0: { state0: {
html: ` html: `
<h2>${title}</h2> <h2>${title}</h2>

View File

@ -1,6 +1,5 @@
/* global APP, $, config, interfaceConfig */ /* global APP, $, config, interfaceConfig */
/* jshint -W101 */ /* jshint -W101 */
import messageHandler from '../util/MessageHandler';
import UIUtil from '../util/UIUtil'; import UIUtil from '../util/UIUtil';
import AnalyticsAdapter from '../../statistics/AnalyticsAdapter'; import AnalyticsAdapter from '../../statistics/AnalyticsAdapter';
import UIEvents from '../../../service/UI/UIEvents'; import UIEvents from '../../../service/UI/UIEvents';
@ -21,7 +20,7 @@ function openLinkDialog () {
} else { } else {
inviteAttributes = "value=\"" + encodeURI(roomUrl) + "\""; inviteAttributes = "value=\"" + encodeURI(roomUrl) + "\"";
} }
messageHandler.openTwoButtonDialog( APP.UI.messageHandler.openTwoButtonDialog(
"dialog.shareLink", null, null, "dialog.shareLink", null, null,
`<input id="inviteLinkRef" type="text" ${inviteAttributes} onclick="this.select();" readonly>`, `<input id="inviteLinkRef" type="text" ${inviteAttributes} onclick="this.select();" readonly>`,
false, "dialog.Invite", false, "dialog.Invite",
@ -129,7 +128,7 @@ const buttonHandlers = {
"toolbar_button_logout": function () { "toolbar_button_logout": function () {
AnalyticsAdapter.sendEvent('toolbar.authenticate.logout.clicked'); AnalyticsAdapter.sendEvent('toolbar.authenticate.logout.clicked');
// Ask for confirmation // Ask for confirmation
messageHandler.openTwoButtonDialog( APP.UI.messageHandler.openTwoButtonDialog(
"dialog.logoutTitle", "dialog.logoutTitle",
null, null,
"dialog.logoutQuestion", "dialog.logoutQuestion",
@ -167,7 +166,7 @@ function showSipNumberInput () {
: ''; : '';
let sipMsg = APP.translation.generateTranslationHTML("dialog.sipMsg"); let sipMsg = APP.translation.generateTranslationHTML("dialog.sipMsg");
messageHandler.openTwoButtonDialog( APP.UI.messageHandler.openTwoButtonDialog(
null, null, null, null, null, null,
`<h2>${sipMsg}</h2> `<h2>${sipMsg}</h2>
<input name="sipNumber" type="text" value="${defaultNumber}" autofocus>`, <input name="sipNumber" type="text" value="${defaultNumber}" autofocus>`,

View File

@ -7,11 +7,18 @@ import UIUtil from './UIUtil';
* Flag for enable/disable of the notifications. * Flag for enable/disable of the notifications.
* @type {boolean} * @type {boolean}
*/ */
var notificationsEnabled = true; let notificationsEnabled = true;
/**
* Flag for enabling/disabling popups.
* @type {boolean}
*/
let popupEnabled = true;
var messageHandler = {
OK: "dialog.OK",
CANCEL: "dialog.Cancel",
var messageHandler = (function(my) {
my.OK = "dialog.OK",
my.CANCEL = "dialog.Cancel",
/** /**
* Shows a message to the user. * Shows a message to the user.
* *
@ -24,7 +31,10 @@ var messageHandler = (function(my) {
* @param message the message to show. If a falsy value is provided, * @param message the message to show. If a falsy value is provided,
* messageKey will be used to get a message via the translation API. * messageKey will be used to get a message via the translation API.
*/ */
my.openMessageDialog = function(titleKey, messageKey, title, message) { openMessageDialog: function(titleKey, messageKey, title, message) {
if (!popupEnabled)
return;
if (!title) { if (!title) {
title = APP.translation.generateTranslationHTML(titleKey); title = APP.translation.generateTranslationHTML(titleKey);
} }
@ -35,8 +45,7 @@ var messageHandler = (function(my) {
$.prompt(message, $.prompt(message,
{title: title, persistent: false} {title: title, persistent: false}
); );
}; },
/** /**
* Shows a message to the user with two buttons: first is given as a * Shows a message to the user with two buttons: first is given as a
* parameter and the second is Cancel. * parameter and the second is Cancel.
@ -55,9 +64,13 @@ var messageHandler = (function(my) {
* @param defaultButton index of default button which will be activated when * @param defaultButton index of default button which will be activated when
* the user press 'enter'. Indexed from 0. * the user press 'enter'. Indexed from 0.
*/ */
my.openTwoButtonDialog = function(titleKey, titleString, msgKey, msgString, openTwoButtonDialog: function(titleKey, titleString, msgKey, msgString,
persistent, leftButtonKey, submitFunction, loadedFunction, persistent, leftButtonKey, submitFunction, loadedFunction,
closeFunction, focus, defaultButton) { closeFunction, focus, defaultButton) {
if (!popupEnabled)
return;
var buttons = []; var buttons = [];
var leftButton = APP.translation.generateTranslationHTML(leftButtonKey); var leftButton = APP.translation.generateTranslationHTML(leftButtonKey);
@ -84,7 +97,7 @@ var messageHandler = (function(my) {
submit: submitFunction, submit: submitFunction,
close: closeFunction close: closeFunction
}); });
}; },
/** /**
* Shows a message to the user with two buttons: first is given as a * Shows a message to the user with two buttons: first is given as a
@ -101,8 +114,11 @@ var messageHandler = (function(my) {
* @param loadedFunction function to be called after the prompt is fully * @param loadedFunction function to be called after the prompt is fully
* loaded * loaded
*/ */
my.openDialog = function (titleString, msgString, persistent, buttons, openDialog: function (titleString, msgString, persistent, buttons,
submitFunction, loadedFunction) { submitFunction, loadedFunction) {
if (!popupEnabled)
return;
var args = { var args = {
title: titleString, title: titleString,
persistent: persistent, persistent: persistent,
@ -115,23 +131,26 @@ var messageHandler = (function(my) {
args.closeText = ''; args.closeText = '';
} }
return new Impromptu(msgString, args); return new Impromptu(msgString, args);
}; },
/** /**
* Closes currently opened dialog. * Closes currently opened dialog.
*/ */
my.closeDialog = function () { closeDialog: function () {
$.prompt.close(); $.prompt.close();
}; },
/** /**
* Shows a dialog with different states to the user. * Shows a dialog with different states to the user.
* *
* @param statesObject object containing all the states of the dialog. * @param statesObject object containing all the states of the dialog.
*/ */
my.openDialogWithStates = function (statesObject, options) { openDialogWithStates: function (statesObject, options) {
if (!popupEnabled)
return;
return new Impromptu(statesObject, options); return new Impromptu(statesObject, options);
}; },
/** /**
* Opens new popup window for given <tt>url</tt> centered over current * Opens new popup window for given <tt>url</tt> centered over current
@ -146,7 +165,10 @@ var messageHandler = (function(my) {
* @returns {object} popup window object if opened successfully or undefined * @returns {object} popup window object if opened successfully or undefined
* in case we failed to open it(popup blocked) * in case we failed to open it(popup blocked)
*/ */
my.openCenteredPopup = function (url, w, h, onPopupClosed) { openCenteredPopup: function (url, w, h, onPopupClosed) {
if (!popupEnabled)
return;
var l = window.screenX + (window.innerWidth / 2) - (w / 2); var l = window.screenX + (window.innerWidth / 2) - (w / 2);
var t = window.screenY + (window.innerHeight / 2) - (h / 2); var t = window.screenY + (window.innerHeight / 2) - (h / 2);
var popup = window.open( var popup = window.open(
@ -161,7 +183,7 @@ var messageHandler = (function(my) {
}, 200); }, 200);
} }
return popup; return popup;
}; },
/** /**
* Shows a dialog prompting the user to send an error report. * Shows a dialog prompting the user to send an error report.
@ -170,18 +192,18 @@ var messageHandler = (function(my) {
* @param msgKey the text of the message * @param msgKey the text of the message
* @param error the error that is being reported * @param error the error that is being reported
*/ */
my.openReportDialog = function(titleKey, msgKey, error) { openReportDialog: function(titleKey, msgKey, error) {
my.openMessageDialog(titleKey, msgKey); this.openMessageDialog(titleKey, msgKey);
console.log(error); console.log(error);
//FIXME send the error to the server //FIXME send the error to the server
}; },
/** /**
* Shows an error dialog to the user. * Shows an error dialog to the user.
* @param titleKey the title of the message. * @param titleKey the title of the message.
* @param msgKey the text of the message. * @param msgKey the text of the message.
*/ */
my.showError = function(titleKey, msgKey) { showError: function(titleKey, msgKey) {
if (!titleKey) { if (!titleKey) {
titleKey = "dialog.oops"; titleKey = "dialog.oops";
@ -190,7 +212,7 @@ var messageHandler = (function(my) {
msgKey = "dialog.defaultError"; msgKey = "dialog.defaultError";
} }
messageHandler.openMessageDialog(titleKey, msgKey); messageHandler.openMessageDialog(titleKey, msgKey);
}; },
/** /**
* Displayes notification. * Displayes notification.
@ -201,10 +223,12 @@ var messageHandler = (function(my) {
* @param messageArguments object with the arguments for the message. * @param messageArguments object with the arguments for the message.
* @param options object with language options. * @param options object with language options.
*/ */
my.notify = function(displayName, displayNameKey, notify: function(displayName, displayNameKey,
cls, messageKey, messageArguments, options) { cls, messageKey, messageArguments, options) {
if(!notificationsEnabled) if(!notificationsEnabled)
return; return;
var displayNameSpan = '<span class="nickname" '; var displayNameSpan = '<span class="nickname" ';
if (displayName) { if (displayName) {
displayNameSpan += ">" + UIUtil.escapeHtml(displayName); displayNameSpan += ">" + UIUtil.escapeHtml(displayName);
@ -222,31 +246,26 @@ var messageHandler = (function(my) {
APP.translation.translateString(messageKey, APP.translation.translateString(messageKey,
messageArguments) + messageArguments) +
'</span>', null, options); '</span>', null, options);
}; },
/** /**
* Removes the toaster. * Removes the toaster.
* @param toasterElement * @param toasterElement
*/ */
my.remove = function(toasterElement) { remove: function(toasterElement) {
toasterElement.remove(); toasterElement.remove();
}; },
/** /**
* Disables notifications. * Enables / disables notifications.
*/ */
my.disableNotifications = function () { enableNotifications: function (enable) {
notificationsEnabled = false; notificationsEnabled = enable;
}; },
/** enablePopups: function (enable) {
* Enables notifications. popupEnabled = enable;
*/ }
my.enableNotifications = function () {
notificationsEnabled = true;
}; };
return my;
}(messageHandler || {}));
module.exports = messageHandler; module.exports = messageHandler;