From d88d817f99df6fafe7dc9e7b142baf8a6c617e5e Mon Sep 17 00:00:00 2001 From: Maxime Roux Date: Fri, 11 Sep 2015 11:53:13 -0700 Subject: [PATCH] UI-1774: Added a TTS greeting feature to the main conference in SmartPBX --- i18n/en-US.json | 8 ++ submodules/strategy/strategy.css | 27 ++++ submodules/strategy/strategy.js | 134 ++++++++++++++++++- views/strategy-confnum.html | 1 + views/strategy-customConferenceGreeting.html | 27 ++++ views/strategy-layout.html | 1 + 6 files changed, 196 insertions(+), 2 deletions(-) create mode 100644 views/strategy-customConferenceGreeting.html diff --git a/i18n/en-US.json b/i18n/en-US.json index 2b2486a..c3b7dac 100644 --- a/i18n/en-US.json +++ b/i18n/en-US.json @@ -855,6 +855,14 @@ "faxing": { "nameExtension": "'s Main Faxbox", "headerExtension": " Fax Printer" + }, + "__comment": "UI-1774: Adding custom greetings to conference", + "__version": "3.22", + "customConferenceGreeting": { + "title": "Custom Conference Greeting", + "link": "Custom Greeting", + "info": "Customize your conference greeting message using our Text-to-Speech feature. Simply type your greeting message in the input field below.", + "mainConfMissing": "Your Main Conference could not be found." } }, diff --git a/submodules/strategy/strategy.css b/submodules/strategy/strategy.css index 3c5f601..3f9d58b 100644 --- a/submodules/strategy/strategy.css +++ b/submodules/strategy/strategy.css @@ -17,6 +17,7 @@ background: #f3f3f3; margin: 5px; cursor: pointer; + position: relative; } #strategy_container .element-container.open .element-header-outer { @@ -497,6 +498,32 @@ font-size: 28px; color: #44cc44; } +#strategy_container .element-container.strategy-confnum .greeting-link { + margin-right: 30px !important; + position: relative; +} +#strategy_container .element-container.strategy-confnum .greeting-link:after { + content: ""; + position: absolute; + width: 0px; + height: 50px; + border-right: solid 1px #c0c0c9; + top: -15px; + right: -15px; +} + +#strategy_custom_conference_greeting textarea { + width: 100%; + box-sizing: border-box; +} +#strategy_custom_conference_greeting .actions button:not(:first-child) { + margin-left: 10px; +} +#strategy_container .element-container.strategy-confnum .custom-greeting-icon { + position: absolute; + right: 45px; + top: 23px; +} /************ Strategy Faxbox *************/ diff --git a/submodules/strategy/strategy.js b/submodules/strategy/strategy.js index b8b741c..f65815d 100644 --- a/submodules/strategy/strategy.js +++ b/submodules/strategy/strategy.js @@ -192,6 +192,7 @@ define(function(require){ templateData = { mainNumbers: hasMainNumber ? results.callflows["MainCallflow"].numbers.slice(1) : [self.i18n.active().strategy.noNumberTitle], confNumbers: hasConfNumber ? results.callflows["MainConference"].numbers : [self.i18n.active().strategy.noNumberTitle], + customConfGreeting: results.callflows.MainConference && ('welcome_prompt' in results.callflows.MainConference.flow.data) ? true : false, faxingNumbers: hasFaxingNumber ? results.callflows["MainFaxing"].numbers : [self.i18n.active().strategy.noNumberTitle] } template = $(monster.template(self, 'strategy-layout', templateData)); @@ -961,6 +962,101 @@ define(function(require){ monster.pub('common.numbers.dialogSpare', args); }); + container.on('click', '.action-links .greeting-link', function(e) { + e.preventDefault(); + var confCallflow = strategyData.callflows.MainConference; + if(confCallflow) { + self.getMainConferenceGreetingMedia(function(greetingMedia) { + var greetingTemplate = $(monster.template(self, 'strategy-customConferenceGreeting', { + enabled: ('welcome_prompt' in confCallflow.flow.data), + greeting: greetingMedia && greetingMedia.tts ? greetingMedia.tts.text : '' + })), + greetingPopup = monster.ui.dialog(greetingTemplate, { + title: self.i18n.active().strategy.customConferenceGreeting.title, + position: ['center', 20] + }); + + greetingTemplate.find('.switch-state').on('change', function() { + $(this).prop('checked') ? greetingTemplate.find('.content').slideDown() : greetingTemplate.find('.content').slideUp(); + }); + + greetingTemplate.find('.cancel').on('click', function() { + greetingPopup.dialog('close').remove(); + }); + + greetingTemplate.find('.save').on('click', function() { + if(greetingTemplate.find('.switch-state').prop('checked')) { + var updateMedia = function(callback) { + if(greetingMedia) { + greetingMedia.description = ""; + greetingMedia.media_source = "tts"; + greetingMedia.tts = { + text: greetingTemplate.find('.custom-greeting-text').val(), + voice: "female/en-US" + } + self.callApi({ + resource: 'media.update', + data: { + accountId: self.accountId, + mediaId: greetingMedia.id, + data: greetingMedia + }, + success: function(data, status) { + callback && callback(data.data); + } + }); + } else { + self.callApi({ + resource: 'media.create', + data: { + accountId: self.accountId, + data: { + description: '', + media_source: 'tts', + name: 'MainConferenceGreeting', + streamable: true, + type: 'mainConfGreeting', + tts: { + text: greetingTemplate.find('.custom-greeting-text').val(), + voice: "female/en-US" + } + } + }, + success: function(data, status) { + callback && callback(data.data); + } + }); + } + }; + + updateMedia(function(updatedGreeting) { + confCallflow.flow.data.welcome_prompt = { + media_id: updatedGreeting.id + }; + self.strategyUpdateCallflow(confCallflow, function() { + greetingPopup.dialog('close').remove(); + $('#strategy_container .custom-greeting-icon').show(); + }); + }); + } else { + if('welcome_prompt' in confCallflow.flow.data) { + delete confCallflow.flow.data.welcome_prompt; + self.strategyUpdateCallflow(confCallflow, function() { + greetingPopup.dialog('close').remove(); + $('#strategy_container .custom-greeting-icon').hide(); + }); + } else { + greetingPopup.dialog('close').remove(); + } + } + }); + }); + + } else { + monster.ui.alert('error', self.i18n.active().strategy.customConferenceGreeting.mainConfMissing) + } + }); + container.on('click', '.action-links .buy-link', function(e) { e.preventDefault(); monster.pub('common.buyNumbers', { @@ -979,9 +1075,8 @@ define(function(require){ container.on('click', '.number-element .remove-number', function(e) { e.preventDefault(); - var numberToRemove = $(this).data('number'), + var numberToRemove = $(this).data('number').toString(), indexToRemove = strategyData.callflows["MainConference"].numbers.indexOf(numberToRemove); - if(indexToRemove >= 0) { strategyData.callflows["MainConference"].numbers.splice(indexToRemove, 1); if(strategyData.callflows["MainConference"].numbers.length === 0) { @@ -998,6 +1093,41 @@ define(function(require){ }); }, + getMainConferenceGreetingMedia: function(callback) { + var self = this; + self.callApi({ + resource: 'media.list', + data: { + accountId: self.accountId, + filters: { + 'filter_type': 'mainConfGreeting' + } + }, + success: function(data, status) { + if(data.data && data.data.length > 0) { + self.callApi({ + resource: 'media.get', + data: { + accountId: self.accountId, + mediaId: data.data[0].id + }, + success: function(data, status) { + callback && callback(data.data); + }, + error: function(data, status) { + callback && callback(null); + } + }); + } else { + callback && callback(null); + } + }, + error: function(data, status) { + callback && callback(null); + } + }); + }, + strategyFaxingNumBindEvents: function(container, strategyData) { var self = this, addNumbersToMainFaxing = function(numbers) { diff --git a/views/strategy-confnum.html b/views/strategy-confnum.html index c816e87..ef928d3 100644 --- a/views/strategy-confnum.html +++ b/views/strategy-confnum.html @@ -15,6 +15,7 @@
{{ i18n.close }} +