Commit 26631f99 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Change how notification settings in profile are rendered and updated

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 729fe42b
......@@ -18,8 +18,11 @@ class @Profile
$(this).find('.btn-save').enable()
$(this).find('.loading-gif').hide()
$('.update-notifications').on 'ajax:complete', ->
$(this).find('.btn-save').enable()
$('.update-notifications').on 'ajax:success', (e, data) ->
if data.saved
new Flash("Notification settings saved", "notice")
else
new Flash("Failed to save new settings", "alert")
@bindEvents()
......
class Groups::NotificationSettingsController < Groups::ApplicationController
def update
notification_setting = group.notification_settings.where(user_id: current_user).find(params[:id])
saved = notification_setting.update_attributes(notification_setting_params)
render json: { saved: saved }
end
private
def notification_setting_params
params.require(:notification_setting).permit(:level)
end
end
......@@ -6,19 +6,7 @@ class Profiles::NotificationsController < Profiles::ApplicationController
end
def update
type = params[:notification_type]
@saved = if type == 'global'
current_user.update_attributes(user_params)
else
notification_setting = current_user.notification_settings.find(params[:notification_id])
notification_setting.level = params[:notification_level]
notification_setting.save
end
respond_to do |format|
format.html do
if @saved
if current_user.update_attributes(user_params)
flash[:notice] = "Notification settings saved"
else
flash[:alert] = "Failed to save new settings"
......@@ -27,10 +15,6 @@ class Profiles::NotificationsController < Profiles::ApplicationController
redirect_back_or_default(default: profile_notifications_path)
end
format.js
end
end
def user_params
params.require(:user).permit(:notification_email, :notification_level)
end
......
......@@ -6,12 +6,8 @@
= notification_icon(setting.level)
%span.str-truncated
- if setting.source.kind_of? Project
= link_to_project(setting.source)
- else
= link_to setting.source.name, group_path(setting.source)
= link_to group.name, group_path(group)
.pull-right
= form_tag profile_notifications_path, method: :put, remote: true, class: 'update-notifications' do
= hidden_field_tag :notification_id, setting.id
= hidden_field_tag :notification_level, setting.level
= select_tag :notification_level, options_for_select(User.notification_levels.keys, setting.level), class: 'form-control trigger-submit'
= form_for [group, setting], remote: true, html: { class: 'update-notifications' } do |f|
= f.select :level, NotificationSetting.levels.keys, {}, class: 'form-control trigger-submit'
%li.notification-list-item
%span.notification.fa.fa-holder.append-right-5
- if setting.global?
= notification_icon(current_user.notification_level)
- else
= notification_icon(setting.level)
%span.str-truncated
= link_to_project(project)
.pull-right
= form_for [project.namespace.becomes(Namespace), project, setting], remote: true, html: { class: 'update-notifications' } do |f|
= f.select :level, NotificationSetting.levels.keys, {}, class: 'form-control trigger-submit'
- page_title "Notifications"
- header_title page_title, profile_notifications_path
= form_for @user, url: profile_notifications_path, method: :put, html: { class: 'update-notifications prepend-top-default' } do |f|
-if @user.errors.any?
%div
- if @user.errors.any?
%div.alert.alert-danger
%ul
- @user.errors.full_messages.each do |msg|
......@@ -20,6 +20,8 @@
.col-lg-9
%h5
Global notification settings
= form_for @user, url: profile_notifications_path, method: :put, html: { class: 'update-notifications prepend-top-default' } do |f|
.form-group
= f.label :notification_email, class: "label-light"
= f.select :notification_email, @user.all_emails, { include_blank: false }, class: "select2"
......@@ -61,7 +63,7 @@
%div
%ul.bordered-list
- @group_notifications.each do |setting|
= render 'settings', setting: setting
= render 'group_settings', setting: setting, group: setting.source
%h5
Projects (#{@project_notifications.count})
%p.account-well
......@@ -69,4 +71,4 @@
.append-bottom-default
%ul.bordered-list
- @project_notifications.each do |setting|
= render 'settings', setting: setting
= render 'project_settings', setting: setting, project: setting.source
- if @saved
:plain
new Flash("Notification settings saved", "notice")
- else
:plain
new Flash("Failed to save new settings", "alert")
......@@ -406,6 +406,7 @@ Rails.application.routes.draw do
resource :avatar, only: [:destroy]
resources :milestones, constraints: { id: /[^\/]+/ }, only: [:index, :show, :update, :new, :create]
resources :notification_settings, only: [:update]
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment