class ReviewsController < ApplicationController
- SECTION=Navigation::SECTION_CONFIGURATION
+ SECTION=Navigation::SECTION_RESOURCE
+
+ #verify :method => :post, :only => [ :create, :...... ], :redirect_to => { :action => :index }
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
+ render :partial => "list", :locals => { :reviews => reviews }
end
def form
@review_comment.user = current_user
@review_comment.review = @review
@review_comment.review_text = "Enter your review here"
- render "_form", :layout => false
+ render :partial => "form"
end
def formComment
@review_comment.review_id = params[:review_id]
@review_comment.review_text = ""
@rule_failure_id = params[:rule_failure_id]
- render "_form_comment", :layout => false
+ render :partial => "form_comment"
end
def create
review = Review.new(params[:review])
review.user = current_user
+ # save!
review.save
+ # --> Build?
#review.review_comments.create(params[:review_comment])
review_comment = ReviewComment.new(params[:review_comment])
review_comment.user = current_user
end
def createComment
+ #return access_denied unless has_role?(:user, @project)
+
review_comment = ReviewComment.new(params[:review_comment])
review_comment.user = current_user
review_comment.save
+<%
+ displayReviewFailureDiv = 'block'
+ if violation.reviews.blank?
+ displayReviewFailureDiv = 'none'
+ end
+%>
<div class="violation">
<table>
<tr>
<td width="30px" valign="top">
- <% if current_user %>
- <%= link_to_remote(image_tag("add.png"),
- :update => "reviewFailure" + violation.id.to_s,
- :url => { :controller => "reviews", :action => "form", :violation_id => violation.id }) -%>
+ <% if current_user && violation.reviews.blank? %>
+ <%= link_to_remote image_tag("add.png"),
+ :url => { :controller => "reviews", :action => "form", :violation_id => violation.id },
+ :update => "reviewFailure" + violation.id.to_s,
+ :html => { :id => "createReviewLink" + violation.id.to_s },
+ :complete => "$('reviewFailure" + violation.id.to_s + "').style.display='';$('reviewText').focus();" -%>
<% end %>
</td>
<span class="violation_date"><%= duration==0 ? 'today' : "#{duration} days ago" -%></span>
<% end %>
- <div id="reviewFailure<%= violation.id -%>" style="padding:5px; background:white">
+ <div id="reviewFailure<%= violation.id -%>" style="padding:5px; background:white; display:<%= displayReviewFailureDiv -%>">
<%= render :partial => "reviews/list", :locals => { :reviews => violation.reviews } %>
</div>
</td>
<br/>
Comment:
<br/>
- <%= text_area :review_comment, :review_text, :rows => 10 %>
+ <%= text_area :review_comment, :review_text, :id => "reviewText", :rows => 10 %>
<br/>
- <%= submit_to_remote 'create_btn', 'Create review',
- :url => { :action => 'create' },
- :update => { :success => "reviewFailure" + @review.rule_failure_id.to_s, :failure => "fail" } %>
- <%= submit_to_remote 'cancel_btn', 'Cancel',
- :url => { :action => 'list', :rule_failure_id => @review.rule_failure_id.to_s },
- :update => { :success => "reviewFailure" + @review.rule_failure_id.to_s } %>
+ <input type="button" name="create_btn" value="Create review"
+ onclick="new Ajax.Updater({success:'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';} });">
+ <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';">
<% end %>
\ No newline at end of file
<br/>
Comment:
<br/>
- <%= f.text_area :review_text, :rows => 10 %>
+ <%= f.text_area :review_text, :rows => 10, :id => "commentText" + @review_comment.review_id.to_s %>
<br/>
<%= submit_to_remote 'create_btn', 'Add comment',
:url => { :action => 'createComment', :rule_failure_id => @rule_failure_id },
%>
</div>
- <%= link_to_remote("Add a comment",
+ <%= link_to_remote "Add a comment",
+ :url => { :controller => "reviews", :action => "formComment", :review_id => review.id, :rule_failure_id => review.rule_failure_id },
: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>
+ :complete => "$('commentText" + review.id.to_s + "').focus()" -%>
+
+ <div id="createComment<%= review.id -%>"></div>
+
</div>