mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-04 19:05:37 +08:00
Added user settings for email notifications [SCI-443]
This commit is contained in:
parent
8dc956010c
commit
5399033fce
7 changed files with 89 additions and 34 deletions
|
@ -95,28 +95,53 @@
|
||||||
|
|
||||||
// Setup notification checkbox buttons
|
// Setup notification checkbox buttons
|
||||||
function notificationsSettings() {
|
function notificationsSettings() {
|
||||||
var recent_notification = $('[name="recent_notification"]');
|
var notification_settings = [ "recent_notification",
|
||||||
recent_notification
|
"assignments_notification" ]
|
||||||
|
|
||||||
|
for (var i = 0; i < notification_settings.length; i++ ) {
|
||||||
|
var setting = $('[name="' + notification_settings[i] + '"]');
|
||||||
|
var dependant = $('[name="' + notification_settings[i] + '_email"]');
|
||||||
|
setting
|
||||||
.checkboxpicker({
|
.checkboxpicker({
|
||||||
onActiveCls: 'btn-primary'
|
onActiveCls: 'btn-primary'
|
||||||
|
}).change(function() {
|
||||||
|
if ( $(this).prop('checked') ) {
|
||||||
|
enableDependant($('[name="' + $(this).attr('name') + '_email"]'));
|
||||||
|
} else {
|
||||||
|
disableDependant($('[name="' + $(this).attr('name') + '_email"]'));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if ( recent_notification.attr('value') === 'true' ) {
|
if ( setting.attr('value') === 'true' ) {
|
||||||
recent_notification.prop('checked', true);
|
setting.prop('checked', true);
|
||||||
} else {
|
} else {
|
||||||
recent_notification.prop('checked', false);
|
setting.prop('checked', false);
|
||||||
|
disableDependant(dependant);
|
||||||
}
|
}
|
||||||
|
|
||||||
var assignments_notification = $('[name="assignments_notification"]');
|
setEmailSwitch(dependant);
|
||||||
assignments_notification
|
}
|
||||||
|
|
||||||
|
function setEmailSwitch(setting) {
|
||||||
|
setting
|
||||||
.checkboxpicker({
|
.checkboxpicker({
|
||||||
onActiveCls: 'btn-primary'
|
onActiveCls: 'btn-primary'
|
||||||
});
|
});
|
||||||
|
if ( setting.attr('value') === 'true' ) {
|
||||||
if ( assignments_notification.attr('value') === 'true' ) {
|
setting.prop('checked', true);
|
||||||
assignments_notification.prop('checked', true);
|
enableDependant(setting);
|
||||||
} else {
|
} else {
|
||||||
assignments_notification.prop('checked', false);
|
setting.prop('checked', false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function disableDependant(dependant) {
|
||||||
|
dependant.checkboxpicker().prop('disabled', true);
|
||||||
|
dependant.checkboxpicker().prop('checked', false);
|
||||||
|
}
|
||||||
|
|
||||||
|
function enableDependant(dependant) {
|
||||||
|
dependant.checkboxpicker().prop('disabled', false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -458,8 +458,13 @@ class Users::SettingsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def notifications_settings
|
def notifications_settings
|
||||||
@user.assignments_notification = params[:assignments_notification]
|
@user.assignments_notification =
|
||||||
@user.recent_notification = params[:recent_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
|
if @user.save
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
|
|
@ -33,7 +33,8 @@ class UserNotification < ActiveRecord::Base
|
||||||
def send_email
|
def send_email
|
||||||
if self.notification.type_of == 'system_message'
|
if self.notification.type_of == 'system_message'
|
||||||
send_email_notification(self.user, self.notification)
|
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)
|
send_email_notification(self.user, self.notification)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -59,6 +59,13 @@
|
||||||
<%= f.label t('notifications.form.assignments'), class: 'visible-sm visible-xs' %>
|
<%= f.label t('notifications.form.assignments'), class: 'visible-sm visible-xs' %>
|
||||||
<%= check_box_tag :assignments_notification, @user.assignments_notification %>
|
<%= check_box_tag :assignments_notification, @user.assignments_notification %>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="col-md-3 col-sm-3 col-text-center">
|
||||||
|
<h5 class="hidden-sm hidden-xs"><%= t('notifications.form.email_settings') %></h5>
|
||||||
|
<%= f.label t('notifications.form.recent_notification'), class: 'visible-sm visible-xs'%> <br>
|
||||||
|
<%= check_box_tag :recent_notification_email, @user.recent_notification_email %> <br>
|
||||||
|
<%= f.label t('notifications.form.assignments'), class: 'visible-sm visible-xs' %>
|
||||||
|
<%= check_box_tag :assignments_notification_email, @user.assignments_notification_email %>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1514,6 +1514,7 @@ en:
|
||||||
form:
|
form:
|
||||||
assignments: "Assignments notifications"
|
assignments: "Assignments notifications"
|
||||||
recent_notification: "Change notifications"
|
recent_notification: "Change notifications"
|
||||||
|
email_settings: "E-mail notifications"
|
||||||
show_all: "Show all notifications"
|
show_all: "Show all notifications"
|
||||||
show_more: "Show more notifications"
|
show_more: "Show more notifications"
|
||||||
no_notifications: "No notifications."
|
no_notifications: "No notifications."
|
||||||
|
|
|
@ -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
|
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# 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
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
@ -662,6 +662,8 @@ ActiveRecord::Schema.define(version: 20161004074754) do
|
||||||
t.integer "tutorial_status", default: 0, null: false
|
t.integer "tutorial_status", default: 0, null: false
|
||||||
t.boolean "assignments_notification", default: true
|
t.boolean "assignments_notification", default: true
|
||||||
t.boolean "recent_notification", default: true
|
t.boolean "recent_notification", default: true
|
||||||
|
t.boolean "assignments_notification_email", default: false
|
||||||
|
t.boolean "recent_notification_email", default: false
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree
|
add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree
|
||||||
|
|
Loading…
Add table
Reference in a new issue