@review_comment.review_id = params[:review_id]\r
@review_comment.review_text = ""\r
@rule_failure_permanent_id = params[:rule_failure_permanent_id]\r
+ if params[:update_comment]\r
+ @update_comment = "true"\r
+ @review_comment.review_text = params[:review_text]\r
+ end\r
render :partial => "form_comment"\r
end\r
\r
render "create_comment_result"\r
end\r
\r
+ def update_comment\r
+ review = Review.find params[:review_comment][:review_id]\r
+ @review_comment = review.review_comments.last\r
+ unless current_user && current_user.id == @review_comment.user_id\r
+ render :text => "<b>Cannot modify the comment</b> : access denied."\r
+ return\r
+ end\r
+\r
+ @review_comment.review_text = params[:review_comment][:review_text]\r
+ @review_comment.created_at = DateTime.now\r
+ @rule_failure_permanent_id = params[:rule_failure_permanent_id]\r
+ if @review_comment.valid?\r
+ @review_comment.save\r
+ @reviews = find_reviews_for_rule_failure @rule_failure_permanent_id\r
+ end\r
+ render "update_comment_result"\r
+ end\r
+\r
## -------------- PRIVATE -------------- ##\r
private\r
\r
:id => "commentText" + @review_comment.review_id.to_s,\r
:style => "width:100%" %>\r
<br/>\r
- <%= submit_to_remote 'create_btn', 'Post', \r
- :url => { :action => 'create_comment', :rule_failure_permanent_id => @rule_failure_permanent_id } %>\r
+ <% if @update_comment %>\r
+ <%= submit_to_remote 'create_btn', 'Update', \r
+ :url => { :action => 'update_comment', \r
+ :rule_failure_permanent_id => @rule_failure_permanent_id } %> \r
+ <% else %>\r
+ <%= submit_to_remote 'create_btn', 'Post', \r
+ :url => { :action => 'create_comment', \r
+ :rule_failure_permanent_id => @rule_failure_permanent_id } %>\r
+ <% end %>\r
<%= submit_to_remote 'cancel_btn', 'Cancel', \r
:url => { :action => 'list', :rule_failure_permanent_id => @rule_failure_permanent_id.to_s },\r
:update => { :success => "reviewFailure" + @rule_failure_permanent_id.to_s } %>\r
-<%\r
- last_comment_user_id = -1\r
-%>\r
<div id="review<%= review.id -%>">\r
<div>\r
<b>Review #<%= review.id -%> - <%= h(review.title) -%></b>\r
</div>\r
\r
<div style="margin-top: 10px; margin-left: 20px">\r
- <% unless review.review_comments.blank? \r
+ <% unless review.review_comments.blank?\r
+ last_comment = review.review_comments.last\r
review.review_comments.each do |review_comment|\r
- last_comment_user_id = review_comment.user_id\r
%>\r
<table style="width:100%; margin-bottom: 3px">\r
<tr style="border: solid 1px grey; background-color: #F7F7F7">\r
</tr>\r
<tr style="border: solid 1px grey;">\r
<td colspan="2" style="padding: 5px;">\r
- <%= h(review_comment.review_text) -%>\r
+ <% if review_comment == last_comment %>\r
+ <div id="lastComment<%= review.id -%>">\r
+ <%= h(review_comment.review_text) -%>\r
+ </div>\r
+ <% else %>\r
+ <%= h(review_comment.review_text) -%>\r
+ <% end %>\r
</td>\r
</tr>\r
</table>\r
\r
<% if current_user %>\r
<div style="text-align: right; padding: 5px">\r
- <% if current_user.id == last_comment_user_id %>\r
+ <% if current_user.id == review.review_comments.last.user_id %>\r
<%= image_tag("pencil.png") -%>\r
<%= link_to_remote "Edit my last comment", \r
- :url => { :controller => "reviews", :action => "form_comment", :review_id => review.id, :rule_failure_permanent_id => review.rule_failure_permanent_id },\r
- :update => "createComment" + review.id.to_s, \r
+ :url => { :controller => "reviews", :action => "form_comment", \r
+ :review_id => review.id, \r
+ :rule_failure_permanent_id => review.rule_failure_permanent_id,\r
+ :review_text => review.review_comments.last.review_text,\r
+ :update_comment => "true" },\r
+ :update => "lastComment" + review.id.to_s, \r
:complete => "$('commentText" + review.id.to_s + "').focus()" -%>\r
\r
<% end %>\r
--- /dev/null
+if @reviews\r
+ page.replace_html "reviewFailure" + @rule_failure_permanent_id.to_s, :partial => "list", :locals => { :reviews => @reviews }\r
+else\r
+ @update_comment = "true"\r
+ page.replace_html "lastComment" + @review_comment.review_id.to_s, :partial => "form_comment"\r
+end
\ No newline at end of file