From 9f013dffb0bac6016739cd87b6ff16f232cb29e3 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Thu, 18 Jul 2013 15:55:39 +0200 Subject: [PATCH] When submitting measures filter modal form, only errors are now returned to the form, not the whole form --- .../app/controllers/measures_controller.rb | 15 +++++++++------ .../app/views/measures/_shared_form.html.erb | 4 +--- .../src/main/webapp/javascripts/application.js | 11 ++++++++++- .../src/main/webapp/stylesheets/style.css | 9 +++++++++ 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb index 76c587377bc..5b0ee79b592 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb @@ -91,7 +91,7 @@ class MeasuresController < ApplicationController current_user.favourited_measure_filters<<@filter if add_to_favourites render :text => @filter.id.to_s, :status => 200 else - render :partial => 'measures/save_as_form', :status => 400 + render_measures_error(@filter) end end @@ -150,7 +150,7 @@ class MeasuresController < ApplicationController render :text => @filter.id.to_s, :status => 200 else - render :partial => 'measures/edit_form', :status => 400 + render_measures_error(@filter) end end @@ -179,10 +179,7 @@ class MeasuresController < ApplicationController current_user.favourited_measure_filters << target render :text => target.id.to_s, :status => 200 else - # keep the id (from source) and errors (from target) in the copy form - target.id= source.id - @filter = target - render :partial => 'measures/copy_form', :status => 400 + render_measures_error(target) end end @@ -239,4 +236,10 @@ class MeasuresController < ApplicationController def criteria_params params.merge({:controller => nil, :action => nil, :search => nil, :widget_id => nil, :edit => nil}) end + + def render_measures_error(filter) + errors = [] + filter.errors.full_messages.each{|msg| errors<'} + render :text => errors, :status => 400 + end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_shared_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_shared_form.html.erb index 6b551d48a38..b670d2655fd 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_shared_form.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_shared_form.html.erb @@ -2,9 +2,7 @@ display_owner = false end %>