From 0a320e34591e4cf6cf9f0cdf8f919865092cfc28 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Fri, 11 Jan 2013 12:33:35 +0100 Subject: [PATCH] SONAR-3992 Replace prototype ajax by jquery ajax on Quality Profile alert page --- .../app/controllers/alerts_controller.rb | 69 ++++++++----------- .../WEB-INF/app/views/alerts/_edit.html.erb | 17 ++--- .../WEB-INF/app/views/alerts/_new.html.erb | 23 +++---- .../WEB-INF/app/views/alerts/index.html.erb | 25 ++++++- 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<'} + 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<'} + 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}") %>
@@ -30,18 +30,15 @@
-<% unless alert.errors.empty? %> -
-
    - <% alert.errors.full_messages.each do |message| %> -
  • <%= h message %>
  • - <% end %> -
-
-<% end %> +
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? %> -
+
<%= render :partial => 'new' %>
<% else %> @@ -45,4 +45,25 @@ <%= image_tag 'levels/error.png' %> <%= message('alerts.notes.error') -%> -
\ No newline at end of file +
+ + \ No newline at end of file -- 2.39.5