{# vim: set ts=2 et sts=2 sw=2: #}
{% extends "wiki/base.html" %}
{% from "wiki/includes/sidebar_modules.html" import document_tabs %}
{% set title = _('Review Translation {id} | {document}')|f(document=document.parent.title, id=revision.id) %}
{% block title %}{{ page_title(title) }}{% endblock %}
{% set crumbs = [(url('wiki.category', document.category), document.get_category_display()),
                 (document.get_absolute_url(), document.title), (None, 'Review Translation')] %}
{% set classes = 'review' %}

{% block content %}
  <article id="review-revision" class="main">
    <h1>{{ _('Review Translation of {title}')|f(title=document.parent.title) }}</h1>
    <p>{{ _('Reviewing Translation {id} in {language} by {user}')|f(id=revision.id, user=revision.creator, language=settings.LANGUAGES[document.locale.lower()]) }}.
    <a href="{{ url('wiki.document_revisions', document.slug) }}">{{ _('Back to History') }}</a></p>

    {% if revision.reviewed %}
      <p>
        {{ _('This translation was already reviewed by {user} on {date}.')|fe(user=revision.reviewer, date=datetimeformat(revision.reviewed, format='longdatetime')) }}
      </p>
    {% elif document.current_revision %}
      {# If there is a parent revision to diff, and this translation is not already based on it. #}
      {% if parent_revision and document.current_revision.based_on and
            document.current_revision.based_on != parent_revision %}
        <details class="h2" open="open">
          <summary>{{ _('Recent English Changes') }}</summary>
          {# Default locale diff #}
          {% with revision_from=document.current_revision.based_on, revision_to=parent_revision %}
            {% include 'wiki/includes/revision_diff.html' %}
            {# TODO: 'change revisions' link and modal selector #}
          {% endwith %}
        </details>
      {% endif %}
      <details class="h2" open="open">
        <summary>{{ _('Submitted Translation Changes') }}</summary>
        {# Current locale diff #}
        {% with revision_from = document.current_revision, revision_to = revision, revision_from_header = _('Current public translation:'), revision_to_header = _('Submitted translation:') %}
          {% include 'wiki/includes/revision_diff.html' %}
        {% endwith %}
      </details>
      <details class="h2"{% if not parent_revision %} open="open"{% endif %}>
        <summary>{{ _('Full Article Sources') }}</summary>
        {% if not parent_revision %}
          <div class="warning-box">
            {{ _('The {default_locale} version has no approved content to show.')|f(default_locale=settings.LANGUAGES[settings.WIKI_DEFAULT_LANGUAGE.lower()]) }}
          </div>
        {% else %}
          {# Default vs. current locale #}
          <div id="content-fields" class="revision-diff">
            <div class="approved">
              <h3>{{ _('Approved {default_locale} version:')|f(default_locale=settings.LANGUAGES[settings.WIKI_DEFAULT_LANGUAGE.lower()]) }}</h3>
              <p>{{ _('Revision {id} by {user} on {date}')|fe(id=parent_revision.id, user=parent_revision.creator, date=datetimeformat(parent_revision.created, format='longdatetime')) }}</p>
            </div>
            <div class="localized">
              <h3>{{ _('Submitted {locale} translation:')|f(locale=settings.LANGUAGES[document.locale.lower()]) }}</h3>
              <p>{{ _('Revision {id} by {user} on {date}')|fe(id=revision.id, user=revision.creator, date=datetimeformat(revision.created, format='longdatetime')) }}</p>
            </div>
            <h4>{{ ('Keywords:') }}</h4>
            <div class="approved">
              <p>{{ parent_revision.keywords }}</p>
            </div>
            <div class="localized">
              <p>{{ revision.keywords }}</p>
            </div>
            <h4>{{ ('Search results summary:') }}</h4>
            <div class="approved">
              <p>{{ parent_revision.summary }}</p>
            </div>
            <div class="localized">
              <p>{{ revision.summary }}</p>
            </div>
            <h4>{{ ('Content:') }}</h4>
            <div class="approved">
              <textarea readonly="readonly">{{ parent_revision.content }}</textarea>
            </div>
            <div class="localized">
              <textarea readonly="readonly">{{ revision.content }}</textarea>
            </div>
          </div>
        {% endif %}
      </details>
      <details class="h2">
        <summary>{{ _('Revision Content') }}</summary>
        <div id="doc-content">
          {{ revision.content_parsed|safe }}
        </div>
      </details>
    {% else %}
      <p>{{ _('This document does not have a current translation.') }}</p>
      <h3>{{ _('Translation keywords:') }}</h3>
      <div id="revision-keywords">
        {{ revision.keywords }}
      </div>
      <h3>{{ _('Translation search results summary:') }}</h3>
      <div id="revision-summary">
        {{ revision.summary }}
      </div>
      <h3>{{ _('Translation source:') }}</h3>
      <div id="revision-content">
        <pre>{{ revision.content }}</pre>
      </div>
      <h3>{{ _('Translation rendered html:') }}</h3>
      <div id="revision-html">
        <div id="doc-content">
          {{ revision.content_parsed|safe }}
        </div>
      </div>
    {% endif %}

    {% include 'wiki/includes/review_form.html' %}
  </article>
{% endblock %}

{% block side_top %}
  {{ document_tabs(document, document.parent, user, '', settings) }}
{% endblock %}

{% block side %}
  {% include 'wiki/includes/support_for_selectors.html' %}
{% endblock %}
