<%
# Code Review plugin for Redmine
# Copyright (C) 2009-2012  Haruyuki Iida
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
-%>

<div class="code_review">

</div>

<div id="review-form-frame">
  <div id="review-form">

  </div>
</div>

<div id="code-review-assign-form" />

<div id="code-review-assign-link" style="text-align: right;">
  <%
  change_id = ''
  change_id = @change.id if @change
  assignments = @change.code_review_assignments if @change
  attachment_id = @attachment.id if @attachment
  assignments = @attachment.code_review_assignments if @attachment
  escaped_path = @path.gsub("'"){"\\'"} if @path
  -%>

  <%= raw show_assignments assignments, @project, {:action_type => @action_type, :rev => @rev, :rev_to => @rev_to, :path => @path, :change_id => change_id, :attachment_id => attachment_id} -%>
</div>

<script type="text/javascript">
  repository_id = "<%= @repository_id %>";
  add_form_title = "<%= l(:label_add_review) %>";
  review_dialog_title = "<%= l(:code_review) %>";
  var addReviewUrl = '<%= url_for :controller => 'code_review', :action => 'new', :id => @project %>';
  var is_readonly = true;
  <% if authorize_for('code_review', 'new') -%>
    is_readonly = false;
  <% end %>
  var is_diff = false;
  <% if @action_type == 'diff' or (@attachment and @attachment.is_diff?) -%>
    is_diff = true;
  <% end %>
  action_type = '<%= @action_type %>';
  rev = '<%= @rev %>';
  rev_to = '<%= @rev_to %>';
  path = '<%= escaped_path -%>';

  setAddReviewButton(addReviewUrl, '<%= @change.id if @change %>', '<%= image_tag('edit.png', :alt => l(:label_add_review), :title => l(:label_add_review)) %>', is_readonly, is_diff, '<%= @attachment_id%>' );

  showReviewUrl = '<%= url_for :controller => 'code_review', :action => 'show', :id=>@project %>';
  showReviewImageTag = '<%= image_tag('review.png', :plugin => 'redmine_code_review', :alt => l(:label_show_review), :title => l(:label_show_review)) %>';
  showClosedReviewImageTag = '<%= image_tag('closed_review.png', :plugin => 'redmine_code_review', :alt => l(:label_show_review), :title => l(:label_show_review)) %>';

  <% for review in @reviews do %>
    setShowReviewButton(<%= review.line %>, <%= review.id %>, <%= review.is_closed? %>, <%= review.file_count %> );
  <% end %>

  <% if @show_review_id -%>
    popupReview(<%= @show_review_id %>);
  <% end -%>
  $('#content table.filecontent:first').before($('#code-review-assign-link'));
</script>
