diff --git a/app/assets/javascripts/users/settings/preferences.js b/app/assets/javascripts/users/settings/preferences.js
index 20c108e00..b0c7827f7 100644
--- a/app/assets/javascripts/users/settings/preferences.js
+++ b/app/assets/javascripts/users/settings/preferences.js
@@ -95,28 +95,53 @@
// Setup notification checkbox buttons
function notificationsSettings() {
- var recent_notification = $('[name="recent_notification"]');
- recent_notification
- .checkboxpicker({
- onActiveCls: 'btn-primary'
- });
+ var notification_settings = [ "recent_notification",
+ "assignments_notification" ]
- if ( recent_notification.attr('value') === 'true' ) {
- recent_notification.prop('checked', true);
- } else {
- recent_notification.prop('checked', false);
+ for (var i = 0; i < notification_settings.length; i++ ) {
+ var setting = $('[name="' + notification_settings[i] + '"]');
+ var dependant = $('[name="' + notification_settings[i] + '_email"]');
+ setting
+ .checkboxpicker({
+ onActiveCls: 'btn-primary'
+ }).change(function() {
+ if ( $(this).prop('checked') ) {
+ enableDependant($('[name="' + $(this).attr('name') + '_email"]'));
+ } else {
+ disableDependant($('[name="' + $(this).attr('name') + '_email"]'));
+ }
+ });
+
+ if ( setting.attr('value') === 'true' ) {
+ setting.prop('checked', true);
+ } else {
+ setting.prop('checked', false);
+ disableDependant(dependant);
+ }
+
+ setEmailSwitch(dependant);
}
- var assignments_notification = $('[name="assignments_notification"]');
- assignments_notification
- .checkboxpicker({
- onActiveCls: 'btn-primary'
- });
+ function setEmailSwitch(setting) {
+ setting
+ .checkboxpicker({
+ onActiveCls: 'btn-primary'
+ });
+ if ( setting.attr('value') === 'true' ) {
+ setting.prop('checked', true);
+ enableDependant(setting);
+ } else {
+ setting.prop('checked', false);
+ }
+ }
- if ( assignments_notification.attr('value') === 'true' ) {
- assignments_notification.prop('checked', true);
- } else {
- assignments_notification.prop('checked', false);
+ function disableDependant(dependant) {
+ dependant.checkboxpicker().prop('disabled', true);
+ dependant.checkboxpicker().prop('checked', false);
+ }
+
+ function enableDependant(dependant) {
+ dependant.checkboxpicker().prop('disabled', false);
}
}
diff --git a/app/controllers/users/settings_controller.rb b/app/controllers/users/settings_controller.rb
index bd89daef8..7e8f13c3c 100644
--- a/app/controllers/users/settings_controller.rb
+++ b/app/controllers/users/settings_controller.rb
@@ -458,8 +458,13 @@ class Users::SettingsController < ApplicationController
end
def notifications_settings
- @user.assignments_notification = params[:assignments_notification]
- @user.recent_notification = params[:recent_notification]
+ @user.assignments_notification =
+ params[:assignments_notification] ? true : false
+ @user.recent_notification = params[:recent_notification] ? true : false
+ @user.recent_notification_email =
+ params[:recent_notification_email] ? true : false
+ @user.assignments_notification_email =
+ params[:assignments_notification_email] ? true : false
if @user.save
respond_to do |format|
diff --git a/app/models/user_notification.rb b/app/models/user_notification.rb
index 4fbce6ffd..b9819ca59 100644
--- a/app/models/user_notification.rb
+++ b/app/models/user_notification.rb
@@ -33,7 +33,8 @@ class UserNotification < ActiveRecord::Base
def send_email
if self.notification.type_of == 'system_message'
send_email_notification(self.user, self.notification)
- elsif self.user.assignments_notification || self.user.recent_notification
+ elsif self.user.assignments_notification_email ||
+ self.user.recent_notification_email
send_email_notification(self.user, self.notification)
end
end
diff --git a/app/views/users/settings/preferences.html.erb b/app/views/users/settings/preferences.html.erb
index b0df12566..d9c2ec581 100644
--- a/app/views/users/settings/preferences.html.erb
+++ b/app/views/users/settings/preferences.html.erb
@@ -59,6 +59,13 @@
<%= f.label t('notifications.form.assignments'), class: 'visible-sm visible-xs' %>
<%= check_box_tag :assignments_notification, @user.assignments_notification %>
+
+
<%= t('notifications.form.email_settings') %>
+ <%= f.label t('notifications.form.recent_notification'), class: 'visible-sm visible-xs'%>
+ <%= check_box_tag :recent_notification_email, @user.recent_notification_email %>
+ <%= f.label t('notifications.form.assignments'), class: 'visible-sm visible-xs' %>
+ <%= check_box_tag :assignments_notification_email, @user.assignments_notification_email %>
+
<% end %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index cb025fa2a..3bef47e81 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -1514,6 +1514,7 @@ en:
form:
assignments: "Assignments notifications"
recent_notification: "Change notifications"
+ email_settings: "E-mail notifications"
show_all: "Show all notifications"
show_more: "Show more notifications"
no_notifications: "No notifications."
diff --git a/db/migrate/20161006065203_add_email_notification_settings_to_user.rb b/db/migrate/20161006065203_add_email_notification_settings_to_user.rb
new file mode 100644
index 000000000..31f9e8bad
--- /dev/null
+++ b/db/migrate/20161006065203_add_email_notification_settings_to_user.rb
@@ -0,0 +1,14 @@
+class AddEmailNotificationSettingsToUser < ActiveRecord::Migration
+ def up
+ add_column :users, :assignments_notification_email, :boolean, default: false
+ add_column :users, :recent_notification_email, :boolean, default: false
+
+ User.update_all(assignments_notification_email: false,
+ recent_notification_email: false)
+ end
+
+ def down
+ remove_column :users, :assignments_notification_email
+ remove_column :users, :recent_notification_email
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 4a0b0e388..02905cd39 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20161004074754) do
+ActiveRecord::Schema.define(version: 20161006065203) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -628,20 +628,20 @@ ActiveRecord::Schema.define(version: 20161004074754) do
add_index "user_projects", ["user_id"], name: "index_user_projects_on_user_id", using: :btree
create_table "users", force: :cascade do |t|
- t.string "full_name", null: false
- t.string "initials", null: false
- t.string "email", default: "", null: false
- t.string "encrypted_password", default: "", null: false
+ t.string "full_name", null: false
+ t.string "initials", null: false
+ t.string "email", default: "", null: false
+ t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
- t.integer "sign_in_count", default: 0, null: false
+ t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
t.string "avatar_file_name"
t.string "avatar_content_type"
t.integer "avatar_file_size"
@@ -650,7 +650,7 @@ ActiveRecord::Schema.define(version: 20161004074754) do
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.string "unconfirmed_email"
- t.string "time_zone", default: "UTC"
+ t.string "time_zone", default: "UTC"
t.string "invitation_token"
t.datetime "invitation_created_at"
t.datetime "invitation_sent_at"
@@ -658,10 +658,12 @@ ActiveRecord::Schema.define(version: 20161004074754) do
t.integer "invitation_limit"
t.integer "invited_by_id"
t.string "invited_by_type"
- t.integer "invitations_count", default: 0
- t.integer "tutorial_status", default: 0, null: false
- t.boolean "assignments_notification", default: true
- t.boolean "recent_notification", default: true
+ t.integer "invitations_count", default: 0
+ t.integer "tutorial_status", default: 0, null: false
+ t.boolean "assignments_notification", default: true
+ t.boolean "recent_notification", default: true
+ t.boolean "assignments_notification_email", default: false
+ t.boolean "recent_notification_email", default: false
end
add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree