{# vim: set ts=2 et sts=2 sw=2: #}
{% extends "wiki/base.html" %}
{% from "layout/errorlist.html" import errorlist %}
{% from "includes/common_macros.html" import content_editor %}
{% set title = _('Translate Article | {document}')|f(document=parent.title) %}
{% block title %}{{ page_title(title) }}{% endblock %}
{% set crumbs = [(url('wiki.category', parent.category), parent.get_category_display()),
                 (parent.get_absolute_url(), parent.title),
                 (None, _('Translate Article'))] %}
{% block bodyclass%}translate{% endblock %}

{% block content %}
  {% set language = settings.LANGUAGES[locale.lower()] %}
<section id="content">
  <div class="wrap">
    <div id="content-main" class="full">
      <form action="" method="post" data-json-url="{{ url('wiki.json') }}">
        {{ csrf() }}
        <input type="hidden" name="form" value="both" />

  <div id="localize-document" class="editing">
    <header id="article-head">
      <div class="title">
        <h1>{{ _('Translating <em>{title}</em>')|fe(title=parent.title) }}</h1>
      </div>
      
      <div class="change-locale">
        {{ _('Translating article to {locale}' )|f(locale=language) }}.
        <a id="change-locale-link" class="toggle" href="#change-locale">{{ _('Change') }}</a>
        <ul id="change-locale" class="sub-menu" data-target="#change-locale-link" data-modal="true" data-close-on-out-click="true">
        {% for lcl in settings.LANGUAGE_CHOICES %}
          {% if lcl[0] not in [settings.WIKI_DEFAULT_LANGUAGE, locale] %}
            <li><a href="{{ url('wiki.translate', document_path=parent.full_path)|urlparams(tolocale=lcl[0]) }}">{{ lcl[1] }} ({{ lcl[0] }})</a></li>
          {% endif %}
        {% endfor %}
        </ul>
      </div>
      
    {% include 'wiki/includes/page_buttons.html' %}
          
    {% if not based_on.reviewed or not based_on.is_approved %}
      <p class="trans-note">{{ _('You are translating an unreviewed or rejected English document.') }}</p>
    {% endif %}
    </header>

    {% if document_form %}
      <details id="trans-description"{% if disclose_description %} open="open"{% endif %}>
        <summary>{{ _('Translate Description') }}</summary>
        {{ errorlist(document_form) }}
            <ul class="description">
              <li>
                <dl class="approved">
                  <dt>{{ _('Title:') }}</dt>
                  <dd>{{ parent.title }}</dd>
                </dl>
                <dl class="localized">
                  <dt><label for="{{ document_form.title.auto_id }}" title="{{ document_form.title.help_text }}">{{ _('Title in {locale}:')|f(locale=language) }}</label></dt>
                  <dd>{{ document_form.title|safe }}</dd>
                </dl>
              </li>
              <li>
                <dl class="approved">
                  <dt>{{ _('Slug:') }}</dt>
                  <dd>{{ specific_slug }}</dd>
                </dl>
                <dl class="localized">
                  <dt><label for="{{ document_form.slug.auto_id }}" title="{{ document_form.slug.help_text }}">{{ _('Slug in {locale}:')|f(locale=language) }}</label></dt>
                  <dd>{{ document_form.slug|safe }}</dd>
                </dl>
              </li>
              {% if parent_slug %}
              <li>
                <dl class="approved">
                  <dt>{{ _('Parent:') }}</dt>
                  <dd>{{ parent_slug }}</dd>
                </dl>
                <dl class="localized">
                  &nbsp;
                </dl>
              </li>
              {% endif %}
              {% if not document.is_template %}
                <li>
                  <dl class="approved">
                    <dt>&nbsp;</dt>
                    <dd>&nbsp;</dd>
                  </dl>
                  <dl class="localized">
                    <dt><label><abbr title="{{_('Generate table of contents')}}">{{_('TOC:')}}</abbr></label></dt>
                    <dd>{{ revision_form.show_toc | safe }}</dd>
                  </dl>
                </li>
                {% endif %}
            </ul>
      </details>
    {% endif %}

    {% if revision_form %}
      <details id="trans-content" open="open">
        <summary>{{ _('Translate Content') }}</summary>
        {{ errorlist(revision_form) }}
        {# TODO: restore keywords and summary when we restore search app
        <ul class="description">
          <li>
            <dl class="approved">
              <dt>{{ _('Keywords:') }}</dt>
              <dd>{{ based_on.keywords }}</dd>
            </dl>
            <dl class="localized">
              <dt><label for="{{ revision_form.keywords.auto_id }}" title="{{ revision_form.keywords.help_text }}">{{ _('Keywords in {locale}:')|f(locale=language) }}</label></dt>
              <dd>{{ revision_form.keywords|safe }}</dd>
            </dl>
          </li>
          <li>
            <dl class="approved">
              <dt>{{ _('Search result summary:') }}</dt>
              <dd>{{ based_on.summary }}</dd>
            </dl>
            <dl class="localized">
              <dt><label for="{{ revision_form.summary.auto_id }}" title="{{ revision_form.summary.help_text }}">{{ _('Search result summary in {locale}:')|f(locale=language) }}</label></dt>
              <dd>{{ revision_form.summary|safe }}</dd>
            </dl>
          </li>
        </ul>
        #}
        {% if document.current_revision and document.current_revision.based_on %}
          {# Diff between the English version the current translation is based on and the current English version. #}
          {% set revision_from = document.current_revision.based_on %}
          {% set revision_to = parent.current_revision %}
          {% include 'wiki/includes/revision_diff.html' %}
          {# TODO: 'change revisions' link and modal selector #}
        {% else %}
          <p class="no-trans">{{ _('Note: There are no approved translations for this article.') }}</p>
        {% endif %}
        
        <div id="content-fields">
          <article class="approved">
            <header>
              <h3>{{ _('Approved {default_locale} version:')|f(default_locale=settings.LANGUAGES[settings.WIKI_DEFAULT_LANGUAGE.lower()]) }}</h3>
            </header>
            <div class="boxed">
              {{ based_on.content|safe }}
            </div>
          </article>
          
          <article class="localized">
            <header>
              <h3>{{ _('{locale} translation:')|f(locale=language) }}</h3>
            </header>
            {{ content_editor(revision_form.content) }}
          </article>
        </div>
        {{ revision_form.hidden_fields()|join|safe }}
        
      </details>
    {% endif %}
    <div id="preview"></div>
  </div>
</form>
    </div>
   </div>
</section>
{% endblock %}

{% block js %}
  <script src="{{ MEDIA_URL }}ckeditor/ckeditor.js"></script>
  <script src="{{ MEDIA_URL }}ckeditor/adapters/jquery.js"></script>
  <script src="{{ MEDIA_URL }}js/wiki_ckeditor_translate.js"></script>
{% endblock %}
