diff --git a/i18n/en-US.json b/i18n/en-US.json index 0f11d88..0d88e7e 100644 --- a/i18n/en-US.json +++ b/i18n/en-US.json @@ -158,11 +158,16 @@ "inherit": "Inherit", "deny": "Deny", "matcher": { - "help": "Type in a number and click on \"Test\" to see which category it falls in.", + "help": "Type in a number and click on \"Test\" to see if the call would be allowed.", "placeholder": "+18554443333", "button": "Test", - "label": "The above number matched this rule." - } + "label": "The above number matched this rule.", + "__comment": "UI-727, v3.19_s2: Updating the way call restrictions are displayed on devices.", + "allowMessage": "This device will be allowed to place a call to {{phoneNumber}}", + "denyMessage": "This device will not be allowed to place a call to {{phoneNumber}}." + }, + "__comment": "UI-727, v3.19_s2: Updating the way call restrictions are displayed on devices.", + "allow": "Allow" }, "video": { "menuTitle": "Video", diff --git a/i18n/fr-FR.json b/i18n/fr-FR.json index a102a41..deab910 100644 --- a/i18n/fr-FR.json +++ b/i18n/fr-FR.json @@ -141,11 +141,15 @@ "inherit": "Hériter", "deny": "Refuser", "matcher": { - "help": "Saisissez un numéro et cliquez sur \"Tester\" pour voir à quelle catégorie il appartient.", + "help": "Saisissez un numéro et cliquez sur \"Tester\" pour savoir s'il sera autorisé.", "placeholder": "+18554443333", "button": "Tester", - "label": "Le numéro ci-dessus appartient à cette catégorie." - } + "label": "Le numéro ci-dessus appartient à cette catégorie.", + "allowMessage": "Ce téléphone sera autorisé à appeler le numéro {{phoneNumber}}", + "denyMessage": "Ce téléphone ne sera pas autorisé à appeler le numéro {{phoneNumber}}." + }, + "__comment": "UI-727, v3.19_s2: Updating the way call restrictions are displayed on devices.", + "allow": "Autoriser" }, "video": { "menuTitle": "Vidéo", diff --git a/submodules/devices/devices.css b/submodules/devices/devices.css index 9df32a3..134343c 100644 --- a/submodules/devices/devices.css +++ b/submodules/devices/devices.css @@ -278,13 +278,30 @@ margin-left: 5px; } -.edit-device .restriction-matcher-label { - line-height: 30px; - margin-right: 50px; - float: right; +.edit-device .restriction-matcher-sign { + margin-left: 20px; + width: 25px; + vertical-align: middle; display: none; } +.edit-device .restriction-list { + display: inline-block; +} + +.edit-device .restriction-message { + width: 275px; + margin: 0 0 0 20px !important; + padding: 10px; + vertical-align: top; + display: none; +} + +.edit-device .restriction-list .restriction-line.disabled .control-label { + opacity: 0.5; + cursor: default; +} + /* Codecs selector */ .edit-device .content .codec-selector .box-selector { float: left; diff --git a/submodules/devices/devices.js b/submodules/devices/devices.js index fb63d97..5ab0589 100644 --- a/submodules/devices/devices.js +++ b/submodules/devices/devices.js @@ -359,27 +359,61 @@ define(function(require){ } }); + templateDevice.find('.restriction-list .switch').on('switch-change', function() { + templateDevice.find('.restriction-matcher-sign').hide(); + templateDevice.find('.restriction-message').hide(); + }); + templateDevice.find('.restriction-matcher-button').on('click', function(e) { e.preventDefault(); var number = templateDevice.find('.restriction-matcher-input').val(), matched = false; - templateDevice.find('.restriction-matcher-label').each(function() { - var label = $(this), - regex = new RegExp(data.extra.restrictions[label.data('restriction')].regex); - - if(regex.test(number)) { - label.show(); - if(matched) { - label.fadeTo(0, 0.5); - } else { - label.fadeTo(0, 1); + + if(number) { + self.callApi({ + resource: 'numbers.matchClassifier', + data: { + accountId: self.accountId, + phoneNumber: encodeURIComponent(number) + }, + success: function(data, status) { + var matchedLine = templateDevice.find('.restriction-line[data-restriction="'+data.data.name+'"]'), + matchedSign = matchedLine.find('.restriction-matcher-sign'), + matchedMsg = templateDevice.find('.restriction-message'); + + templateDevice.find('.restriction-matcher-sign').hide(); + if(matchedLine.find('.switch').bootstrapSwitch('status')) { + matchedSign.removeClass('icon-red icon-remove') + .addClass('icon-green icon-ok') + .css('display', 'inline-block'); + + matchedMsg.removeClass('red-box') + .addClass('green-box') + .css('display', 'inline-block') + .empty() + .text( + monster.template(self, '!' + self.i18n.active().devices.popupSettings.restrictions.matcher.allowMessage, { phoneNumber: monster.util.formatPhoneNumber(number) }) + ); + } else { + matchedSign.removeClass('icon-green icon-ok') + .addClass('icon-red icon-remove') + .css('display', 'inline-block'); + + matchedMsg.removeClass('green-box') + .addClass('red-box') + .css('display', 'inline-block') + .empty() + .text( + monster.template(self, '!' + self.i18n.active().devices.popupSettings.restrictions.matcher.denyMessage, { phoneNumber: monster.util.formatPhoneNumber(number) }) + ); + } } - matched = true; - } else { - label.hide(); - } - }); - }) + }); + } else { + templateDevice.find('.restriction-matcher-sign').hide(); + templateDevice.find('.restriction-message').hide(); + } + }); var popup = monster.ui.dialog(templateDevice, { position: ['center', 20], @@ -441,8 +475,12 @@ define(function(require){ } if('call_restriction' in formData) { - _.each(formData.call_restriction, function(restriction) { - restriction.action = restriction.action === true ? 'inherit' : 'deny'; + _.each(formData.call_restriction, function(restriction, key) { + if(key in originalData.extra.restrictions && originalData.extra.restrictions[key].disabled) { + restriction.action = originalData.extra.restrictions[key].action + } else { + restriction.action = restriction.action === true ? 'inherit' : 'deny'; + } }); } @@ -605,9 +643,8 @@ define(function(require){ } } }; - + _.each(data.listClassifiers, function(restriction, name) { - defaults.extra.restrictions[name] = restriction; if(name in self.i18n.active().devices.classifiers) { defaults.extra.restrictions[name].friendly_name = self.i18n.active().devices.classifiers[name].name; @@ -616,9 +653,14 @@ define(function(require){ } } + if('call_restriction' in data.accountLimits + && name in data.accountLimits.call_restriction + && data.accountLimits.call_restriction[name].action === 'deny') { + defaults.extra.restrictions[name].disabled = true; + } + if('call_restriction' in data.device && name in data.device.call_restriction) { defaults.extra.restrictions[name].action = data.device.call_restriction[name].action; - } else { defaults.extra.restrictions[name].action = 'inherit'; @@ -844,6 +886,17 @@ define(function(require){ self.devicesGetE911Numbers(function(e911Numbers) { callback(null, e911Numbers); }); + }, + accountLimits: function(callback) { + self.callApi({ + resource: 'limits.get', + data: { + accountId: self.accountId + }, + success: function(data, status) { + callback(null, data.data); + } + }); } }, function(error, results) { diff --git a/views/devices-ata.html b/views/devices-ata.html index 2a432aa..df6532e 100644 --- a/views/devices-ata.html +++ b/views/devices-ata.html @@ -101,21 +101,25 @@