From f061be784ef61bd01c76e0cf66e09525b1d45699 Mon Sep 17 00:00:00 2001 From: mira-t Date: Wed, 21 Mar 2018 11:33:15 +1300 Subject: [PATCH] Add do not disturb user feature (#44) --- i18n/en-US.json | 4 ++ submodules/users/users.js | 56 +++++++++++++++++++++++++ views/users-feature-do_not_disturb.html | 20 +++++++++ 3 files changed, 80 insertions(+) create mode 100644 views/users-feature-do_not_disturb.html diff --git a/i18n/en-US.json b/i18n/en-US.json index 09cf394..825e820 100644 --- a/i18n/en-US.json +++ b/i18n/en-US.json @@ -611,6 +611,10 @@ "help": "You can create a conference call by providing a conferencing phone number and your personal room number to the participants", "noConfNumbers": "You need to add a Main Conference Number (in the Main number section on the left of the SmartPBX) in order to enable the Personnals Conference Bridges" }, + "do_not_disturb": { + "headline": "User DND Settings", + "title": "Do Not Disturb" + }, "faxing": { "trialError": "You're currently using a trial version of the UI. Please upgrade your account to have access to the Faxing feature!", "title": "Faxbox", diff --git a/submodules/users/users.js b/submodules/users/users.js index 945886c..bde08a9 100644 --- a/submodules/users/users.js +++ b/submodules/users/users.js @@ -232,6 +232,11 @@ define(function(require) { icon: 'fa fa-microphone', iconColor: 'monster-blue', title: self.i18n.active().users.callRecording.title + }, + do_not_disturb: { + icon: 'fa fa-ban', + iconColor: 'monster-red', + title: self.i18n.active().users.do_not_disturb.title } } }; @@ -1389,6 +1394,10 @@ define(function(require) { } }); + template.on('click', '.feature[data-feature="do_not_disturb"]', function() { + self.usersRenderDoNotDisturb(currentUser); + }); + template.on('click', '.feature[data-feature="call_forward"]', function() { if (currentUser.features.indexOf('find_me_follow_me') < 0) { var featureUser = $.extend(true, {}, currentUser); @@ -2191,6 +2200,53 @@ define(function(require) { popup.find('.monster-button').blur(); }, + usersRenderDoNotDisturb: function(featureUser) { + var self = this, + featureTemplate = $(monster.template(self, 'users-feature-do_not_disturb', featureUser)), + switchFeature = featureTemplate.find('#checkbox_do_not_disturb'); + + featureTemplate.find('.cancel-link').on('click', function() { + popup.dialog('close').remove(); + }); + featureTemplate.find('.save').on('click', function() { + var userToSave = featureUser; + //update data.data.do_not_disturb depending on the switch status + if (typeof userToSave.do_not_disturb === 'undefined') { + userToSave.do_not_disturb = {}; + } + if (typeof userToSave.do_not_disturb.enabled === 'undefined') { + userToSave.do_not_disturb.enabled = false; + } + userToSave.do_not_disturb.enabled = switchFeature.prop('checked'); + + self.usersUpdateUser(userToSave, function(data) { + self.callApi({ + resource: 'user.updatePresence', + data: { + accountId: self.accountId, + userId: userToSave.id, + data: { + action: 'set', + state: userToSave.do_not_disturb.enabled ? 'confirmed' : 'terminated' + } + }, + error: function() { + console.log('Failed to update presence state'); + } + }); + popup.dialog('close').remove(); + self.usersRender({ + userId: userToSave.id, + openedTab: 'features' + }); + }); + }); + var popup = monster.ui.dialog(featureTemplate, { + title: featureUser && featureUser.extra && featureUser.extra.mapFeatures.do_not_disturb.title, + position: ['center', 20] + }); + }, + usersRenderFindMeFollowMe: function(params) { var self = this; diff --git a/views/users-feature-do_not_disturb.html b/views/users-feature-do_not_disturb.html new file mode 100644 index 0000000..3ceecf0 --- /dev/null +++ b/views/users-feature-do_not_disturb.html @@ -0,0 +1,20 @@ +
+
+
+ +
+ {{ i18n.users.do_not_disturb.headline }} +
+ {{#monsterSwitch}} + + {{/monsterSwitch}} +
+
+ +
+
+ {{ i18n.cancel }} + +
+
+