]> source.dussan.org Git - sonarqube.git/commitdiff
When submitting measures filter modal form, only errors are now returned to the form...
authorJulien Lancelot <julien.lancelot@gmail.com>
Thu, 18 Jul 2013 13:55:39 +0000 (15:55 +0200)
committerJulien Lancelot <julien.lancelot@gmail.com>
Thu, 18 Jul 2013 13:55:49 +0000 (15:55 +0200)
sonar-server/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/views/measures/_shared_form.html.erb
sonar-server/src/main/webapp/javascripts/application.js
sonar-server/src/main/webapp/stylesheets/style.css

index 76c587377bc58aab86278441f9e83cbac842b402..5b0ee79b592f6943364d269bc9c70e6e7ce5b768 100644 (file)
@@ -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
index 6b551d48a3849fbcc3e7db31a5ee0af53f9d0567..b670d2655fdb7a38b39b4b30cd7ed5055fc72df9 100644 (file)
@@ -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"/>
index ca1345c981e0e378d52e4ce42da0db4aa0b8a466..5e8d4764b1ee3f8542b91fe1f16ab81cc4334567 100644 (file)
@@ -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;
index afe528792a273a93a9ff82f0068bd2057b812e41..754769fb2764694f2f287a36665bb593409c0445 100644 (file)
@@ -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;