{% extends "tp_base.html" %}
{% load assets baseurl cache cleanhtml i18n locale progressbar search translation_project_tags common_tags %}
{% get_current_language as LANGUAGE_CODE %}

{% block body_id %}tpoverview{% endblock %}

{% block search %}{% render_search %}{% endblock %}

{% block content %}
<div class="module first">
  <div class="hd">
    {% if store %}
    {% cache settings.CACHE_TIMEOUT path_trail store.id %}
    <h2><span><a href="{{ translation_project.pootle_path|l }}">{{ project.code }}</a> / {{ store|trail:"/" }}</span></h2>
    {% endcache %}
    {% else %}
    {% cache settings.CACHE_TIMEOUT path_trail directory.id %}
    <h2><span><a href="{{ translation_project.pootle_path|l }}">{{ project.code }}</a> / {{ directory|trail:"/" }}</span></h2>
    {% endcache %}
    {% endif %}
  </div>
  <div id="path-summary" class="bd">
    <ul>
      {% for summary_item in path_summary %}
      <li>{{ summary_item|safe }}</li>
      {% endfor %}
    </ul>
    {% progressbar stats stats.total.words %}
    <div id="js-path-summary-more" data-loaded="false" data-collapsed="true">
    </div>
  </div>

  {% if table %}
  <div class="hd">
    <h2>{% trans "Files and Subfolders" %}</h2>
  </div>
  <div class="bd">
    <div class="files-subfolders" lang="{{ LANGUAGE_CODE }}">
      {% display_table table %}
    </div>
  </div>
  {% endif %}
</div>

<div class="module">
  {% if action_groups %}
  <div class="hd">
    <h2>{% trans "Actions" %}</h2>
  </div>
  <div id="overview-actions" class="bd">
    {% for action_group in action_groups %}
    <div id="overview-actions-{{ action_group.group }}"
         class="overview-actions-container{% if forloop.first %} first{% endif %}">
      <div class="overview-actions-group">{{ action_group.group_display }}</div>
      <div class="overview-actions-content">
        <ul>
        {% for action in action_group.actions %}
        <li class="{% cycle "odd" "even" %}">
          <a href="{{ action.href }}" title="{{ action.tooltip }}"
          {% if action.class %}class="{{ action.class }}"{% endif %}>
          <i class="{{ action.icon }}"></i> <span>{{ action.text }}</span></a>
        </li>
        {% endfor %}
        </ul>
      </div>
    </div>
    {% endfor %}
  </div>
  {% endif %}

  {% if translation_project.description_html or project.description_html or language.description_html or can_edit %}
  <div class="hd">
    <h2>{% trans "Description" %}</h2>
  </div>

  <div id="overview-description" class="bd">

    <div id="overview-description-tp"
      class="markup-body{% if can_edit %} js-ctx-meta-desc{% endif %}">
    {% if translation_project.description_html %}
      {{ translation_project.description_html|clean }}
    {% else %}
      <p class="placeholder muted">{% trans "No description set." %}</p>
    {% endif %}
    {% if can_edit %}
      {% include "admin/edit_links.html" %}
    {% endif %}
    </div>
  {% if can_edit %}
    <div class="settings-container js-edit-ctx-meta-desc" style="display:none;">
      {% include "admin/general_settings_form.html" with form_action="edit_settings.html" %}
    </div>
  {% endif %}

    {% if project.description_html %}
    <a class="overview-description-toggle js-toggle" href="#overview-description-project">{% blocktrans with project.fullname as project %}{{ project }} project information{% endblocktrans %}</a>
    <div id="overview-description-project" class="markup-body hide">
      {{ project.description_html|clean }}
    </div>
    {% endif %}

    {% if language.description_html %}
    <a class="overview-description-toggle js-toggle" href="#overview-description-language">{% blocktrans with language.name as language %}{{ language }} language information{% endblocktrans %}</a>
    <div id="overview-description-language" class="markup-body hide">
      {{ language.description_html|clean }}
    </div>
    {% endif %}

  </div>
  {% endif %}
</div>

<div class="hide">
{% include "translation_project/fileop_forms.html" %}
</div>
{% endblock content %}

{% block postcontent %}
{% include "top_contributers_table.html" %}
{% endblock postcontent %}

{% block scripts_extra %}
{{ block.super }}
<script type="text/javascript">
$(function() {
  PTL.search.init();

  $("#search-form").submit(function (e) {
    e.preventDefault();

    var s = $(this.search).val();

    if (!s) {
      return false;
    }

    var remember = true,
        hash = "#search=" + PTL.search.parse(s, remember);
    window.location = this.action + hash;

    return false;
  });
{% if upload %}
  $("select#id_upload_to_dir").parent().hide();
  $("input#id_file").change(function() {
    if (/\.zip$/.test($(this).val())) {
      $("select#id_upload_to").parent().hide();
      $("select#id_upload_to_dir").parent().show();
    } else {
      $("select#id_upload_to_dir").parent().hide();
      $("select#id_upload_to").parent().show();
    }
  });
{% endif %}
});
</script>
{% if user.is_superuser or request.permissions.administrate %}
{% assets "js_admin" %}
<script type="text/javascript" src="{{ ASSET_URL }}"></script>
{% endassets %}
{% endif %}
{% endblock %}
