diff --git a/app/assets/javascripts/angularjs/config.js b/app/assets/javascripts/angularjs/config.js index 9d1a7862e..d4e504b21 100644 --- a/app/assets/javascripts/angularjs/config.js +++ b/app/assets/javascripts/angularjs/config.js @@ -26,6 +26,7 @@ var LocalesHelper = function($locale) { RosaABF.factory("LocalesHelper", ['$locale', LocalesHelper]); var SoundNotificationsHelper = function() { + var isOn = true; var statusChangedSound = null; soundManager.setup({ url: '/assets/swf/', @@ -35,8 +36,11 @@ var SoundNotificationsHelper = function() { }); return { buildStatusChanged: function() { - if (statusChangedSound) + if (isOn && statusChangedSound) statusChangedSound.play(); + }, + enabled: function(status) { + isOn = status; } } } diff --git a/app/assets/javascripts/angularjs/controllers/rosa_abf_controller.js b/app/assets/javascripts/angularjs/controllers/rosa_abf_controller.js index acedbd7c8..b0d884682 100644 --- a/app/assets/javascripts/angularjs/controllers/rosa_abf_controller.js +++ b/app/assets/javascripts/angularjs/controllers/rosa_abf_controller.js @@ -1,7 +1,8 @@ -RosaABF.controller('RosaABFController', ['$scope', 'LocalesHelper', function($scope, LocalesHelper) { +RosaABF.controller('RosaABFController', ['$scope', 'LocalesHelper', 'SoundNotificationsHelper', function($scope, LocalesHelper, SoundNotificationsHelper) { - $scope.init = function(locale) { + $scope.init = function(locale, sound_notifications) { LocalesHelper.setLocale(locale); + SoundNotificationsHelper.enabled(sound_notifications); } }]); \ No newline at end of file diff --git a/app/models/user.rb b/app/models/user.rb index 1c4322cc2..85cad6db5 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -41,7 +41,7 @@ class User < Avatar validates :language, :inclusion => {:in => LANGUAGES}, :allow_blank => true attr_accessible :email, :password, :password_confirmation, :current_password, :remember_me, :login, :name, :uname, :language, - :site, :company, :professional_experience, :location + :site, :company, :professional_experience, :location, :sound_notifications attr_readonly :uname attr_accessor :login diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 1083dcf30..a5ef6f216 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -12,7 +12,7 @@ - if user_signed_in? = auto_discovery_link_tag :atom, atom_activity_feeds_path(:format => 'atom', :token => current_user.authentication_token), :title => t("layout.atom_link_tag_title", :nickname => current_user.uname, :app_name => APP_CONFIG['project_name']) - %body{'ng-app' => 'RosaABF', 'ng-controller' => 'RosaABFController', 'ng-init' => "init('#{I18n.locale}')"} + %body{'ng-app' => 'RosaABF', 'ng-controller' => 'RosaABFController', 'ng-init' => "init('#{I18n.locale}', #{!!current_user.try(:sound_notifications)})"} .wrap{:class => content_for?(:sidebar) ? 'columns' : ''} %header .left diff --git a/app/views/users/base/_form.html.haml b/app/views/users/base/_form.html.haml index 4bacedbc6..c4cccf559 100644 --- a/app/views/users/base/_form.html.haml +++ b/app/views/users/base/_form.html.haml @@ -32,6 +32,9 @@ .leftlist= f.label :professional_experience, t("activerecord.attributes.user.professional_experience") .rightlist= f.text_area :professional_experience .both +.leftlist= f.label :sound_notifications, t("activerecord.attributes.user.sound_notifications") +.rightlist= f.check_box :sound_notifications +.both .leftlist \  .rightlist= submit_tag t('layout.save'), :data => {'disable-with' => t('layout.saving')} diff --git a/config/locales/users.en.yml b/config/locales/users.en.yml index b910b21f6..ceab2c08d 100644 --- a/config/locales/users.en.yml +++ b/config/locales/users.en.yml @@ -42,6 +42,7 @@ en: role: Role created_at: Created updated_at: Updated + sound_notifications: Enable sound notifications role: System role language: Language password: Password diff --git a/config/locales/users.ru.yml b/config/locales/users.ru.yml index bd30181e5..e78e1cbd5 100644 --- a/config/locales/users.ru.yml +++ b/config/locales/users.ru.yml @@ -42,6 +42,7 @@ ru: role: Роль created_at: Создан updated_at: Обновлен + sound_notifications: Включить звуковые оповещения role: Роль в системе language: Язык password: Пароль diff --git a/db/migrate/20130820195938_add_sound_notifications_to_user.rb b/db/migrate/20130820195938_add_sound_notifications_to_user.rb new file mode 100644 index 000000000..a7b32696c --- /dev/null +++ b/db/migrate/20130820195938_add_sound_notifications_to_user.rb @@ -0,0 +1,5 @@ +class AddSoundNotificationsToUser < ActiveRecord::Migration + def change + add_column :users, :sound_notifications, :boolean, :default => true + end +end diff --git a/db/schema.rb b/db/schema.rb index 67a46f31b..fb841f5fd 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20130731130518) do +ActiveRecord::Schema.define(:version => 20130820195938) do create_table "activity_feeds", :force => true do |t| t.integer "user_id", :null => false @@ -567,6 +567,7 @@ ActiveRecord::Schema.define(:version => 20130731130518) do t.datetime "confirmation_sent_at" t.string "authentication_token" t.integer "build_priority", :default => 50 + t.boolean "sound_notifications", :default => true end add_index "users", ["authentication_token"], :name => "index_users_on_authentication_token"