{% extends "tp_base.html" %}
{% load url from future %}
{% load assets baseurl cache cleanhtml i18n locale progressbar search translation_project_tags goal_tags common_tags profile_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">
    <h2>
      {% if goal %}
        {% cache settings.CACHE_TIMEOUT path_with_goal_trail path_obj.id goal.pk %}
        <span><a href="{{ translation_project.pootle_path|l }}">{{ project.code }}</a> / <a href="{{ goal_url }}">{{ goal.name }}</a> / {{ path_obj|goal_trail:goal }}</span>
        {% endcache %}
      {% else %}
        {% cache settings.CACHE_TIMEOUT path_trail path_obj.id %}
        <span><a href="{{ translation_project.pootle_path|l }}">{{ project.code }}</a> / {{ path_obj|trail:"/" }}</span>
        {% endcache %}
      {% endif %}
      <a href="" id="js-toggle-tags" class="hide tags-aside tags-toggle">
        <i class="icon-tag"></i>
        <span id="js-toggle-tags-text">{% trans "Show tags" %}</span>
      </a>
    </h2>
  </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>

  <div class="tags-bd">
    {% if can_edit and add_tag_form %}
    <a href="#js-add-tag-dialog" class="js-add-tag-popup js-tags tags-add">
      <i class="icon-tag-add"></i> {% trans "Add tag" %}
    </a>
    {% endif %}
    <ul class="js-tags tag-list">
      {% block tag_list %}
      {% include "translation_project/xhr_tags_list.html" %}
      {% endblock %}
    </ul>
    <br />
  </div>

  {% if table %}
  <div class="bd">

    <ul id="file-tabs">
      <li>
        <a href="{% url 'pootle-tp-overview' language.code project.code path_obj.path %}"
          {% if table.id = 'tp-files'  %} class="selected-tab"{% endif %}
          title="{% trans 'Translation project files and folders' %}">
          {% trans "Files" %}</a>
      </li>
      {% if path_obj_has_goals %}
      <li>
        <a href="{% url 'pootle-tp-goals' language.code project.code path_obj.path %}"
          {% if table.id = 'tp-goals'  %} class="selected-tab"{% endif %}
          title="{% trans 'Administrate your project goals' %}">
          {% trans "Goals" %}</a>
      </li>
      {% endif %}
    </ul>

    <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 %}
    {% if action_output %}
    <div id="overview-actions-output" class="bd">
      <p>{{ action_output }}</p>
    </div>
    {% endif %}
  </div>
  {% endif %}

  {% if description or project.description or language.description 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 description %}
      {{ description }}
    {% 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" %}
    </div>
  {% endif %}

    {% if project.description %}
    <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 }}
    </div>
    {% endif %}

    {% if language.description %}
    <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 }}
    </div>
    {% endif %}

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

{% if upload_form %}
<div id="upload" class="form popup-inline mfp-hide" lang="{{ LANGUAGE_CODE }}">
  <h2>{% trans "Upload File" %}</h2>
  <form action="" method="post" class="upload" enctype="multipart/form-data">
    {% csrf_token %}
    {{ form.non_field_errors }}
    {% for field in upload_form %}
    <p {% if field.help_text %}title="{{ field.help_text }}"{% endif %}>
      {{ field.label_tag }} {{ field }}
      {{ field.errors }}
    </p>
    {% endfor %}
    <p class="buttons">
      <input type="submit" value="{% trans 'Upload' %}" />
    </p>
  </form>
</div>
{% endif %}

{% if can_edit and add_tag_form %}
<div id="js-add-tag-dialog" class="form popup-inline mfp-hide" lang="{{ LANGUAGE_CODE }}">
  <h2>{% trans "Add tag" %}</h2>
  {% include "common/xhr_add_tag_form.html" %}
</div>
{% endif %}
{% endblock content %}

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

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

  PTL.common.updateRelativeDates();
  setInterval(PTL.common.updateRelativeDates, 6e4);

{% if upload_form %}
  $("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 %}
