diff --git a/src/apps/callflows/app.js b/src/apps/callflows/app.js index cf303ce..c4d36ad 100644 --- a/src/apps/callflows/app.js +++ b/src/apps/callflows/app.js @@ -9,6 +9,7 @@ define(function(require) { 'branchbnumber', 'branchvariable', 'callcenter', + 'checkcid', 'conference', 'device', 'directory', diff --git a/src/apps/callflows/i18n/en-US.json b/src/apps/callflows/i18n/en-US.json index 6beebb9..cd00081 100644 --- a/src/apps/callflows/i18n/en-US.json +++ b/src/apps/callflows/i18n/en-US.json @@ -160,6 +160,35 @@ "merged": "Merged", "user": "User" }, + "check_cid": { + "check_cid": "Check Cid", + "tooltip": "Handles inspection of incoming caller id and branching to a child callflow node accordingly.", + "edit_dialog": { + "title": "Check Cid", + "cid_external_name": "Caller id external name", + "cid_external_number": "Caller id external number", + "use_absolute_mode": "Use absolute mode", + "use_absolute_mode_tooltip": "If true, direct call down a branch that matches the caller ID", + "regex": "Regex", + "regex_tooltip": "Determine match/nomatch when \"Use absolute mode\" param is disabled", + "user_id": "User ID", + "user_id_tooltip": "User ID to use as owner instead of detected owner" + }, + "menu_option_dialog": { + "title": "Menu option", + "menu_option": "Menu option", + "match": "Match", + "no_match": "No match", + "caller_id": "Caller ID" + }, + "warning_dialog": { + "change_mode_warning": "Change mode warning", + "change_mode_warning_message": "You have changed to the absolute mode. Since your callflow has children elements created in another mode, they may not work correctly. You can delete them and recreate them, or make the necessary changes to existing nodes.", + "remove_all_children": "Remove all children", + "change_children_later": "I will change later", + "cancel": "Cancel" + } + }, "conference": { "conference": "Conference", "conference_tip": "Connect a caller to a Meet-Me conference bridge", diff --git a/src/apps/callflows/style/app.css b/src/apps/callflows/style/app.css index 39e440b..394507f 100644 --- a/src/apps/callflows/style/app.css +++ b/src/apps/callflows/style/app.css @@ -14,6 +14,7 @@ @import url('../submodules/afterbridge/afterbridge.css'); @import url('../submodules/branchbnumber/branchbnumber.css'); @import url('../submodules/branchvariable/branchvariable.css'); +@import url('../submodules/checkcid/checkcid.css'); @import url('../../../css/vendor/bootstrap-tour.css'); /* style.css */ #ws_callflow > .callflow { @@ -1396,7 +1397,6 @@ max-width: 214px; } - .dialog_popup .form_content .checkbox-label-wrapper { padding-left: 140px; text-align: left; @@ -1406,6 +1406,20 @@ padding-top: 0; } +.dialog_popup .dialog_content-part { + margin: 15px 0; +} + +.dialog_popup .buttons-center, +.dialog_popup .buttons-center { + padding: 10px 0 0; +} + +.dialog_popup .buttons-center button, +.dialog_popup .buttons-center .monster-button { + margin: 0 6px 14px; +} + .callflows-port form label:not(.monster-invalid) { float: left; font-size: 15px; @@ -1421,6 +1435,12 @@ width: auto; } +.callflows-port form label.monster-checkbox { + margin-top: 5px; + display: inline-block; + width: auto; +} + .callflows-port label.monster-invalid { position: relative; color: orange; diff --git a/src/apps/callflows/submodules/checkcid/checkcid.css b/src/apps/callflows/submodules/checkcid/checkcid.css new file mode 100644 index 0000000..4782e4f --- /dev/null +++ b/src/apps/callflows/submodules/checkcid/checkcid.css @@ -0,0 +1,7 @@ +.check-cid-dialog.callflows-port form label:not(.monster-invalid) { + width: 160px; +} + +.no-close .ui-dialog-titlebar-close { + display: none; +} diff --git a/src/apps/callflows/submodules/checkcid/checkcid.js b/src/apps/callflows/submodules/checkcid/checkcid.js new file mode 100644 index 0000000..0181381 --- /dev/null +++ b/src/apps/callflows/submodules/checkcid/checkcid.js @@ -0,0 +1,278 @@ +define(function(require) { + var $ = require('jquery'), + monster = require('monster'); + + var useAbsoluteMode; + + var app = { + requests: {}, + + subscribe: { + 'callflows.fetchActions': 'checkcidDefineActions' + }, + + checkcidDefineActions: function(args) { + var self = this, + callflow_nodes = args.actions, + i18n = self.i18n.active().callflows.check_cid; + + + $.extend(callflow_nodes, { + 'check_cid[]': { + name: i18n.check_cid, + icon: 'check', + category: self.i18n.active().oldCallflows.caller_id_cat, + module: 'check_cid', + tip: i18n.tooltip, + data: { + use_absolute_mode: false + }, + rules: [{ + type: 'quantity', + maxSize: 2 + }], + isUsable: 'true', + weight: 48, + caption: function(node, caption_map) { + return self.checkcidGetCaptionFromNode(node); + }, + edit: function(node, callback) { + self.checkcidShowEditDialog(node, callback); + }, + key_caption: function(child_node, caption_map) { + if(child_node.key === 'match') { + return i18n.menu_option_dialog.match; + } else if(child_node.key === 'nomatch') { + return i18n.menu_option_dialog.no_match; + } + return child_node.key; + }, + key_edit: function(child_node, callback) { + var $dialog, $popup; + + $popup = $(self.getTemplate({ + name: 'dialogMenuOption', + data: { + useAbsoluteMode: useAbsoluteMode, + selected: child_node.key === '_' ? '' : child_node.key + }, + submodule: 'checkcid' + })); + + $popup.find('.js-save').on('click', function() { + if(useAbsoluteMode) { + var callerID = $('#check-cid_caller-id', $popup).val(); + child_node.key = callerID; + child_node.key_caption = callerID; + } else { + var $regexKeySelectedOption = $('#check-cid_regex-menu-options option:selected', $popup); + var regexKeyVal = $regexKeySelectedOption.val(); + var regexKeyText = $regexKeySelectedOption.text(); + child_node.key = regexKeyVal; + child_node.key_caption = regexKeyText; + } + $dialog.dialog('close'); + }); + + $dialog = monster.ui.dialog($popup, { + title: self.i18n.active().callflows.check_cid.menu_option_dialog.title, + minHeight: '0', + width: 450, + beforeClose: function() { + if (typeof callback === 'function') { + callback(); + } + } + }); + } + } + }); + }, + + checkcidGetCaptionFromNode: function (node) { + var caption = ''; + useAbsoluteMode = node.getMetadata('use_absolute_mode'); + var callerID = node.getMetadata('caller_id'); + var regex = node.getMetadata('regex'); + if(useAbsoluteMode && callerID && callerID.external) { + if(callerID.external.hasOwnProperty('name')) { + caption = Object.values(callerID.external).join(', ') + } + } else if(regex) { + caption = regex; + } + return caption; + }, + + checkcidShowEditDialog: function (node, callback) { + var self = this; + self.checkcidGetUsers(function(users) { + var $dialogHtml, + $dialog, + i18n = self.i18n.active().callflows.check_cid, + caller_id = node.getMetadata('caller_id') || {}, + regex = node.getMetadata('regex') || '', + user_id = node.getMetadata('user_id') || ''; + useAbsoluteMode = node.getMetadata('use_absolute_mode') || false; + + $dialogHtml = $(self.getTemplate({ + name: 'dialogEdit', + data: { + caller_id: caller_id, + regex: regex, + use_absolute_mode: useAbsoluteMode, + user_id: user_id, + users: users + }, + submodule: 'checkcid' + })); + + $dialog = monster.ui.dialog($dialogHtml, { + title: self.i18n.active().callflows.check_cid.edit_dialog.title, + minHeight: '0', + width: 450, + beforeClose: function() { + if (typeof callback === 'function') { + callback(); + } + } + }); + + monster.ui.tooltips($dialogHtml); + + $('#check-cid_use_absolute_mode', $dialog).change(function (e) { + e.preventDefault(); + var useAbsoluteMode = $(this).is(':checked'); + if(useAbsoluteMode) { + self.checkcidShowChildNodesWarning({ + node: node, + successCallback: function () { + node.rules = [{ + type: 'quantity', + maxSize: 999 + }]; + $('.js-caller-id-mode', $dialog).removeClass('hidden'); + $('.js-regexp-mode', $dialog).addClass('hidden'); + $('#check-cid_use_absolute_mode', $dialog).prop('checked', useAbsoluteMode); + }, + failCallback: function () { + $('#check-cid_use_absolute_mode', $dialog).prop('checked', !useAbsoluteMode); + } + }); + } else { + self.checkcidShowChildNodesWarning({ + node: node, + successCallback: function () { + node.rules = [{ + type: 'quantity', + maxSize: 2 + }]; + $('.js-caller-id-mode').addClass('hidden'); + $('.js-regexp-mode').removeClass('hidden'); + $('#check-cid_use_absolute_mode', $dialog).prop('checked', useAbsoluteMode); + }, + failCallback: function () { + $('#check-cid_use_absolute_mode', $dialog).prop('checked', !useAbsoluteMode); + } + }); + } + }); + + $dialogHtml.find('.js-save').click(function() { + var $form = $(this) + .closest('.js-check-cid-dialog') + .find('.js-check-cid-form'); + var formData = monster.ui.getFormData($form[0]); + + useAbsoluteMode = formData.use_absolute_mode; + node.setMetadata('use_absolute_mode', useAbsoluteMode); + + if(formData.caller_id && formData.caller_id.hasOwnProperty('external')) { + var external = formData.caller_id.external; + if(external.name || external.number) { + node.setMetadata('caller_id', formData.caller_id); + } else { + node.deleteMetadata('caller_id'); + } + } + + formData.user_id ? node.setMetadata('user_id', formData.user_id) : node.deleteMetadata('user_id'); + formData.regex ? node.setMetadata('regex', formData.regex) : node.deleteMetadata('regex'); + + node.caption = self.checkcidGetCaptionFromNode(node); + + if (typeof callback === 'function') { + callback(); + } + + $dialog.dialog('close'); + }); + }); + }, + + checkcidShowChildNodesWarning: function (data) { + var self = this, + $dialog, + $dialogHtml, + node = data.node, + successCallback = data.successCallback, + failCallback = data.failCallback; + + if(node.children.length === 0) { + successCallback(); + return; + } + + $dialogHtml = $(self.getTemplate({ + name: 'dialogWarning', + data: {}, + submodule: 'checkcid' + })); + + $dialog = monster.ui.dialog($dialogHtml, { + title: self.i18n.active().callflows.check_cid.edit_dialog.title, + minHeight: '0', + width: 450, + dialogClass: 'no-close', + }); + + $('.js-remove-all-children', $dialogHtml).on('click', function (e) { + e.preventDefault(); + node.children = []; + self.repaintFlow(); + successCallback(); + $dialog.dialog('close'); + }); + + $('.js-change-later', $dialogHtml).on('click', function (e) { + e.preventDefault(); + successCallback(); + $dialog.dialog('close'); + }); + + $('.js-cancel', $dialogHtml).on('click', function (event) { + event.preventDefault(); + failCallback(); + $dialog.dialog('close'); + }); + }, + + checkcidGetUsers: function (callback) { + var self = this; + + self.getAll({ + resource: 'user.list', + data: { + accountId: self.accountId, + filters: { paginate: false }, + generateError: false + }, + success: function(users, status) { + callback && callback(users.data); + } + }); + }, + }; + + return app; +}); diff --git a/src/apps/callflows/submodules/checkcid/views/dialogEdit.html b/src/apps/callflows/submodules/checkcid/views/dialogEdit.html new file mode 100644 index 0000000..ed5cc16 --- /dev/null +++ b/src/apps/callflows/submodules/checkcid/views/dialogEdit.html @@ -0,0 +1,81 @@ +