2017-02-09 18:07:16 +08:00
|
|
|
module Users
|
|
|
|
module Settings
|
|
|
|
module Account
|
|
|
|
class PreferencesController < ApplicationController
|
|
|
|
before_action :load_user, only: [
|
|
|
|
:index,
|
|
|
|
:update,
|
|
|
|
:notifications_settings
|
|
|
|
]
|
2018-04-05 22:30:02 +08:00
|
|
|
layout 'fluid'
|
2017-02-09 18:07:16 +08:00
|
|
|
|
|
|
|
def index
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
respond_to do |format|
|
|
|
|
if @user.update(update_params)
|
|
|
|
flash[:notice] =
|
|
|
|
t('users.settings.account.preferences.update_flash')
|
|
|
|
format.json do
|
|
|
|
flash.keep
|
|
|
|
render json: { status: :ok }
|
|
|
|
end
|
|
|
|
else
|
|
|
|
format.json do
|
|
|
|
render json: @user.errors,
|
|
|
|
status: :unprocessable_entity
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def notifications_settings
|
2017-12-13 18:59:53 +08:00
|
|
|
@user.assignments_notification =
|
2017-02-09 18:07:16 +08:00
|
|
|
params[:assignments_notification] ? true : false
|
2017-12-13 18:59:53 +08:00
|
|
|
@user.recent_notification =
|
2017-02-09 18:07:16 +08:00
|
|
|
params[:recent_notification] ? true : false
|
2017-12-13 18:59:53 +08:00
|
|
|
@user.recent_email_notification =
|
2017-02-09 18:07:16 +08:00
|
|
|
params[:recent_notification_email] ? true : false
|
2017-12-13 18:59:53 +08:00
|
|
|
@user.assignments_email_notification =
|
2017-02-09 18:07:16 +08:00
|
|
|
params[:assignments_notification_email] ? true : false
|
2017-12-13 18:59:53 +08:00
|
|
|
@user.system_message_email_notification =
|
2017-02-09 18:07:16 +08:00
|
|
|
params[:system_message_notification_email] ? true : false
|
|
|
|
|
|
|
|
if @user.save
|
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
|
|
|
render json: {
|
|
|
|
status: :ok
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
|
|
|
render json: {
|
|
|
|
status: :unprocessable_entity
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def load_user
|
|
|
|
@user = current_user
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_params
|
|
|
|
params.require(:user).permit(
|
2017-08-10 20:29:01 +08:00
|
|
|
:time_zone
|
2017-02-09 18:07:16 +08:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|