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
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
<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';">
--- /dev/null
+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