Commit 19c2ceb6005378bfa87b13a278b0ac483e69bd6f
1 parent
fc719411
Exists in
community_notifications
Notification manager
Showing
1 changed file
with
64 additions
and
0 deletions
Show diff stats
plugins/environment_notification/lib/notification_manager.rb
0 → 100644
@@ -0,0 +1,64 @@ | @@ -0,0 +1,64 @@ | ||
1 | +module NotificationManager | ||
2 | + | ||
3 | + def index | ||
4 | + @notifications = target.environment_notifications.order('updated_at DESC') | ||
5 | + end | ||
6 | + | ||
7 | + def new | ||
8 | + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.new | ||
9 | + if request.post? | ||
10 | + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.new(params[:notifications]) | ||
11 | + @notification.message = @notification.message.html_safe | ||
12 | + @notification.target = target | ||
13 | + if @notification.save | ||
14 | + session[:notice] = _("Notification successfully created") | ||
15 | + redirect_to :action => :index | ||
16 | + else | ||
17 | + session[:notice] = _("Notification couldn't be created") | ||
18 | + end | ||
19 | + end | ||
20 | + end | ||
21 | + | ||
22 | + def destroy | ||
23 | + if request.delete? | ||
24 | + notification = target.environment_notifications.find_by_id(params[:id]) | ||
25 | + if notification && notification.destroy | ||
26 | + session[:notice] = _('The notification was deleted.') | ||
27 | + else | ||
28 | + session[:notice] = _('Could not remove the notification') | ||
29 | + end | ||
30 | + end | ||
31 | + redirect_to :action => :index | ||
32 | + end | ||
33 | + | ||
34 | + def edit | ||
35 | + @notification = target.environment_notifications.find_by_id(params[:id]) | ||
36 | + if request.post? | ||
37 | + if @notification.update_attributes(params[:notifications]) | ||
38 | + session[:notice] = _('The notification was edited.') | ||
39 | + else | ||
40 | + session[:notice] = _('Could not edit the notification.') | ||
41 | + end | ||
42 | + redirect_to :action => :index | ||
43 | + end | ||
44 | + end | ||
45 | + | ||
46 | + def change_status | ||
47 | + @notification = target.environment_notifications.find_by_id(params[:id]) | ||
48 | + | ||
49 | + @notification.active = !@notification.active | ||
50 | + | ||
51 | + if @notification.save! | ||
52 | + session[:notice] = _('The status of the notification was changed.') | ||
53 | + else | ||
54 | + session[:notice] = _('Could not change the status of the notification.') | ||
55 | + end | ||
56 | + | ||
57 | + redirect_to :action => :index | ||
58 | + end | ||
59 | + | ||
60 | + protected | ||
61 | + def admin_required | ||
62 | + redirect_to :root unless current_user.person.is_admin? | ||
63 | + end | ||
64 | +end |