2013-03-27 13:04:29 -04:00
|
|
|
module NotificationsHelper
|
2015-05-21 17:49:06 -04:00
|
|
|
include IconsHelper
|
|
|
|
|
2013-07-31 10:05:22 -04:00
|
|
|
def notification_icon(notification)
|
|
|
|
if notification.disabled?
|
2015-01-28 03:32:48 -05:00
|
|
|
icon('volume-off', class: 'ns-mute')
|
2013-07-31 10:05:22 -04:00
|
|
|
elsif notification.participating?
|
2015-01-28 03:32:48 -05:00
|
|
|
icon('volume-down', class: 'ns-part')
|
2013-07-31 10:05:22 -04:00
|
|
|
elsif notification.watch?
|
2015-01-28 03:32:48 -05:00
|
|
|
icon('volume-up', class: 'ns-watch')
|
2013-07-31 10:05:22 -04:00
|
|
|
else
|
2015-01-28 03:32:48 -05:00
|
|
|
icon('circle-o', class: 'ns-default')
|
2013-07-31 10:05:22 -04:00
|
|
|
end
|
|
|
|
end
|
2015-09-14 19:37:11 -04:00
|
|
|
|
2015-09-14 21:33:24 -04:00
|
|
|
def notification_list_item(notification_level, user_membership)
|
2015-09-14 19:37:11 -04:00
|
|
|
case notification_level
|
2015-09-14 20:40:45 -04:00
|
|
|
when Notification::N_DISABLED
|
2015-11-14 13:38:05 -05:00
|
|
|
update_notification_link(Notification::N_DISABLED, user_membership, 'Disabled', 'microphone-slash')
|
2015-09-14 20:40:45 -04:00
|
|
|
when Notification::N_PARTICIPATING
|
2015-11-14 13:38:05 -05:00
|
|
|
update_notification_link(Notification::N_PARTICIPATING, user_membership, 'Participate', 'volume-up')
|
2015-09-14 20:40:45 -04:00
|
|
|
when Notification::N_WATCH
|
2015-11-14 13:38:05 -05:00
|
|
|
update_notification_link(Notification::N_WATCH, user_membership, 'Watch', 'eye')
|
2015-09-14 20:40:45 -04:00
|
|
|
when Notification::N_MENTION
|
2015-11-14 13:38:05 -05:00
|
|
|
update_notification_link(Notification::N_MENTION, user_membership, 'On mention', 'at')
|
2015-09-16 20:46:24 -04:00
|
|
|
when Notification::N_GLOBAL
|
2015-11-14 13:38:05 -05:00
|
|
|
update_notification_link(Notification::N_GLOBAL, user_membership, 'Global', 'globe')
|
2015-09-14 20:40:45 -04:00
|
|
|
else
|
|
|
|
# do nothing
|
2015-09-14 19:37:11 -04:00
|
|
|
end
|
|
|
|
end
|
2015-09-14 21:33:24 -04:00
|
|
|
|
2015-11-16 03:53:17 -05:00
|
|
|
def update_notification_link(notification_level, user_membership, title, icon)
|
2015-11-14 13:38:05 -05:00
|
|
|
content_tag(:li, class: active_level_for(user_membership, notification_level)) do
|
2015-11-16 03:53:17 -05:00
|
|
|
link_to '#', class: 'update-notification', data: { notification_level: notification_level } do
|
2015-11-14 13:38:05 -05:00
|
|
|
icon("#{icon} fw", text: title)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-09-16 20:46:24 -04:00
|
|
|
def notification_label(user_membership)
|
|
|
|
Notification.new(user_membership).to_s
|
|
|
|
end
|
|
|
|
|
2015-09-14 21:33:24 -04:00
|
|
|
def active_level_for(user_membership, level)
|
2015-09-20 12:28:14 -04:00
|
|
|
'active' if user_membership.notification_level == level
|
2015-09-14 21:33:24 -04:00
|
|
|
end
|
2013-03-27 13:04:29 -04:00
|
|
|
end
|