{% extends "reviews/reviewable_base.html" %}
{% load i18n %}
{% load djblets_deco %}
{% load djblets_utils %}
{% load reviewtags %}

{% block title %}{{review_request_details.summary}} | {% trans "Review Request" %}{% endblock %}

{% block jsconsts %}
{{block.super}}
{%  include "reviews/review_flags.js" %}
{% endblock %}

{% block css %}
<link rel="stylesheet" type="text/css" href="{{MEDIA_URL}}rb/css/diffviewer.css?{{MEDIA_SERIAL}}" />
<link rel="stylesheet" type="text/css" href="{{MEDIA_URL}}rb/css/reviews.css?{{MEDIA_SERIAL}}" />
<link rel="stylesheet" type="text/css" href="{{MEDIA_URL}}rb/css/syntax.css?{{MEDIA_SERIAL}}" />
{% if siteconfig.settings.diffviewer_show_trailing_whitespace|default_if_none:1 %}
<style type="text/css">
  .ew { background: #ee3434; }
</style>
{% endif %}
{% endblock %}

{% block scripts-post %}
<script type="text/javascript" src="{{MEDIA_URL}}rb/js/reviews.js?{{MEDIA_SERIAL}}"></script>
<script type="text/javascript" src="{{MEDIA_URL}}rb/js/jquery.form.js?{{MEDIA_SERIAL}}"></script>
{% endblock %}

{% block content %}
{% include "reviews/trophy_box.html" %}
{% include "reviews/review_header.html" %}

{% box "review-request" %}

<ul class="actions">
{% include "reviews/review_request_actions_secondary.html" %}
{% if has_diffs %}
 <li class="primary"><a href="diff/raw/">{% trans "Download Diff" %}</a></li>
{% endif %}
{% include "reviews/review_request_actions_primary.html" %}
{% if has_diffs %}
 <li class="primary"><a href="diff/#index_header">{% trans "View Diff" %}</a></li>
{% endif %}
</ul>

<div class="main">
{% include "reviews/review_request_box.html" %}

<ul class="controls">
{% if entries %}
 <li>
  <a href="#" id="expand-all"><img width="14" height="14" border="0" alt="" src="{{MEDIA_URL}}rb/images/expand.png?{{MEDIA_SERIAL}}"> {% trans "Expand All" %}</a>
 </li>
{% endif %}
</ul>

</div>
{% endbox %}



{% for entry in entries %}
{%  if entry.review %}
<a name="review{{entry.review.id}}"></a>
<div id="review{{entry.review.id}}">
{%   if forloop.last %}
<a name="last-review"></a>
{%   endif %}
{% definevar "boxclass" %}review {{entry.class}}{% enddefinevar %}
{% box boxclass %}
<div class="main">
 <div class="banners"></div>
 <div class="header">
  {% if entry.review.ship_it %}<div class="shipit">{% trans "Ship it!" %}</div>{% endif %}
  <div class="collapse-button"></div>
  <div class="reviewer"><a href="{% url user entry.review.user %}" class="user">{{entry.review.user|user_displayname}}</a></div>
  <div class="posted_time">{% blocktrans with entry.review.timestamp as timestamp and entry.review.timestamp|date:"c" as timestamp_raw %}Posted <time class="timesince" datetime="{{timestamp_raw}}">{{timestamp}}</time> ({{timestamp}}){% endblocktrans %}</div>
 </div>
 <div class="body">
   <pre class="body_top reviewtext">{{entry.review.body_top|escape}}</pre>
   {% reply_section entry "" "body_top" "rcbt" %}
{% if entry.diff_comments or entry.screenshot_comments or entry.file_attachment_comments %}
   <dl class="diff-comments">

{% for comment in entry.screenshot_comments %}
    <dt>
     <a name="scomment{{comment.id}}"></a>
     <div class="screenshot">
      <span class="filename">
       <a href="{{comment.screenshot.get_absolute_url}}">{% spaceless %}
{% if draft and comment.screenshot.draft_caption %}
{{comment.screenshot.draft_caption}}
{% else %}
{{comment.screenshot.caption|default_if_none:comment.screenshot.image.name|basename}}
{% endif %}
{% endspaceless %}</a>
      </span>
      {{comment.image|safe}}
     </div>
    </dt>
    <dd>
     <pre>{{comment.text|escape}}</pre>
{% if comment.issue_opened %}
     <div id="comment-{{comment.id}}-issue" class="issue-indicator">
       {% comment_issue review_request_details comment "screenshot_comments" %}
     </div>
{% endif %}
     {% reply_section entry comment "screenshot_comments" "rc" %}
    </dd>
{% endfor %}

{% for comment in entry.file_attachment_comments %}
    <dt>
     <a name="fcomment{{comment.id}}"></a>
     <div class="file-attachment">
      <a href="{{comment.file_attachment.get_absolute_url}}">{% spaceless %}
       <img src="{{comment.file_attachment.icon_url}}" />
        <span class="filename">{{comment.file_attachment.filename}}</span>
	  </a>
{% if draft and comment.file_attachment.draft_caption %}
      <p class="caption">{{comment.file_attachment.draft_caption}}</p>
{% else %}
{%  if comment.file_attachment.caption %}
      <p class="caption">{{comment.file_attachment.caption}}</p>
{%  endif %}
{% endif %}
{% endspaceless %}</a>
      </span>
     </div>
    </dt>
    <dd>
     <pre>{{comment.text|escape}}</pre>
{% if comment.issue_opened %}
     <div id="comment-{{comment.id}}-issue" class="issue-indicator">
       {% comment_issue review_request_details comment "file_attachment_comments" %}
     </div>
{% endif %}
     {% reply_section entry comment "file_attachment_comments" "rc" %}
    </dd>
{% endfor %}

{% for comment in entry.diff_comments %}
    <dt>
     <a name="comment{{comment.id}}"></a>
     <div id="comment_container_{{comment.id}}">
      <table class="sidebyside loading">
       <thead>
        <tr>
         <th class="filename">
          <a name="{{comment.get_absolute_url}}">{{comment.filediff.dest_file_display}}</a>
          <span class="diffrevision">
{% if comment.interfilediff %}
           (Diff revisions {{comment.filediff.diffset.revision}} - {{comment.interfilediff.diffset.revision}})
{% else %}
           (Diff revision {{comment.filediff.diffset.revision}})
{% endif %}
          </span>
         </th>
        </tr>
       </thead>
       <tbody>
        <tr><td><pre>&nbsp;</pre></td></tr>{# header entry #}
{% for i in comment.num_lines|default_if_none:1|range %}
        <tr><td><pre>&nbsp;</pre></td></tr>
{% endfor %}
       </tbody>
      </table>
     </div>
    </dt>
    <dd>
     <pre class="reviewtext">{{comment.text|escape}}</pre>
{% if comment.issue_opened %}
     <div id="comment-{{comment.id}}-issue" class="issue-indicator">
       {% comment_issue review_request_details comment "diff_comments" %}
     </div>
{% endif %}
     {% reply_section entry comment "diff_comments" "rc" %}
    </dd>
    <script type="text/javascript">
      $(document).ready(function() {
        queueLoadDiffFragment("diff_fragments", "{{comment.id}}",
{% if comment.interfilediff %}
          "{{comment.filediff.id}}-{{comment.interfilediff.id}}"
{% else %}
          "{{comment.filediff.id}}"
{% endif %}
        );
      });
    </script>
{% endfor %}
   </dl>
{% endif %}
  {% if entry.review.body_bottom %}
   <pre class="body_bottom reviewtext">{{entry.review.body_bottom|escape}}</pre>
   {% reply_section entry "" "body_bottom" "rcbb" %}
  {% endif %}
 </div><!-- body -->
</div><!-- main -->
{%   endbox %}
</div><!-- review{{entry.review.id}} -->
{%  endif %}
{%  if entry.changedesc %}
<a name="changedesc{{entry.changedesc.id}}"></a>
{% definevar "boxclass" %}changedesc {{entry.class}}{% enddefinevar %}
{% box boxclass %}
<div class="main">
 <div class="header">
   <div class="collapse-button"></div>
   <div class="reviewer"><b>{% trans "Review request changed" %}</b></div>
   <div class="posted_time">{% blocktrans with entry.changedesc.timestamp as timestamp and entry.changedesc.timestamp|date:"c" as timestamp_raw %}Updated <time class="timesince" datetime="{{timestamp_raw}}">{{timestamp}}</time> ({{timestamp}}){% endblocktrans %}</div>
 </div>
 <div class="body">
  <ul>
{% for fieldinfo in entry.changeinfo %}
   <li><label>{{fieldinfo.title}}</label>
{%  ifequal fieldinfo.type "changed" %}
{%   if fieldinfo.multiline %}
	  <p><label>{% trans "Changed from:" %}</label></p>
      <pre>{{fieldinfo.info.old.0}}</pre>
	  <p><label>{% trans "Changed to:" %}</label></p>
	  <pre>{{fieldinfo.info.new.0}}</pre>
{%   else %}
{%    blocktrans with fieldinfo.info.old.0 as old_value and fieldinfo.info.new.0 as new_value %}changed from <i>{{old_value}}</i> to <i>{{new_value}}</i>{% endblocktrans %}
{%   endif %}
{%  endifequal %}
{%  ifequal fieldinfo.type "add_remove" %}
    <ul>
{%   if fieldinfo.info.removed %}
{% definevar "removed_values" %}
{% for item in fieldinfo.info.removed %}{% if item.1 %}<a href="{{item.1}}">{{item.0}}</a>{% else %}{{item.0}}{% endif %}{% if not forloop.last %}, {% endif %}{% endfor %}
{% enddefinevar %}
<li>{% blocktrans %}removed {{removed_values}}{% endblocktrans %}</li>
{%   endif %}
{%   if fieldinfo.info.added %}
{% definevar "added_values" %}
{% for item in fieldinfo.info.added %}{% if item.1 %}<a href="{{item.1}}">{{item.0}}</a>{% else %}{{item.0}}{% endif %}{% if not forloop.last %}, {% endif %}{% endfor %}
{% enddefinevar %}
<li>{% blocktrans %}added {{added_values}}{% endblocktrans %}</li>
{%   endif %}
    </ul>
{%  endifequal %}
{%  ifequal fieldinfo.type "screenshot_captions" %}
    <ul>
{%   for info in fieldinfo.info.values %}
     <li>{% blocktrans with info.old.0 as old_value and info.new.0 as new_value %}changed from <i>{{old_value}}</i> to <i>{{new_value}}</i>{% endblocktrans %}</li>
{%   endfor %}
    </ul>
{%  endifequal %}
   </li>
{% endfor %}
  </ul>
{% if entry.changedesc.text %}
  <label>{% trans "Description:" %}</label>
  <pre class="changedesc-text">{{entry.changedesc.text|escape}}</pre>
{% endif %}
 </div>
</div>
{%   endbox %}
{%  endif %}
{% endfor %}

<script type="text/javascript">
  $(document).ready(function() {
	  /* Listen for updates to this review request. */
	  registerForUpdates("{{last_activity_time|date:"Y-m-d H:i:s"}}");

{% if request.GET.reply_id and request.GET.reply_type %}
      $.funcQueue("diff_comments").add(function() {
          var link = $("#add_{{request.GET.reply_type}}_{{request.GET.reply_id}}");
          $(window).scrollTop(link.offset().top);
          link.click();
          $.funcQueue("diff_comments").next();
      });
{% endif %}
  });
</script>

{% endblock %}
