From 57815cb2fecf175ed48601d18ab6a00310ee0606 Mon Sep 17 00:00:00 2001 From: yanas Date: Wed, 8 Jun 2016 14:34:02 -0500 Subject: [PATCH] Unifrms messageHandler access and adds enable disable --- modules/UI/Feedback.js | 5 -- modules/UI/UI.js | 2 +- modules/UI/authentication/LoginDialog.js | 8 +- modules/UI/authentication/RoomLocker.js | 31 ++++---- modules/UI/recording/Recording.js | 2 + modules/UI/shared_video/SharedVideo.js | 7 +- modules/UI/toolbars/Toolbar.js | 7 +- modules/UI/util/MessageHandler.js | 97 ++++++++++++++---------- 8 files changed, 87 insertions(+), 72 deletions(-) diff --git a/modules/UI/Feedback.js b/modules/UI/Feedback.js index 5fca4464e..3b8eb3bab 100644 --- a/modules/UI/Feedback.js +++ b/modules/UI/Feedback.js @@ -1,11 +1,6 @@ /* global $, APP, config, interfaceConfig */ 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. * diff --git a/modules/UI/UI.js b/modules/UI/UI.js index 8b50f3041..7f3d6a788 100644 --- a/modules/UI/UI.js +++ b/modules/UI/UI.js @@ -430,7 +430,7 @@ UI.start = function () { $("#downloadlog").css("display", "none"); BottomToolbar.hide(); FilmStrip.setupFilmStripOnly(); - messageHandler.disableNotifications(); + messageHandler.enableNotifications(false); $('body').popover("disable"); JitsiPopover.enabled = false; } diff --git a/modules/UI/authentication/LoginDialog.js b/modules/UI/authentication/LoginDialog.js index 30488cb0a..124269524 100644 --- a/modules/UI/authentication/LoginDialog.js +++ b/modules/UI/authentication/LoginDialog.js @@ -1,7 +1,5 @@ /* global $, APP, config*/ -var messageHandler = require('../util/MessageHandler'); - /** * Build html for "password required" dialog. * @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 ); @@ -182,14 +180,14 @@ export default { * @returns auth dialog */ showExternalAuthDialog: function (url, callback) { - var dialog = messageHandler.openCenteredPopup( + var dialog = APP.UI.messageHandler.openCenteredPopup( url, 910, 660, // On closed callback ); if (!dialog) { - messageHandler.openMessageDialog(null, "dialog.popupError"); + APP.UI.messageHandler.openMessageDialog(null, "dialog.popupError"); } return dialog; diff --git a/modules/UI/authentication/RoomLocker.js b/modules/UI/authentication/RoomLocker.js index 703cba4e5..09e29a31b 100644 --- a/modules/UI/authentication/RoomLocker.js +++ b/modules/UI/authentication/RoomLocker.js @@ -1,5 +1,4 @@ /* global APP, JitsiMeetJS */ -import messageHandler from '../util/MessageHandler'; import UIUtil from '../util/UIUtil'; //FIXME: import AnalyticsAdapter from '../../statistics/AnalyticsAdapter'; @@ -19,7 +18,7 @@ function askForNewPassword () { `; return new Promise(function (resolve, reject) { - messageHandler.openTwoButtonDialog( + APP.UI.messageHandler.openTwoButtonDialog( null, null, null, msg, false, "dialog.Save", function (e, v, m, f) { @@ -27,7 +26,7 @@ function askForNewPassword () { resolve(UIUtil.escapeHtml(f.lockKey)); } else { - reject(messageHandler.CANCEL); + reject(APP.UI.messageHandler.CANCEL); } }, null, null, 'input:first' @@ -51,7 +50,7 @@ function askForPassword () { placeholder="${passMsg}" autofocus> `; return new Promise(function (resolve, reject) { - messageHandler.openTwoButtonDialog( + APP.UI.messageHandler.openTwoButtonDialog( null, null, null, msg, true, "dialog.Ok", function (e, v, m, f) {}, null, @@ -59,7 +58,7 @@ function askForPassword () { if (v && f.lockKey) { resolve(UIUtil.escapeHtml(f.lockKey)); } else { - reject(messageHandler.CANCEL); + reject(APP.UI.messageHandler.CANCEL); } }, ':input:first' @@ -73,14 +72,14 @@ function askForPassword () { */ function askToUnlock () { return new Promise(function (resolve, reject) { - messageHandler.openTwoButtonDialog( + APP.UI.messageHandler.openTwoButtonDialog( null, null, "dialog.passwordCheck", null, false, "dialog.Remove", function (e, v) { if (v) { resolve(); } else { - reject(messageHandler.CANCEL); + reject(APP.UI.messageHandler.CANCEL); } } ); @@ -93,7 +92,8 @@ function askToUnlock () { */ function notifyPasswordNotSupported () { 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) { 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; @@ -153,7 +154,7 @@ export default function createRoomLocker (room) { AnalyticsAdapter.sendEvent('toolbar.lock.disabled'); }).catch( reason => { - if (reason !== messageHandler.CANCEL) + if (reason !== APP.UI.messageHandler.CANCEL) console.error(reason); } ); @@ -171,7 +172,7 @@ export default function createRoomLocker (room) { AnalyticsAdapter.sendEvent('toolbar.lock.enabled'); }).catch( reason => { - if (reason !== messageHandler.CANCEL) + if (reason !== APP.UI.messageHandler.CANCEL) console.error(reason); } ); @@ -185,7 +186,7 @@ export default function createRoomLocker (room) { newPass => { password = newPass; } ).catch( reason => { - if (reason !== messageHandler.CANCEL) + if (reason !== APP.UI.messageHandler.CANCEL) console.error(reason); } ); @@ -196,9 +197,11 @@ export default function createRoomLocker (room) { */ notifyModeratorRequired () { if (password) { - messageHandler.openMessageDialog(null, "dialog.passwordError"); + APP.UI.messageHandler + .openMessageDialog(null, "dialog.passwordError"); } else { - messageHandler.openMessageDialog(null, "dialog.passwordError2"); + APP.UI.messageHandler + .openMessageDialog(null, "dialog.passwordError2"); } } }; diff --git a/modules/UI/recording/Recording.js b/modules/UI/recording/Recording.js index 8929d1be7..261687ff4 100644 --- a/modules/UI/recording/Recording.js +++ b/modules/UI/recording/Recording.js @@ -236,6 +236,8 @@ var Recording = { Feedback.enableFeedback(false); Toolbar.enable(false); BottomToolbar.enable(false); + APP.UI.messageHandler.enableNotifications(false); + APP.UI.messageHandler.enablePopups(false); } }, diff --git a/modules/UI/shared_video/SharedVideo.js b/modules/UI/shared_video/SharedVideo.js index ad4984ecc..827334718 100644 --- a/modules/UI/shared_video/SharedVideo.js +++ b/modules/UI/shared_video/SharedVideo.js @@ -1,6 +1,5 @@ /* global $, APP, YT, onPlayerReady, onPlayerStateChange, onPlayerError */ -import messageHandler from '../util/MessageHandler'; import UIUtil from '../util/UIUtil'; import UIEvents from '../../../service/UI/UIEvents'; @@ -71,7 +70,7 @@ export default class SharedVideoManager { this.emitter.emit( UIEvents.UPDATE_SHARED_VIDEO, this.url, 'stop')); } else { - messageHandler.openMessageDialog( + APP.UI.messageHandler.openMessageDialog( "dialog.shareVideoTitle", "dialog.alreadySharedVideoMsg" ); @@ -701,7 +700,7 @@ function getYoutubeLink(url) { */ function showStopVideoPropmpt() { return new Promise(function (resolve, reject) { - messageHandler.openTwoButtonDialog( + APP.UI.messageHandler.openTwoButtonDialog( "dialog.removeSharedVideoTitle", null, "dialog.removeSharedVideoMsg", @@ -736,7 +735,7 @@ function requestVideoLink() { const defaultUrl = i18n.translateString("defaultLink", i18nOptions); return new Promise(function (resolve, reject) { - let dialog = messageHandler.openDialogWithStates({ + let dialog = APP.UI.messageHandler.openDialogWithStates({ state0: { html: `

${title}

diff --git a/modules/UI/toolbars/Toolbar.js b/modules/UI/toolbars/Toolbar.js index 221de3ae1..c1e79de92 100644 --- a/modules/UI/toolbars/Toolbar.js +++ b/modules/UI/toolbars/Toolbar.js @@ -1,6 +1,5 @@ /* global APP, $, config, interfaceConfig */ /* jshint -W101 */ -import messageHandler from '../util/MessageHandler'; import UIUtil from '../util/UIUtil'; import AnalyticsAdapter from '../../statistics/AnalyticsAdapter'; import UIEvents from '../../../service/UI/UIEvents'; @@ -21,7 +20,7 @@ function openLinkDialog () { } else { inviteAttributes = "value=\"" + encodeURI(roomUrl) + "\""; } - messageHandler.openTwoButtonDialog( + APP.UI.messageHandler.openTwoButtonDialog( "dialog.shareLink", null, null, ``, false, "dialog.Invite", @@ -129,7 +128,7 @@ const buttonHandlers = { "toolbar_button_logout": function () { AnalyticsAdapter.sendEvent('toolbar.authenticate.logout.clicked'); // Ask for confirmation - messageHandler.openTwoButtonDialog( + APP.UI.messageHandler.openTwoButtonDialog( "dialog.logoutTitle", null, "dialog.logoutQuestion", @@ -167,7 +166,7 @@ function showSipNumberInput () { : ''; let sipMsg = APP.translation.generateTranslationHTML("dialog.sipMsg"); - messageHandler.openTwoButtonDialog( + APP.UI.messageHandler.openTwoButtonDialog( null, null, null, `

${sipMsg}

`, diff --git a/modules/UI/util/MessageHandler.js b/modules/UI/util/MessageHandler.js index 3cbebc5a6..fdf274481 100644 --- a/modules/UI/util/MessageHandler.js +++ b/modules/UI/util/MessageHandler.js @@ -7,11 +7,18 @@ import UIUtil from './UIUtil'; * Flag for enable/disable of the notifications. * @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. * @@ -24,7 +31,10 @@ var messageHandler = (function(my) { * @param message the message to show. If a falsy value is provided, * 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) { title = APP.translation.generateTranslationHTML(titleKey); } @@ -35,8 +45,7 @@ var messageHandler = (function(my) { $.prompt(message, {title: title, persistent: false} ); - }; - + }, /** * Shows a message to the user with two buttons: first is given as a * 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 * the user press 'enter'. Indexed from 0. */ - my.openTwoButtonDialog = function(titleKey, titleString, msgKey, msgString, + openTwoButtonDialog: function(titleKey, titleString, msgKey, msgString, persistent, leftButtonKey, submitFunction, loadedFunction, closeFunction, focus, defaultButton) { + + if (!popupEnabled) + return; + var buttons = []; var leftButton = APP.translation.generateTranslationHTML(leftButtonKey); @@ -84,7 +97,7 @@ var messageHandler = (function(my) { submit: submitFunction, close: closeFunction }); - }; + }, /** * 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 * loaded */ - my.openDialog = function (titleString, msgString, persistent, buttons, + openDialog: function (titleString, msgString, persistent, buttons, submitFunction, loadedFunction) { + if (!popupEnabled) + return; + var args = { title: titleString, persistent: persistent, @@ -115,23 +131,26 @@ var messageHandler = (function(my) { args.closeText = ''; } return new Impromptu(msgString, args); - }; + }, /** * Closes currently opened dialog. */ - my.closeDialog = function () { + closeDialog: function () { $.prompt.close(); - }; + }, /** * Shows a dialog with different states to the user. * * @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); - }; + }, /** * Opens new popup window for given url centered over current @@ -146,7 +165,10 @@ var messageHandler = (function(my) { * @returns {object} popup window object if opened successfully or undefined * 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 t = window.screenY + (window.innerHeight / 2) - (h / 2); var popup = window.open( @@ -161,7 +183,7 @@ var messageHandler = (function(my) { }, 200); } return popup; - }; + }, /** * 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 error the error that is being reported */ - my.openReportDialog = function(titleKey, msgKey, error) { - my.openMessageDialog(titleKey, msgKey); + openReportDialog: function(titleKey, msgKey, error) { + this.openMessageDialog(titleKey, msgKey); console.log(error); //FIXME send the error to the server - }; + }, /** * Shows an error dialog to the user. * @param titleKey the title of the message. * @param msgKey the text of the message. */ - my.showError = function(titleKey, msgKey) { + showError: function(titleKey, msgKey) { if (!titleKey) { titleKey = "dialog.oops"; @@ -190,7 +212,7 @@ var messageHandler = (function(my) { msgKey = "dialog.defaultError"; } messageHandler.openMessageDialog(titleKey, msgKey); - }; + }, /** * Displayes notification. @@ -201,10 +223,12 @@ var messageHandler = (function(my) { * @param messageArguments object with the arguments for the message. * @param options object with language options. */ - my.notify = function(displayName, displayNameKey, + notify: function(displayName, displayNameKey, cls, messageKey, messageArguments, options) { + if(!notificationsEnabled) return; + var displayNameSpan = '', null, options); - }; + }, /** * Removes the toaster. * @param toasterElement */ - my.remove = function(toasterElement) { + remove: function(toasterElement) { toasterElement.remove(); - }; + }, /** - * Disables notifications. + * Enables / disables notifications. */ - my.disableNotifications = function () { - notificationsEnabled = false; - }; + enableNotifications: function (enable) { + notificationsEnabled = enable; + }, - /** - * Enables notifications. - */ - my.enableNotifications = function () { - notificationsEnabled = true; - }; - - return my; -}(messageHandler || {})); + enablePopups: function (enable) { + popupEnabled = enable; + } +}; module.exports = messageHandler;