From 7aa1f2e0a576038d6ac0c6e3a62cc586504b5d48 Mon Sep 17 00:00:00 2001 From: ramandeepromana Date: Thu, 16 Nov 2023 14:59:08 -0400 Subject: [PATCH] [5.3] MSPB-315: Updated cross-site message based routing Moved from flag/bindEvents based cross-site message routing to event subscribe. --- app.js | 83 +++++++++++++-------------------- submodules/callLogs/callLogs.js | 3 +- 2 files changed, 35 insertions(+), 51 deletions(-) diff --git a/app.js b/app.js index 239580af..9f492253 100644 --- a/app.js +++ b/app.js @@ -36,7 +36,9 @@ define(function(require) { }, requests: {}, - subscribe: {}, + subscribe: { + 'core.crossSiteMessage.voip': 'crossSiteMessageHandler' + }, appFlags: { common: { hasProvisioner: false, @@ -70,18 +72,7 @@ define(function(require) { } } } - }, - navigationMenus: [ - 'myOffice', - 'numbers', - 'users', - 'groups', - 'strategy', - 'callLogs', - 'devices', - 'vmboxes', - 'featureCodes' - ] + } }, global: {}, disableFirstUseWalkthrough: monster.config.whitelabel.disableFirstUseWalkthrough @@ -158,45 +149,37 @@ define(function(require) { bindEvents: function(parent) { var self = this, - container = parent.find('.right-content'), - bindDefaultNavigation = function defaultNavigation() { - parent.find('.left-menu').on('click', '.category:not(.loading)', function() { - // Get the ID of the submodule to render - var $this = $(this), - args = { - parent: container, - callback: function() { - parent.find('.category').removeClass('loading'); - } - }, - id = $this.attr('id'); - - // Display the category we clicked as active - parent - .find('.category') - .removeClass('active') - .addClass('loading'); - $this.toggleClass('active'); - - // Empty the main container and then render the submodule content - container.empty(); - monster.pub('voip.' + id + '.render', args); - }); - }, - bindEventNavigation = function bindEventNavigation() { - window.addEventListener('message', function(event) { - var args = { parent: container }; - - if (event.data.type === 'smartpbx.routing' && self.appFlags.common.navigationMenus.includes(event.data.data)) { - container.empty(); - monster.pub('voip.' + event.data.data + '.render', args); + container = parent.find('.right-content'); + + parent.find('.left-menu').on('click', '.category:not(.loading)', function() { + // Get the ID of the submodule to render + var $this = $(this), + args = { + parent: container, + callback: function() { + parent.find('.category').removeClass('loading'); } - }); - }; + }, + id = $this.attr('id'); + + // Display the category we clicked as active + parent + .find('.category') + .removeClass('active') + .addClass('loading'); + $this.toggleClass('active'); + + // Empty the main container and then render the submodule content + container.empty(); + monster.pub('voip.' + id + '.render', args); + }); + }, + + crossSiteMessageHandler: function(topic) { + var crossSiteMessageTopic = topic.replace('.tab', '') + '.render', + container = $('.right-content'); - monster.util.getFeatureConfig('smartpbx.other.eventRouting', false) - ? bindEventNavigation() - : bindDefaultNavigation(); + monster.pub(crossSiteMessageTopic, { parent: container }); }, overlayInsert: function() { diff --git a/submodules/callLogs/callLogs.js b/submodules/callLogs/callLogs.js index e18fb483..dc19cfae 100644 --- a/submodules/callLogs/callLogs.js +++ b/submodules/callLogs/callLogs.js @@ -127,6 +127,7 @@ define(function(require) { var self = this, template, defaultDateRange = 1, + container = parent || $('.right-content'), maxDateRange = 31; if (!toDate && !fromDate) { @@ -193,7 +194,7 @@ define(function(require) { monster.ui.tooltips(template); - parent + container .empty() .append(template);