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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
#
# Sonar, open source software quality management tool.
# Copyright (C) 2008-2012 SonarSource
# mailto:contact AT sonarsource DOT com
#
# Sonar is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
#
# Sonar is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with Sonar; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
#
class AlertsController < ApplicationController
verify :method => :post, :only => ['create', 'update', 'delete'], :redirect_to => { :action => 'index' }
before_filter :admin_required, :except => [ 'index' ]
#
#
# GET /alerts/index/<profile_id>
#
#
def index
require_parameters :id
@profile = Profile.find(params[:id])
@alerts = @profile.alerts.sort
@alert=Alert.new
add_breadcrumbs ProfilesController::ROOT_BREADCRUMB, Api::Utils.language_name(@profile.language), @profile.name
end
#
#
# GET /alerts/show/<alert id>
#
#
def show
@alert = @profile.alerts.find(params[:id])
end
#
#
# GET /alerts/new?profile_id=<profile id>
#
#
def new
@profile = Profile.find(params[:profile_id])
@alert = @profile.alerts.build(params[:alert])
respond_to do |format|
format.js {
render :update do |page|
page.replace_html :new_alert_form, :partial => 'new'
end
}
format.html # new.html.erb
format.xml { render :xml => @alert }
end
end
#
#
# GET /alerts/edit/<alert id>
#
#
def edit
@alert = @profile.alerts.find(params[:id])
end
#
#
# POST /alerts/create?profile_id=<profile id>&...
#
#
def create
@profile = Profile.find(params[:profile_id])
@alert = @profile.alerts.build(params[:alert])
respond_to do |format|
if @alert.save
flash[:notice] = message('alerts.alert_created')
format.html { redirect_to :action => 'index', :id=>@profile.id }
format.js { render :update do |page|
page.redirect_to :action => 'index', :id=>@profile.id
end}
else
@alerts = @profile.alerts.reload
format.html { render :action => "index" }
format.xml { render :xml => @alert.errors, :status => :unprocessable_entity }
format.js { render :update do |page|
page.replace_html( 'new_alert_form', :partial => 'new')
end}
end
end
end
#
#
# POST /alerts/update/<alert id>?profile_id=<profile id>
#
#
def update
@profile = Profile.find(params[:profile_id])
@alerts=@profile.alerts
alert = @alerts.find(params[:id])
respond_to do |format|
if alert.update_attributes(params[:alert])
flash[:notice] = message('alerts.alert_updated')
format.html { redirect_to :action => 'index', :id=>@profile.id }
format.xml { head :ok }
format.js { render :update do |page| page.redirect_to :action => 'index', :id=>@profile.id end}
else
@alert=Alert.new
format.html { render :action => "index" }
format.xml { render :xml => @alert.errors, :status => :unprocessable_entity }
format.js { render :update do |page|
page.replace_html( "row_alert_#{alert.id}", :partial => 'edit', :locals => {:alert => alert})
end}
end
end
end
#
#
# POST /alerts/delete/<alert id>?profile_id=<profile id>
#
#
def delete
@profile = Profile.find(params[:profile_id])
@alert = @profile.alerts.find(params[:id])
@alert.destroy
flash[:notice] = message('alerts.alert_deleted')
respond_to do |format|
format.html { redirect_to(:action => 'index', :id=>@profile.id) }
format.xml { head :ok }
end
end
end
|