From c9e264eb2b42f89a13502a4b7721b4577f5c2634 Mon Sep 17 00:00:00 2001 From: Fabrice Bellingard Date: Fri, 8 Apr 2011 11:45:27 +0200 Subject: [PATCH] [SONAR-1973] Displays the comment in right DIV after a validation fails --- .../app/controllers/reviews_controller.rb | 22 ++++++++----------- .../app/views/reviews/_form_comment.html.erb | 3 +-- .../reviews/create_comment_result.js.rjs | 5 +++++ 3 files changed, 15 insertions(+), 15 deletions(-) create mode 100644 sonar-server/src/main/webapp/WEB-INF/app/views/reviews/create_comment_result.js.rjs diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb index 4be1371cf00..c1ee0a44cdf 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb @@ -25,7 +25,7 @@ class ReviewsController < ApplicationController verify :method => :post, :only => [ :create, :create_comment ], :redirect_to => { :action => :error_not_post } def index - reviews = Review.find :all, :conditions => ['rule_failure_id=?', params[:rule_failure_id]] + reviews = findReviewsForRuleFailure params[:rule_failure_id] render :partial => "index", :locals => { :reviews => reviews } end @@ -63,8 +63,7 @@ class ReviewsController < ApplicationController @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 + @reviews = findReviewsForRuleFailure @review.rule_failure_id end render "create_result" end @@ -75,17 +74,14 @@ class ReviewsController < ApplicationController return end - review_comment = ReviewComment.new(params[:review_comment]) - review_comment.user = current_user - if review_comment.valid? - review_comment.save - index - else - @review_comment = review_comment - @rule_failure_id = params[:rule_failure_id] - # TODO Find a way to update the right DIV... - render :partial => "form_comment" + @review_comment = ReviewComment.new(params[:review_comment]) + @review_comment.user = current_user + @rule_failure_id = params[:rule_failure_id] + if @review_comment.valid? + @review_comment.save + @reviews = findReviewsForRuleFailure @rule_failure_id end + render "create_comment_result" end private diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_form_comment.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_form_comment.html.erb index f9056660f9a..6bf3b47b6eb 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_form_comment.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_form_comment.html.erb @@ -7,8 +7,7 @@ <%= f.text_area :review_text, :rows => 10, :id => "commentText" + @review_comment.review_id.to_s %>
<%= submit_to_remote 'create_btn', 'Add comment', - :url => { :action => 'create_comment', :rule_failure_id => @rule_failure_id }, - :update => { :success => "reviewFailure" + @rule_failure_id.to_s } %> + :url => { :action => 'create_comment', :rule_failure_id => @rule_failure_id } %> <%= submit_to_remote 'cancel_btn', 'Cancel', :url => { :action => 'index', :rule_failure_id => @rule_failure_id.to_s }, :update => { :success => "reviewFailure" + @rule_failure_id.to_s } %> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/create_comment_result.js.rjs b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/create_comment_result.js.rjs new file mode 100644 index 00000000000..ba5a4d8fb53 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/create_comment_result.js.rjs @@ -0,0 +1,5 @@ +if @reviews + page.replace_html "reviewFailure" + @rule_failure_id.to_s, :partial => "index", :locals => { :reviews => @reviews } +else + page.replace_html "createComment" + @review_comment.review_id.to_s, :partial => "form_comment" +end \ No newline at end of file -- 2.39.5