diff --git a/app/assets/javascripts/app/controllers/_profile/notification.coffee b/app/assets/javascripts/app/controllers/_profile/notification.coffee index e117dd6f3..b2d75681f 100644 --- a/app/assets/javascripts/app/controllers/_profile/notification.coffee +++ b/app/assets/javascripts/app/controllers/_profile/notification.coffee @@ -39,7 +39,6 @@ class Index extends App.Controller { name: 'Xylo' file: 'Xylo.mp3' - selected: true } ] @@ -84,10 +83,15 @@ class Index extends App.Controller config['group_ids'] = [] config['group_ids'].push group_id.toString() + for sound in @sounds + if sound.file is App.OnlineNotification.soundFile() + sound.selected = true + @html App.view('profile/notification') groups: groups config: config sounds: @sounds + notification_sound_enabled: App.OnlineNotification.soundEnabled() update: (e) => @@ -147,6 +151,10 @@ class Index extends App.Controller params.notification_config.group_ids = ['-'] @formDisable(e) + params.notification_sound = form_params.notification_sound + if !params.notification_sound.enabled + params.notification_sound.enabled = false + # get data @ajax( id: 'preferences' @@ -179,8 +187,11 @@ class Index extends App.Controller msg: App.i18n.translateContent(data.message) ) - previewSound: (event) -> - sound = new Audio("assets/sounds/#{ @sounds[event.currentTarget.value].file }") - sound.play() + previewSound: (e) => + params = @formParam(e.target) + return if !params.notification_sound + return if !params.notification_sound.file + App.OnlineNotification.play(params.notification_sound.file) + App.Config.set( 'Notifications', { prio: 2600, name: 'Notifications', parent: '#profile', target: '#profile/notifications', role: ['Agent'], controller: Index }, 'NavBarProfile' ) diff --git a/app/assets/javascripts/app/controllers/widget/online_notification.coffee b/app/assets/javascripts/app/controllers/widget/online_notification.coffee index 4ff95bb7a..d70387248 100644 --- a/app/assets/javascripts/app/controllers/widget/online_notification.coffee +++ b/app/assets/javascripts/app/controllers/widget/online_notification.coffee @@ -201,6 +201,7 @@ class App.OnlineNotificationWidget extends App.Controller url: item.link title: title ) + App.OnlineNotification.play() # execute controller again of already open (because hash hasn't changed, we need to do it manually) notificationsContainer.find('.js-locationVerify').on('click', (e) => diff --git a/app/assets/javascripts/app/models/online_notification.coffee b/app/assets/javascripts/app/models/online_notification.coffee index e30f9a2dc..b456a383a 100644 --- a/app/assets/javascripts/app/models/online_notification.coffee +++ b/app/assets/javascripts/app/models/online_notification.coffee @@ -5,6 +5,56 @@ class App.OnlineNotification extends App.Model ### + App.OnlineNotification.play() + + App.OnlineNotification.play('bell.mp3') + + ### + + @play: (file) -> + if file + sound = new Audio("assets/sounds/#{file}") + sound.play() + return + preferences = App.Session.get('preferences') + return if !preferences + return if !App.OnlineNotification.soundEnabled() + file = App.OnlineNotification.soundFile() + sound = new Audio("assets/sounds/#{file}") + sound.play() + + ### + + App.OnlineNotification.soundEnabled() + + ### + + @soundEnabled: -> + preferences = App.Session.get('preferences') + return false if !preferences + if !preferences.notification_sound + preferences.notification_sound = {} + if preferences.notification_sound.enabled is undefined + preferences.notification_sound.enabled = true + return false if preferences.notification_sound.enabled.toString() is 'false' + true + + ### + + App.OnlineNotification.soundFile() + + ### + + @soundFile: -> + file = 'Xylo.mp3' + preferences = App.Session.get('preferences') + return file if !preferences + return file if !preferences.notification_sound + return file if !preferences.notification_sound.file + preferences.notification_sound.file + + ### + App.OnlineNotification.seen( 'Ticket', 123 ) ### diff --git a/app/assets/javascripts/app/views/profile/notification.jst.eco b/app/assets/javascripts/app/views/profile/notification.jst.eco index c887b8636..440110d8c 100644 --- a/app/assets/javascripts/app/views/profile/notification.jst.eco +++ b/app/assets/javascripts/app/views/profile/notification.jst.eco @@ -81,9 +81,9 @@
- + <% for sound in @sounds: %> + <% end %> <%- @Icon('arrow-down') %> @@ -92,7 +92,7 @@