From 0b224dea88bf47b943ae1f6b35c093a3dc3df59c Mon Sep 17 00:00:00 2001 From: Isaac Sanchez Date: Wed, 25 Jan 2023 03:05:36 -0600 Subject: [PATCH 1/2] MNUM-7: Add the logic to execute external numbers search --- src/apps/common/submodules/numbers/numbers.js | 90 ++++++++++++++++++- 1 file changed, 89 insertions(+), 1 deletion(-) diff --git a/src/apps/common/submodules/numbers/numbers.js b/src/apps/common/submodules/numbers/numbers.js index 38798039b..7dd3e9b88 100644 --- a/src/apps/common/submodules/numbers/numbers.js +++ b/src/apps/common/submodules/numbers/numbers.js @@ -125,7 +125,8 @@ define(function(require) { viewType: data.viewType, canAddExternalCids: monster.util.getCapability('caller_id.external_numbers').isEnabled, canAddExternalNumbers: monster.util.canAddExternalNumbers(), - listAccounts: [] + listAccounts: [], + listExternalNumbersAccounts: [] }; /* Initializing accounts metadata */ @@ -173,6 +174,19 @@ define(function(require) { } }); + /* Save a list of the acccounts that have an associated external number */ + _.each(mapAccounts, function(value) { + self.listAccountExternalNumbers(value.id, function(data) { + if (data.length > 0) { + _.each(data, function(element) { + element.accountId = value.id; + }); + templateData.listExternalNumbersAccounts.push(data); + templateData.listExternalNumbersAccounts = _.flatten(templateData.listExternalNumbersAccounts); + } + }); + }); + /* Order the subaccount list by name */ templateData.listAccounts.sort(function(a, b) { return a.name.toLowerCase() > b.name.toLowerCase() ? 1 : -1; @@ -811,6 +825,47 @@ define(function(require) { }); }; + var searchExternalNumber = function(searchString, parent) { + var viewList = parent, + searchString = monster.util.unformatPhoneNumber(searchString), + foundNumber = _.find(dataNumbers.listExternalNumbersAccounts, { number: searchString }), + accountId = foundNumber ? foundNumber.accountId : '', + numberId = foundNumber ? foundNumber.id : ''; + + if (accountId) { + var section = viewList.find('[data-id="' + accountId + '"]'), + toggle = function() { + section.addClass('open'); + + var numberBox = parent.find('.number-box[data-id="' + numberId + '"]'); + + if (!section.hasClass('open')) { + section.find('input[type="checkbox"]:checked').prop('checked', false); + section.find('.number-box.selected').removeClass('selected'); + } + + monster.ui.highlight(numberBox, { + timer: 5000 + }); + + _.each(dataNumbers.listAccounts, function(account) { + if (account.id === accountId) { + account.open = section.hasClass('open') ? 'open' : ''; + } + }); + }; + + displayNumberList(accountId, function() { + toggle(); + }); + } else { + monster.ui.toast({ + type: 'error', + message: self.i18n.active().numbers.numberNotFound + }); + } + }; + parent.on('click', '.list-numbers[data-type="spare"] button.search-numbers', function(e) { var spareList = parent.find('.list-numbers[data-type="spare"]'), searchString = spareList.find('.search-custom input[type="text"]').val().toLowerCase(); @@ -847,6 +902,24 @@ define(function(require) { } }); + parent.on('click', '.list-numbers[data-type="external"] button.search-numbers', function(e) { + var externalList = parent.find('.list-numbers[data-type="external"]'), + searchString = externalList.find('.search-custom input[type="text"]').val().toLowerCase(); + + searchExternalNumber(searchString, externalList); + }); + + parent.on('keyup', '.list-numbers[data-type="external"] .search-custom input[type="text"]', function(e) { + if (e.keyCode === 13) { + var val = e.target.value.toLowerCase(), + externalList = parent.find('.list-numbers[data-type="external"]'); + + if (val) { + searchExternalNumber(val, externalList); + } + } + }); + self.numbersBindExternalNumbersEvents(parent, dataNumbers); }, @@ -1539,6 +1612,21 @@ define(function(require) { }); }, + listAccountExternalNumbers: function(accountId, success) { + var self = this; + + self.callApi({ + resource: 'externalNumbers.list', + data: { + accountId: accountId, + generateError: false + }, + success: function(_data, status) { + success && success(_data.data); + } + }); + }, + numbersDelete: function(args, callback) { var self = this; From bf2e81c4aca26e1012334a3e99e977b685129ee9 Mon Sep 17 00:00:00 2001 From: Isaac Sanchez Date: Wed, 25 Jan 2023 03:06:30 -0600 Subject: [PATCH 2/2] MNUM-7: Add the button to the numbers template --- src/apps/common/submodules/numbers/views/external.html | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/apps/common/submodules/numbers/views/external.html b/src/apps/common/submodules/numbers/views/external.html index 79efb3b6f..653a02706 100644 --- a/src/apps/common/submodules/numbers/views/external.html +++ b/src/apps/common/submodules/numbers/views/external.html @@ -1,5 +1,12 @@
+
+ + +
+