2015-04-30 17:06:18 +00:00
|
|
|
class Profiles::NotificationsController < Profiles::ApplicationController
|
2013-03-27 17:04:29 +00:00
|
|
|
def show
|
2015-02-06 23:23:58 +00:00
|
|
|
@user = current_user
|
2013-03-27 17:04:29 +00:00
|
|
|
@notification = current_user.notification
|
2014-09-14 16:51:54 +00:00
|
|
|
@project_members = current_user.project_members
|
|
|
|
@group_members = current_user.group_members
|
2013-03-27 17:04:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2013-04-04 19:11:51 +00:00
|
|
|
type = params[:notification_type]
|
|
|
|
|
|
|
|
@saved = if type == 'global'
|
2015-02-06 23:23:58 +00:00
|
|
|
current_user.update_attributes(user_params)
|
2013-06-21 20:17:58 +00:00
|
|
|
elsif type == 'group'
|
2015-03-13 15:16:51 +00:00
|
|
|
group_member = current_user.group_members.find(params[:notification_id])
|
|
|
|
group_member.notification_level = params[:notification_level]
|
|
|
|
group_member.save
|
2013-04-04 19:11:51 +00:00
|
|
|
else
|
2014-09-15 07:57:02 +00:00
|
|
|
project_member = current_user.project_members.find(params[:notification_id])
|
|
|
|
project_member.notification_level = params[:notification_level]
|
|
|
|
project_member.save
|
2013-04-04 19:11:51 +00:00
|
|
|
end
|
2015-02-06 23:23:58 +00:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
|
|
|
if @saved
|
|
|
|
flash[:notice] = "Notification settings saved"
|
|
|
|
else
|
|
|
|
flash[:alert] = "Failed to save new settings"
|
|
|
|
end
|
|
|
|
|
2015-10-20 07:28:28 +00:00
|
|
|
redirect_back_or_default(default: profile_notifications_path)
|
2015-02-06 23:23:58 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
format.js
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def user_params
|
|
|
|
params.require(:user).permit(:notification_email, :notification_level)
|
2013-03-27 17:04:29 +00:00
|
|
|
end
|
|
|
|
end
|