ref: master
plugins/admin_notifications/controllers/public/admin_notifications_plugin_public_controller.rb
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 |
class AdminNotificationsPluginPublicController < PublicController helper AdminNotificationsPlugin::NotificationHelper include AdminNotificationsPlugin::NotificationHelper def notifications_with_popup @hide_notifications = hide_notifications if params[:previous_path] @previous_path = params[:previous_path] else @previous_path = nil end end def close_notification result = false if logged_in? @notification = AdminNotificationsPlugin::Notification.find_by_id(params[:notification_id]) if @notification @notification.users << current_user result = @notification.users.include?(current_user) end end render json: result end def hide_notification result = false if logged_in? @notification = AdminNotificationsPlugin::Notification.find_by_id(params[:notification_id]) if @notification current_notificaions = [] current_notificaions = JSON.parse(cookies[:hide_notifications]) unless cookies[:hide_notifications].blank? current_notificaions << @notification.id unless current_notificaions.include? @notification.id cookies[:hide_notifications] = JSON.generate(current_notificaions) result = current_notificaions.include? @notification.id end end render json: result end end |