diff --git a/i18n/en-US.json b/i18n/en-US.json index f53311e..7e6b34d 100644 --- a/i18n/en-US.json +++ b/i18n/en-US.json @@ -835,6 +835,8 @@ "ttsGreetingTitle": "Text to Speech", "ttsGreetingPlaceholder": "Please enter your greeting message here.", "uploadGreetingTitle": "Upload your own file", + "chooseExistingGreetingTitle": "Choose from existing recordings", + "noExistingGreetings": "You don't have any greetings recorded yet. Upload some first.", "recordGreetingTitle": "Record it over the phone", "recordGreetingInfo": "Record the greeting message yourself over the phone, by following the steps below:", "recordGreetingLines": { diff --git a/submodules/strategy/strategy.js b/submodules/strategy/strategy.js index e5fb954..e852960 100644 --- a/submodules/strategy/strategy.js +++ b/submodules/strategy/strategy.js @@ -2313,35 +2313,51 @@ define(function(require) { label = params.label, template, menu, greeting, showPopup = function() { - template = $(monster.template(self, 'strategy-menuPopup', { menu: menu, greeting: greeting })); + self.callApi({ + resource: 'media.list', + data: { + accountId: self.accountId + }, + success: function(response) { + var greetingFiles, + noGreetingFiles; + if(response.data.length > 0) { + greetingFiles = response.data; + } else { + noGreetingFiles = true; + } - var popup = monster.ui.dialog(template, { - title: self.i18n.active().strategy.popup.title + ' - ' + label, - dialogClass: 'overflow-visible' - }); + template = $(monster.template(self, 'strategy-menuPopup', { menu: menu, greeting: greeting, greetingFiles: greetingFiles, noGreetingFiles: noGreetingFiles })); - var menuLineContainer = template.find('.menu-block .left .content'), - popupCallEntities = $.extend(true, {}, strategyData.callEntities, { voicemail: strategyData.voicemails }, { directory: strategyData.directories }), - dropdownCallEntities = self.strategyGetCallEntitiesDropdownData(popupCallEntities); + var popup = monster.ui.dialog(template, { + title: self.i18n.active().strategy.popup.title + ' - ' + label, + dialogClass: 'overflow-visible' + }); - _.each(strategyData.callflows[name].flow.children, function(val, key) { - menuLineContainer.append(monster.template(self, 'strategy-menuLine', { - number: key, - callEntities: dropdownCallEntities, - selectedId: val.data.id || val.data.endpoints[0].id - })); - }); + var menuLineContainer = template.find('.menu-block .left .content'), + popupCallEntities = $.extend(true, {}, strategyData.callEntities, { voicemail: strategyData.voicemails }, { directory: strategyData.directories }), + dropdownCallEntities = self.strategyGetCallEntitiesDropdownData(popupCallEntities); - $.each(menuLineContainer.find('.target-input'), function() { - var $this = $(this), - icon = $this.find('.target-select option:selected').parents('optgroup').data('icon'); - $this.find('.target-icon').addClass(icon); - }); + _.each(strategyData.callflows[name].flow.children, function(val, key) { + menuLineContainer.append(monster.template(self, 'strategy-menuLine', { + number: key, + callEntities: dropdownCallEntities, + selectedId: val.data.id || val.data.endpoints[0].id + })); + }); + + $.each(menuLineContainer.find('.target-input'), function() { + var $this = $(this), + icon = $this.find('.target-select option:selected').parents('optgroup').data('icon'); + $this.find('.target-icon').addClass(icon); + }); - self.strategyBindMenuPopupEvents(popup, $.extend({ - menu: menu, - greeting: greeting - }, params)); + self.strategyBindMenuPopupEvents(popup, $.extend({ + menu: menu, + greeting: greeting + }, params)); + } + }); }; if (name in strategyData.callflows) { @@ -2439,6 +2455,7 @@ define(function(require) { container = popup.find('#strategy_menu_popup'), ttsGreeting = container.find('#strategy_menu_popup_tts_greeting'), uploadGreeting = container.find('#strategy_menu_popup_upload_greeting'), + chooseExisting = container.find('#strategy_menu_popup_choose_existing'), mediaToUpload; container.find('.target-select').chosen({ search_contains: true, width: '150px' }); @@ -2631,7 +2648,28 @@ define(function(require) { } }); - container.find('.cancel-greeting').on('click', function(e) { + chooseExisting.find('.update-greeting').on('click', function(ev) { + ev.preventDefault(); + + var greetingId = chooseExisting.find('.choose-input').find(':selected').val(); + menu.media.greeting = greetingId; + self.callApi({ + resource: 'menu.update', + data: { + accountId: self.accountId, + menuId: menu.id, + data: menu + }, + success: function(data, status) { + menu = data.data; + container.find('.greeting-option').removeClass('active'); + chooseExisting.parents('.greeting-option').addClass('active'); + chooseExisting.collapse('hide'); + } + }); + }); + + container.find('.cancel-greeting').on('click', function() { $(this).parents('.collapse').collapse('hide'); }); diff --git a/views/strategy-menuPopup.html b/views/strategy-menuPopup.html index 682ff7e..9753388 100644 --- a/views/strategy-menuPopup.html +++ b/views/strategy-menuPopup.html @@ -57,6 +57,35 @@ +