-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MNUM-7: Add "GO" under "Caller ID Numbers" tab #1048
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As the sub-accounts' numbers will no longer be pre-loaded, this needs to be refactored. Check how the function |
||
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All the functions in a submodule should have the submodule name as prefix. In this case it would be something like |
||
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; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The numbers should not be pre-loaded, because one request will be done per sub-account, and if the current account has a lot of sub-accounts, it will hit the server a lot of times. Also this is unnecessary, because these numbers are not displayed until the account is expanded in the view.
See how this works in the "Numbers" app, in the "Spare numbers" or "Numbers in use" tab.