def index
end
+ def list
+ reviews = Review.find :all, :conditions => ['rule_failure_id=?', params[:rule_failure_id]]
+ render :partial => "list", :locals => { :reviews => reviews }, :layout => false
+ end
+
def form
@review = Review.new
@review.rule_failure_id = params[:violation_id]
render "_form", :layout => false
end
+ def formComment
+ @review_comment = ReviewComment.new
+ @review_comment.user = current_user
+ @review_comment.review_id = params[:review_id]
+ @review_comment.review_text = ""
+ @rule_failure_id = params[:rule_failure_id]
+ render "_form_comment", :layout => false
+ end
+
def create
review = Review.new(params[:review])
review.user = current_user
review.save
+ #review.review_comments.create(params[:review_comment])
review_comment = ReviewComment.new(params[:review_comment])
review_comment.user = current_user
review_comment.review_id = review.id
review_comment.save
- render "create", :layout => false
+
+ params[:rule_failure_id] = review.rule_failure_id
+ list
end
- def cancel_create
- render :nothing => true
+ def createComment
+ review_comment = ReviewComment.new(params[:review_comment])
+ review_comment.user = current_user
+ review_comment.save
+
+ list
end
end
<td width="30px" valign="top">
<% if current_user %>
<%= link_to_remote(image_tag("add.png"),
- :update => "review" + violation.id.to_s ,
+ :update => "reviewFailure" + violation.id.to_s,
:url => { :controller => "reviews", :action => "form", :violation_id => violation.id }) -%>
<% end %>
</td>
%>
<span class="violation_date"><%= duration==0 ? 'today' : "#{duration} days ago" -%></span>
<% end %>
-
- <div id="review<%= violation.id -%>" style="padding:5px; background:white">
- <% unless violation.reviews.blank?
- violation.reviews.each do |review|
- %>
- <%= render :partial => "reviews/view", :locals => { :review => review } %>
- <%
- end
- end
- %>
+
+ <div id="reviewFailure<%= violation.id -%>" style="padding:5px; background:white">
+ <%= render :partial => "reviews/list", :locals => { :reviews => violation.reviews } %>
</div>
</td>
-<% form_for :review, @review, :url => { :action => 'create', :id => @review.id } do |f| %>
+<h3>Create a new review</h3>
+<% form_for :review, @review do |f| %>
<%= f.hidden_field :rule_failure_id %>
Review by: <%= @review.user.login -%>
<br/>
<%= text_area :review_comment, :review_text, :rows => 10 %>
<br/>
<%= submit_to_remote 'create_btn', 'Create review',
- :url => { :action => 'create', :id => @review.id },
- :update => { :success => "review" + @review.rule_failure_id.to_s, :failure => "fail" } %>
+ :url => { :action => 'create' },
+ :update => { :success => "reviewFailure" + @review.rule_failure_id.to_s, :failure => "fail" } %>
<%= submit_to_remote 'cancel_btn', 'Cancel',
- :url => { :action => 'cancel_create' },
- :update => { :success => "review" + @review.rule_failure_id.to_s } %>
+ :url => { :action => 'list', :rule_failure_id => @review.rule_failure_id.to_s },
+ :update => { :success => "reviewFailure" + @review.rule_failure_id.to_s } %>
<% end %>
\ No newline at end of file
--- /dev/null
+<% form_for :review_comment, @review_comment do |f| %>
+ <%= f.hidden_field :review_id %>
+ Review by: <%= :user -%>
+ <br/>
+ Comment:
+ <br/>
+ <%= f.text_area :review_text, :rows => 10 %>
+ <br/>
+ <%= submit_to_remote 'create_btn', 'Add comment',
+ :url => { :action => 'createComment', :rule_failure_id => @rule_failure_id },
+ :update => { :success => "reviewFailure" + @rule_failure_id.to_s, :failure => "fail" } %>
+ <%= submit_to_remote 'cancel_btn', 'Cancel',
+ :url => { :action => 'list', :rule_failure_id => @rule_failure_id.to_s },
+ :update => { :success => "reviewFailure" + @rule_failure_id.to_s } %>
+<% end %>
\ No newline at end of file
--- /dev/null
+<%
+ unless reviews.blank?
+ reviews.each do |review|
+%>
+
+ <%= render :partial => "reviews/view", :locals => { :review => review } %>
+
+<%
+ end
+ end
+%>
\ No newline at end of file
-<div>
+ <div id="review<%= review.id -%>" style="border:solid 1px black; margin:2px">
User name: <%= h(review.user.name) -%>
<br/>
Status: <%= h(review.status) -%>
External Link: <%= h(review.external_link) -%>
<br/>
- <% unless review.review_comments.blank?
- review.review_comments.each do |review_comment|
- %>
+ <div>
+ <% unless review.review_comments.blank?
+ review.review_comments.each do |review_comment|
+ %>
+ <div id="commentReview" style="border:solid 1px grey; margin:2px">
<%= l review_comment.created_at -%>, by <%= h(review_comment.user.name) -%>
ยป
<%= h(review_comment.review_text) -%>
<br/>
- <%
- end
+ </div>
+ <%
end
- %>
-</div>
\ No newline at end of file
+ end
+ %>
+ </div>
+
+ <%= link_to_remote("Add a comment",
+ :update => "createComment" + review.id.to_s,
+ :url => { :controller => "reviews", :action => "formComment", :review_id => review.id, :rule_failure_id => review.rule_failure_id }) -%>
+ <div id="createComment<%= review.id -%>">
+
+ </div>
+ </div>