Commit 01cc2037 authored by Patricio Cano's avatar Patricio Cano

Notification dropdown now shows currently active level, and also shows what...

Notification dropdown now shows currently active level, and also shows what the actual value of `global` is, if the project has the notification level set to global.
parent 8a6fb46d
...@@ -29,4 +29,6 @@ class @Project ...@@ -29,4 +29,6 @@ class @Project
e.preventDefault() e.preventDefault()
level = $(this).data('notification-level') level = $(this).data('notification-level')
$('#notification_level').val(level) $('#notification_level').val(level)
$('#notification-form').submit() $('#notification-form').submit()
\ No newline at end of file $(this).parents('ul').find('li.active').removeClass('active')
$(this).parent().addClass('active')
\ No newline at end of file
...@@ -82,7 +82,9 @@ class ProjectsController < ApplicationController ...@@ -82,7 +82,9 @@ class ProjectsController < ApplicationController
if @project.empty_repo? if @project.empty_repo?
render 'projects/empty' render 'projects/empty'
else else
@membership_id = @project.project_members.where(user_id: current_user.id).first.id unless current_user.nil?
@membership = @project.project_members.where(user_id: current_user.id).first
end
render :show render :show
end end
else else
......
...@@ -13,28 +13,28 @@ module NotificationsHelper ...@@ -13,28 +13,28 @@ module NotificationsHelper
end end
end end
def notification_list_item(notification_level) def notification_list_item(notification_level, user_membership)
case notification_level case notification_level
when Notification::N_DISABLED when Notification::N_DISABLED
content_tag(:li) do content_tag(:li, class: active_level_for(user_membership, 'disabled?')) do
link_to '#', class: 'update-notification', data: { notification_level: Notification::N_DISABLED } do link_to '#', class: 'update-notification', data: { notification_level: Notification::N_DISABLED } do
icon('microphone-slash fw', text: 'Disabled') icon('microphone-slash fw', text: 'Disabled')
end end
end end
when Notification::N_PARTICIPATING when Notification::N_PARTICIPATING
content_tag(:li) do content_tag(:li, class: active_level_for(user_membership, 'participating?')) do
link_to '#', class: 'update-notification', data: { notification_level: Notification::N_PARTICIPATING } do link_to '#', class: 'update-notification', data: { notification_level: Notification::N_PARTICIPATING } do
icon('volume-up fw', text: 'Participating') icon('volume-up fw', text: 'Participating')
end end
end end
when Notification::N_WATCH when Notification::N_WATCH
content_tag(:li) do content_tag(:li, class: active_level_for(user_membership, 'watch?')) do
link_to '#', class: 'update-notification', data: { notification_level: Notification::N_WATCH } do link_to '#', class: 'update-notification', data: { notification_level: Notification::N_WATCH } do
icon('globe fw', text: 'Watch') icon('globe fw', text: 'Watch')
end end
end end
when Notification::N_MENTION when Notification::N_MENTION
content_tag(:li) do content_tag(:li, class: active_level_for(user_membership, 'mention?')) do
link_to '#', class: 'update-notification', data: { notification_level: Notification::N_MENTION } do link_to '#', class: 'update-notification', data: { notification_level: Notification::N_MENTION } do
icon('at fw', text: 'Mention') icon('at fw', text: 'Mention')
end end
...@@ -43,4 +43,13 @@ module NotificationsHelper ...@@ -43,4 +43,13 @@ module NotificationsHelper
# do nothing # do nothing
end end
end end
def active_level_for(user_membership, level)
value = Notification.new(user_membership)
if value.global?
return 'active' if current_user.notification.send(level)
elsif value.send(level)
return 'active'
end
end
end end
- if current_user and !@membership_id.nil? - if current_user and !@membership.nil?
= form_tag profile_notifications_path, method: :put, remote: true, class: 'inline-form', id: 'notification-form' do = form_tag profile_notifications_path, method: :put, remote: true, class: 'inline-form', id: 'notification-form' do
= hidden_field_tag :notification_type, 'project' = hidden_field_tag :notification_type, 'project'
= hidden_field_tag :notification_id, @membership_id = hidden_field_tag :notification_id, @membership.id
= hidden_field_tag :notification_level = hidden_field_tag :notification_level
%span.dropdown %span.dropdown
%a.dropdown-toggle.btn.btn-new{href: '#', "data-toggle" => "dropdown"} %a.dropdown-toggle.btn.btn-new{href: '#', "data-toggle" => "dropdown"}
...@@ -9,4 +9,4 @@ ...@@ -9,4 +9,4 @@
Notifications Notifications
%ul.dropdown-menu.dropdown-menu-right.project-home-dropdown %ul.dropdown-menu.dropdown-menu-right.project-home-dropdown
- Notification.notification_levels.each do |level| - Notification.notification_levels.each do |level|
= notification_list_item(level) = notification_list_item(level, @membership)
\ No newline at end of file \ No newline at end of file
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