]> source.dussan.org Git - sonarqube.git/commitdiff
[SONAR-1973] Update correctly the "Add" button visibility
authorFabrice Bellingard <bellingard@gmail.com>
Fri, 8 Apr 2011 09:25:43 +0000 (11:25 +0200)
committerFabrice Bellingard <bellingard@gmail.com>
Wed, 20 Apr 2011 06:49:57 +0000 (08:49 +0200)
sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_form.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/reviews/create_result.js.rjs [new file with mode: 0644]

index 91e0a489f6d35e8250cf373a4bc02ffe8552c4e0..4be1371cf002560bfde2453003aab19cfef015f7 100644 (file)
@@ -54,22 +54,19 @@ class ReviewsController < ApplicationController
            return
          end
                  
-         review = Review.new(params[:review])
-         review.user = current_user
-         review.status = "open"
-         review.review_type = "simple"
-         review_comment = ReviewComment.new(params[:review_comment])
-         review_comment.user = current_user
-         review.review_comments << review_comment
-         if review.valid?
-           review.save
-           params[:rule_failure_id] = review.rule_failure_id
-               index
-         else 
-           @review = review
-           @review_comment = review_comment
-           render :partial => "form"
+         @review = Review.new(params[:review])
+         @review.user = current_user
+         @review.status = "open"
+         @review.review_type = "simple"
+         @review_comment = ReviewComment.new(params[:review_comment])
+         @review_comment.user = current_user
+         @review.review_comments << @review_comment
+         if @review.valid?
+           @review.save
+                #@reviews = Review.find :all, :conditions => ['rule_failure_id=?', @review.rule_failure_id]
+                @reviews = findReviewsForRuleFailure @review.rule_failure_id
          end
+         render "create_result"
        end
        
        def create_comment
@@ -93,6 +90,10 @@ class ReviewsController < ApplicationController
        
        private
        
+       def findReviewsForRuleFailure ( rule_failure_id )
+         return Review.find :all, :conditions => ['rule_failure_id=?', rule_failure_id]
+       end
+       
        def hasRightsToCreate? ( rule_failure_id )
          return false unless current_user
          
index ffd94f09f46e0b43f5f7753bc85f9ef3db38639e..49f229d95231e6dbb8d309dbdaa9cd5a3681ff0a 100644 (file)
@@ -10,8 +10,8 @@
       <br/>
       <%= text_area :review_comment, :review_text, :id => "reviewText", :rows => 10 %>
       <br/>
-      <input type="button" name="create_btn" value="Create review" 
-             onclick="new Ajax.Updater({success:'reviewFailure<%= @review.rule_failure_id.to_s -%>', failure:'reviewFailure<%= @review.rule_failure_id.to_s -%>'}, '<%= ApplicationController.root_context -%>/reviews/create?rule_failure_id=<%= @review.rule_failure_id.to_s -%>', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this.form), onSuccess:function(request){$('createReviewLink<%= @review.rule_failure_id.to_s -%>').style.display='none';} });">
+      
+      <%= submit_to_remote "create_btn", "Create review", :url => { :action => 'create' } %>
       <input type="button" name="cancel_btn" value="Cancel" 
              onclick="new Ajax.Updater({success:'reviewFailure<%= @review.rule_failure_id.to_s -%>'}, '<%= ApplicationController.root_context -%>/reviews/list?rule_failure_id=<%= @review.rule_failure_id.to_s -%>', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this.form), }); $('reviewFailure<%= @review.rule_failure_id.to_s -%>').style.display='none';">
 
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/create_result.js.rjs b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/create_result.js.rjs
new file mode 100644 (file)
index 0000000..bdf2006
--- /dev/null
@@ -0,0 +1,6 @@
+if @reviews
+  page.hide "createReviewLink" + @review.rule_failure_id.to_s
+  page.replace_html "reviewFailure" + @review.rule_failure_id.to_s, :partial => "index", :locals => { :reviews => @reviews }
+else
+  page.replace_html "reviewFailure" + @review.rule_failure_id.to_s, :partial => "form"
+end
\ No newline at end of file