aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@gmail.com>2013-01-11 12:33:35 +0100
committerJulien Lancelot <julien.lancelot@gmail.com>2013-01-11 12:33:35 +0100
commit0a320e34591e4cf6cf9f0cdf8f919865092cfc28 (patch)
tree49d14070ee72fd7c6b318a9d98a7b20e2cc0aae7 /sonar-server
parent2c7b0dd0b59d1aba36fac19f1b2d6899cb8c6cc0 (diff)
downloadsonarqube-0a320e34591e4cf6cf9f0cdf8f919865092cfc28.tar.gz
sonarqube-0a320e34591e4cf6cf9f0cdf8f919865092cfc28.zip
SONAR-3992 Replace prototype ajax by jquery ajax on Quality Profile alert page
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/alerts_controller.rb69
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/alerts/_edit.html.erb17
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/alerts/_new.html.erb23
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/alerts/index.html.erb25
4 files changed, 66 insertions, 68 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/alerts_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/alerts_controller.rb
index 457fcd2611e..a2518af4c29 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/alerts_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/alerts_controller.rb
@@ -21,6 +21,7 @@ class AlertsController < ApplicationController
verify :method => :post, :only => ['create', 'update', 'delete'], :redirect_to => { :action => 'index' }
before_filter :admin_required, :except => [ 'index' ]
+ before_filter :load_new_metrics_id, :only => [:index, :create, :update]
SECTION=Navigation::SECTION_CONFIGURATION
@@ -35,13 +36,6 @@ class AlertsController < ApplicationController
@alerts = @profile.alerts.sort
@alert=Alert.new
- @newMetricsId = []
- Metric.domains.collect do |domain|
- Metric.by_domain(domain).select{ |m| m.alertable? }.each do |metric|
- @newMetricsId << metric.id if metric.name.index("new_") == 0
- end
- end
-
add_breadcrumbs ProfilesController::ROOT_BREADCRUMB, Api::Utils.language_name(@profile.language), {:name => @profile.name, :url => {:controller => 'rules_configuration', :action => 'index', :id => @profile.id}}
end
@@ -74,24 +68,15 @@ class AlertsController < ApplicationController
@profile = Profile.find(params[:profile_id])
params[:alert][:period] = nil if params[:alert][:period] == '0'
@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
+
+ if @alert.save
+ flash[:notice] = message('alerts.alert_created')
+ render :text => 'ok', :status => 200
+ else
+ @alerts = @profile.alerts.reload
+ errors = []
+ @alert.errors.full_messages.each{|msg| errors<<msg + '<br/>'}
+ render :text => errors, :status => 404
end
end
@@ -106,20 +91,13 @@ class AlertsController < ApplicationController
@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
+ if alert.update_attributes(params[:alert])
+ flash[:notice] = message('alerts.alert_updated')
+ render :text => 'ok', :status => 200
+ else
+ errors = []
+ alert.errors.full_messages.each{|msg| errors<<msg + '<br/>'}
+ render :text => errors, :status => 404
end
end
@@ -133,10 +111,17 @@ class AlertsController < ApplicationController
@alert = @profile.alerts.find(params[:id])
@alert.destroy
flash[:notice] = message('alerts.alert_deleted')
+ redirect_to(:action => 'index', :id=>@profile.id)
+ end
- respond_to do |format|
- format.html { redirect_to(:action => 'index', :id=>@profile.id) }
- format.xml { head :ok }
+ private
+
+ def load_new_metrics_id
+ @newMetricsId = []
+ Metric.domains.collect do |domain|
+ Metric.by_domain(domain).select{ |m| m.alertable? }.each do |metric|
+ @newMetricsId << metric.id if metric.name.index("new_") == 0
+ end
end
end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/alerts/_edit.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/alerts/_edit.html.erb
index 481bc8e6dda..535b5acae10 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/alerts/_edit.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/alerts/_edit.html.erb
@@ -1,4 +1,4 @@
-<%= form_remote_tag :url => {:action => 'update', :id => alert.id, :profile_id => @profile.id}, :html => {:id => "edit_alert_#{alert.id}"} %>
+<%= form_tag({:action => 'update', :id => alert.id, :profile_id => @profile.id}, :id => "edit_alert_#{alert.id}") %>
<table>
<tr>
<td nowrap>
@@ -30,18 +30,15 @@
</td>
</tr>
</table>
-<% unless alert.errors.empty? %>
-<div class="error" style="margin: 5px;">
- <ul>
- <% alert.errors.full_messages.each do |message| %>
- <li><%= h message %></li>
- <% end %>
- </ul>
-</div>
-<% end %>
+<div id="alert_error_<%= alert.id -%>" class="error" style="margin: 5px;" />
</form>
<script type="text/javascript">
+ $j("#alert_error_<%= alert.id -%>").hide();
+ $j(document).ready(function () {
+ ajaxForm("edit_alert_<%= alert.id -%>", "alert_error_<%= alert.id -%>");
+ });
+
$j('#alert_period_<%= alert.id %>').select2({
allowClear: false,
minimumResultsForSearch: 10,
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/alerts/_new.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/alerts/_new.html.erb
index 0f520124b4c..a1b34dd5ba7 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/alerts/_new.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/alerts/_new.html.erb
@@ -1,5 +1,5 @@
<h3><%= message('alerts.create_alert') -%></h3>
-<%= form_remote_tag :url => {:action => 'create', :profile_id => @profile.id}, :html => {:id => 'new_alert_form'} %>
+<%= form_tag({:action => 'create', :profile_id => @profile.id}, :id => 'new_alert_form') %>
<table class="spaced">
<tr>
<td valign="top">
@@ -47,19 +47,16 @@
</td>
</tr>
</table>
-<% unless @alert.errors.empty? %>
-<div class="error" style="margin: 5px;">
- <ul>
- <% @alert.errors.full_messages.each do |message| %>
- <li><%= h message %></li>
- <% end %>
- </ul>
-</div>
-<% end %>
+<div id="alert_error" class="error" style="margin: 5px;"/>
</form>
<script type="text/javascript">
- //<![CDATA[
+
+ $j("#alert_error").hide();
+ $j(document).ready(function () {
+ ajaxForm("new_alert_form", "alert_error");
+ });
+
$j('#alert_metric_id').select2({
allowClear: false,
width: '250px',
@@ -68,7 +65,7 @@
function htmlDecode(value) {
if (value) {
- return $j('<div />').html(value).text();
+ return $j('<div/>').html(value).text();
} else {
return '';
}
@@ -117,8 +114,6 @@
});
});
-
- //]]>
</script>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/alerts/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/alerts/index.html.erb
index c672968789d..4b5d583475c 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/alerts/index.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/alerts/index.html.erb
@@ -1,7 +1,7 @@
<%= render :partial => 'profiles/tabs', :locals => {:selected_tab=>'Alerts'} %>
<% if is_admin? %>
- <div class="tabs-panel marginbottom10 admin" id="new_alert_form">
+ <div class="tabs-panel marginbottom10 admin" id="new_alert_content">
<%= render :partial => 'new' %>
</div>
<% else %>
@@ -45,4 +45,25 @@
<tr class="even"><td><%= image_tag 'levels/error.png' %></td><td> <%= message('alerts.notes.error') -%></td></tr>
</tbody>
</table>
-</div> \ No newline at end of file
+</div>
+
+<script type="text/javascript">
+ function ajaxForm(formId, errorId){
+ var obj = $j("#"+ formId);
+ obj.submit(function (event) {
+ $j.ajax({
+ type: 'POST',
+ url: obj.attr('action'),
+ data: obj.serialize(),
+ success: function (data) {
+ window.location.reload();
+ },
+ error: function (xhr, textStatus, errorThrown) {
+ $j("#"+ errorId).show();
+ $j("#"+ errorId).html(xhr.responseText);
+ }
+ });
+ return false;
+ });
+ }
+</script> \ No newline at end of file