1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
module NotificationsHelper
include IconsHelper
def notification_icon(notification)
if notification.disabled?
icon('volume-off', class: 'ns-mute')
elsif notification.participating?
icon('volume-down', class: 'ns-part')
elsif notification.watch?
icon('volume-up', class: 'ns-watch')
else
icon('circle-o', class: 'ns-default')
end
end
def notification_list_item(notification_level, user_membership)
case notification_level
when Notification::N_DISABLED
content_tag(:li, class: active_level_for(user_membership, 'disabled?')) do
link_to '#', class: 'update-notification', data: { notification_level: Notification::N_DISABLED } do
icon('microphone-slash fw', text: 'Disabled')
end
end
when Notification::N_PARTICIPATING
content_tag(:li, class: active_level_for(user_membership, 'participating?')) do
link_to '#', class: 'update-notification', data: { notification_level: Notification::N_PARTICIPATING } do
icon('volume-up fw', text: 'Participating')
end
end
when Notification::N_WATCH
content_tag(:li, class: active_level_for(user_membership, 'watch?')) do
link_to '#', class: 'update-notification', data: { notification_level: Notification::N_WATCH } do
icon('globe fw', text: 'Watch')
end
end
when Notification::N_MENTION
content_tag(:li, class: active_level_for(user_membership, 'mention?')) do
link_to '#', class: 'update-notification', data: { notification_level: Notification::N_MENTION } do
icon('at fw', text: 'Mention')
end
end
else
# do nothing
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
|