diff options
author | Julien Lancelot <julien.lancelot@gmail.com> | 2013-07-18 15:55:39 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@gmail.com> | 2013-07-18 15:55:49 +0200 |
commit | 9f013dffb0bac6016739cd87b6ff16f232cb29e3 (patch) | |
tree | 811e91e873b377da56d9d8137f3c28d69a8e7705 | |
parent | dc77b1b701761faa3884d970f56a028e15f4c97f (diff) | |
download | sonarqube-9f013dffb0bac6016739cd87b6ff16f232cb29e3.tar.gz sonarqube-9f013dffb0bac6016739cd87b6ff16f232cb29e3.zip |
When submitting measures filter modal form, only errors are now returned to the form, not the whole form
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<<msg + '<br/>'} + 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 %> <div class="modal-body"> - <% @filter.errors.full_messages.each do |msg| %> - <p class="error"><%= h msg -%></p> - <% end %> + <div class="modal-error"/> <div class="modal-field"> <label for="name"><%= h message('name') -%> <em class="mandatory">*</em></label> <input id="name" name="name" type="text" size="50" maxlength="100" value="<%= h @filter.name -%>" autofocus="autofocus"/> diff --git a/sonar-server/src/main/webapp/javascripts/application.js b/sonar-server/src/main/webapp/javascripts/application.js index ca1345c981e..5e8d4764b1e 100644 --- a/sonar-server/src/main/webapp/javascripts/application.js +++ b/sonar-server/src/main/webapp/javascripts/application.js @@ -311,7 +311,16 @@ function openModalWindow(url, options) { window.location.reload(); }, error: function (xhr, textStatus, errorThrown) { - $j("#modal").html(xhr.responseText); + // If the modal window has defined a modal-error element, then returned text must be displayed in it + var errorElt = obj.find(".modal-error"); + if (errorElt.length) { + $j('input[type=submit]', obj).removeAttr('disabled'); + errorElt.show(); + errorElt.html(xhr.responseText); + // otherwise replace modal window by the returned text + } else { + $j("#modal").html(xhr.responseText); + } } }, ajax_options)); return false; diff --git a/sonar-server/src/main/webapp/stylesheets/style.css b/sonar-server/src/main/webapp/stylesheets/style.css index afe528792a2..754769fb276 100644 --- a/sonar-server/src/main/webapp/stylesheets/style.css +++ b/sonar-server/src/main/webapp/stylesheets/style.css @@ -2354,6 +2354,15 @@ ul.modal-head-metadata li { color: #777; } +.modal-error { + border: 1px solid red; + background-color: #FF5252; + color: #eee; + margin: 0 0 4px; + padding: 4px; + display: none; +} + input[type=text], input[type=password] { height: 18px; padding: 0 3px; |