{% 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="{{ MEDIA_URL }}js/file_submit.js"></script>
  <script type="text/javascript" src="{{ MEDIA_URL }}js/watch_toggle.js"></script>
  <script type="text/javascript" src="{{ MEDIA_URL }}js/tablesorted.js"></script>
  <script type="text/javascript" src="{{ MEDIA_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 %}

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

  });


  </script>
  <link media="screen" href="{{ MEDIA_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.name }}{% endwith %}{% endblock %}

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


{% block content_main %}
  <div class="obj_bigdetails">
  <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 %}

  {% get_permission "project_perm.maintain" for request.user and component.project as "is_maintainer" %}
  {% 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>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 to the source" %}" 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 to the source" %}" href="{{ component.unit.root }}" target="_blank" >{% trans "web" %}</a>)</sup>{% endifequal %}
        <img class="repotype" src="{{ MEDIA_URL }}images/icons/vcs/{{ component.unit.type }}.png" alt="{{ component.unit.type }}" title="{{ component.unit.type }}" />
    </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>
    {% 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">
        {% for release in releases|slice:"0:6" %}<a class="release" href="{% url collection_release_detail slug=release.collection.slug release_slug=release.slug %}">{{ release }}</a> {% endfor %}
      </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 %}
  {% get_permission "project_perm.submit_file" for request.user and component.project as "can_submit_file" %}
    {% if request.user.is_authenticated and not perms.projects.submit_file and not can_submit_file and not is_maintainer%}
    <tr>
      <th class="i16 user">{% trans "Become a translator:" %}</th>
      <td>
      {% get_permission_request "project_perm.submit_file" for request.user and component.project,component as "can_submit_file_request" %}
      {% if can_submit_file_request %}
         <a href="{% url project_add_permission_request component.project.slug %}">{% trans "Your request is pending for approval." %}<a/>
      {% else %}
          {% txpermission_request_form for component.project using "project_perm.submit_file" %}
      {% endif %}
      </td>
    </tr>    
  {% endif %}
{% endif %} 

</table>

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

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

{% if component.allows_submission %}
 {% get_permission "project_perm.submit_file" for request.user and component.project as "can_submit_file" %}
 {% if perms.projects.submit_file or can_submit_file or is_maintainer %}
   {% include "projects/component_submit_new_file.html" %}
 {% endif %}
{% endif %}

{% endwith %}
</div>

<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.
{% 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 %}

