{% extends "projects/project_detail_childs.html" %}
{% load statistics %}
{% load markup %}
{% load i18n %}
{% load truncate %}
{% load permissions %}
{% load txpermissions %}

{% block extra_head %}
  <script type="text/javascript" src="{{ STATIC_URL }}js/file_submit.js"></script>
  <script type="text/javascript" src="{{ STATIC_URL }}js/watch_toggle.js"></script>
  <script type="text/javascript" src="{{ STATIC_URL }}js/tablesorted.js"></script>
  <script type="text/javascript" src="{{ STATIC_URL }}js/jquery.qtip-1.0.0-rc2.min.js"></script>

  <script type="text/javascript">
  var calcstats = {{ component.should_calculate|lower }};

  $(function(){

      // Toogle to source files list
      $("#source-troggle").click(function () {
           $("#source-stats").slideToggle("slow");
      });


    // Tooltip for submission note
    {% if component.allows_submission %}
        {% ifequal component.submission_type 'email' %}
            {% ifequal component.unit.type 'tar' %}
                    submission_note='{% trans "This component supports local storing of submitted files and also sends the files to the maintainers\' email." %}'
            {% else %}
                    submission_note='{% trans "This component does not support local storing of submitted files. The submitted files will be sent to the maintainers\' emails and the statistics will reflect the change once the files are committed upstream." %}'
            {% endifequal %}
        {% endifequal %}
        {% ifequal component.submission_type 'ssh' %}
                submission_note='{% trans "This component supports local storing of submitted files and also sends the files direct to the upstream repository." %}'
        {% endifequal %}

        tooltip('#note', submission_note);

    {% endif %}
  });
  </script>
  {% include "translations/stats_table_filter_header.html" %}
  <link media="screen" href="{{ STATIC_URL }}css/tablesorter.css" type="text/css" rel="stylesheet" />
  <style type="text/css">
    form.submit_form { display: none; }
    form.submit_form fieldset { border: 2px dotted #ddd; }
  </style>
{% endblock %}

{% block body_class %}{{ block.super }} project_detail{% endblock %}

{% block title %}{% with component.project as project %}{{ block.super }} | Component '{{ component.name }}'{% endwith %}{% endblock %}

{% block breadcrumb %}{% with component.project as project %}{{ block.super }}
&raquo; Component '{{ component.name }}'{% endwith %}{% endblock %}

{% block content_main %}
  {% get_permission "project_perm.maintain" for request.user and component.project as "is_maintainer" %}

  <div class="obj_bigdetails">
  {% if component.project.private %}
  <span id="private_project_banner" class="ui-corner-all">
    {% trans "Private Project"%}
    <img style="vertical-align:top" src="{{ STATIC_URL }}images/icons/lock.png" title="Private Project">
  </span>
  {% endif %}
  <h2 class="name">{{ component.project.name }} &raquo; {{ component.name }}</h2>

  {% if component.description %}<p class="description">{{ component.description }}</p>{% endif %}

  {% with component.long_description_html as long_desc %}
  {% if long_desc %}
  <div class="long_description">
    {{ long_desc|truncatewords_html:"100"|safe }}
  </div>
  {% endif %}
  {% endwith %}

  {% if perms.projects.add_component or is_maintainer %}
    <div class="editlinks"><p><a class="i16 edit buttonized" href="{% url component_edit project_slug=component.project.slug component_slug=component.slug %}">{% trans "Edit" %}</a></p></div>
  {% endif %}

{% if component.unit %}
<div id="vcs_details">
  <h3>{% trans "Source details" %}</h3>

  <table class="definition">
    <tr>
      <th class="repository i16">{% trans "Repository:" %}</th>
      <td>
        <code>{{ component.unit.root|truncate_chars_middle:"70" }}</code>
        {% if component.unit.web_frontend %}<sup>(<a title="{% trans "Link to a web front-end for the source code" %}" href="{{ component.unit.web_frontend }}" target="_blank" >{% trans "web" %}</a>)</sup>{% endif %}
        {# FIXME: tar too restrictive #}
        {% ifequal component.unit.type "tar" %}<sup>(<a title="{% trans "Link to a web front-end for the source code" %}" href="{{ component.unit.root }}" target="_blank" >{% trans "web" %}</a>)</sup>{% endifequal %}
        <img class="repotype" src="{{ STATIC_URL }}images/icons/vcs/{{ component.unit.type }}.png" alt="{{ component.unit.type }}" title="{{ component.unit.type }}" />
      </td>
    </tr>
    {% if component.unit.branch %}
    <tr>
      <th class="branch i16">{% trans "Branch:" %}</th>
      <td>{{ component.unit.branch }}</td>
    </tr>
    {% endif %}
    <tr>
      <th class="i16 filter">{% trans "File filter:" %}</th>
      <td>{{ component.file_filter }}</td>
    </tr>
    <tr>
      <th class="i16 structure">{% trans "i18n method:" %}</th>
      <td>{{ component.i18n_type|lower|capfirst }}</td>
    </tr>
    {% with component.releases.all as releases %}
    {% if releases %}
    <tr>
      <th class="i16 release">{% blocktrans count releases|length as counter %}Release:{% plural %}Releases:{% endblocktrans %}</th>
      <td class="compact">
        <ul class="simple links">{% for release in releases %}<li><a class="release" href="{% url release_detail project_slug=release.project.slug release_slug=release.slug %}">{{ release.full_name }}</a></li> {% endfor %}</ul>
      </td>
    </tr>
    {% endif %}
    {% endwith %}
    <tr>
      <th class="i16 allow_file">{% trans "Allows submissions:" %}</th>
      <td>
        {% if component.allows_submission %}
            <span class="i16 tick_circle"></span>
            <sup><span id="note" class="note buttonized_simple" >{% trans "Note" %}</span></sup>
        {% else %}
            <span class="i16 stop"></span>
        {% endif %}
      </td>
    </tr>
  </table>
</div>
{% endif %}

<h3>{% trans "Translation files" %}</h3>

<table class="definition">
  {% if component.trans.get_source_stats %}
	<tr>
	  <th class="source_code i16">{% trans "Source file:" %}</th>
	  <td>
          {% render_source_files component.trans.get_source_stats %}
	  </td>
	</tr>
  {% endif %}
    <tr>
      <th class="i16 cache">{% trans "Statistics last updated:" %}</th>
      <td>
        {% if component.unit.last_checkout %}<strong>{{component.unit.last_checkout|timesince}}</strong> {% trans "ago" %}.
        {% else %}{% trans "Component not yet pulled from source repository." %}{% endif %}
        {% if perms.projects.refresh_stats or is_maintainer %}
        <form action="{% url component_set_stats component.project.slug component.slug %}" class="microform">
            <input title="{% trans "Refresh and re-calculate statistics. This action may take some time." %}" class="i16 stats_edit" value="{% trans "Refresh cache" %}" type="submit">
        </form>
        {% endif %}
        {% if perms.projects.clear_cache or is_maintainer %}
        <form action="{% url component_clear_cache component.project.slug component.slug %}" class="microform">
            <input title="{% trans "Reset Transifex's local data for a clean pull" %}" class="i16 cache_empty" value="{% trans "Clear cache" %}" type="submit">
        </form>
        {# FIXME: tar too restrictive #}
        {% ifequal component.unit.type "tar" %}<sup><span class="warning" title="{% trans "Any locally modified data will be overwritten with fresh copies." %}">{% trans "warning" %}</span></sup>{% endifequal %}
        {% endif %}
      </td>
    </tr>

{% if component.allows_submission %}
    <tr>
      <th class="i16 team">{% trans "Teams:" %}</th>
      <td>
         <a href="{% url team_list component.project.slug %}">{% trans "See the translation teams." %}</a>
      </td>
    </tr>
{% endif %}

</table>

{% include "translations/stats_table_filter_box.html" %}

{% with component.trans.get_stats as stats %} 
{% comp_stats_table stats %}

{% if request.user.is_authenticated and component.allows_submission %}
 {% get_permission "project_perm.submit_file" for request.user and component.project,1 as "can_submit_file" %}
    {% if component.unit.last_checkout %}
      {% if perms.reviews.add_poreviewrequest or can_submit_file %}
        {% include "projects/component_submit_new_file.html" %}
      {% endif %}
    {% endif %}
{% endif %}

{% endwith %}
</div>

<h3>{% trans 'Translation files reviews' %}</h3>
<p class="i16 tip compact clear">
  {% blocktrans %}Translators can request a file review from another person, who
  can take a look at his work and provide any feedback needed, or simply submit
  the file to the upstream project.{% endblocktrans %}
</p>
{% url review_list  component.project.slug component.slug as review_url %}
<a class="i16 reviews buttonized" title="{% trans "Reviews" %}" href="{{ review_url }}">View all reviews</a>

<h3>{% trans 'History' %}</h3>
{% load tx_action_log %}
{% get_log 5 as action_log for_object component %}
{% if not action_log %}
<p>{% trans 'None available' %}</p>
{% else %}
<ul class="actionlist simple">
{% for entry in action_log %}
    <li class="i16 actionlog">
    {{ entry.message|safe }} by {{ entry.user }} {{ entry.action_time|timesince }} ago.
    </li>
{% endfor %}
</ul>
{% endif %}

{% endblock %}

{% block content_footer %}
  <div id="content_footer_center">
    {% get_permission "project_perm.maintain" for request.user and component.project as "is_maintainer" %}
    {% if perms.projects.delete_component or is_maintainer %}
    <div class="deletelink">
      <a class="i16 delete buttonized" href="{% url component_delete project_slug=component.project.slug component_slug=component.slug %}">{% trans "Delete component" %}</a>
    </div>
    {% endif %}
  </div>
{% endblock %}

