{% extends "projects/project_menu.html" %}
{% load i18n %}
{% load pagination_tags %}
{% load txcommontags %}
{% load permissions %}
{% load txpermissions %}

{% block extra_head %}
<script type="text/javascript">
  $(function(){
    $("form.submit_form").hide();
   })

</script>
{% endblock %}

{% block title %}{{ block.super }} | {{ project.name }} | {% trans "Translation Teams" %}{% endblock %}

{% block breadcrumb %}{{ block.super }} &raquo; <a href="{{ project.get_absolute_url }}">{{ project.name }}</a> &raquo; {% trans "Teams" %}{% endblock %}

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

<div class="obj_bigdetails">

<h2 class="name">{% trans "Translation Teams" %}</h2>

{% if perms.projects.change_team or is_maintainer %}
<div class="addteam editlinks">
    <a class="i16 buttonized add" href="{% url team_create project.slug %}">{% trans "Add a new team" %}</a>
</div>
{% endif %}

<div class="project_create generic_form">


{% with project.teamrequest_set.all|dictsort:"language.name" as teamrequests %}
{% if teamrequests %}
{% autopaginate teamrequests 20 %}
<div class="list">
<h4>{% trans "List of team requests:" %}</h4>
<ul>
{% for teamrequest in teamrequests %}
    <li class="i16 team_request">
        <span class="name notice">{{ teamrequest.language.name }}</span> 
        <span class="details">- Requester: <a href="{% url profile_public teamrequest.user.username %}">{{ teamrequest.user.username }}</a></span>
        
        {% if is_maintainer %}
        <form class="microform" method="post" action="{% url team_request_approve teamrequest.project.slug teamrequest.language.code %}">
            <input class="i16 submit" type="submit" value="{% trans "Approve" %}"/>
        </form>
        
        <form class="microform" method="post" action="{% url team_request_deny teamrequest.project.slug teamrequest.language.code %}">
            <input class="i16 delete" type="submit" value="{% trans "Deny" %}"/>
        </form>
        {% endif %}

    </li>
{% endfor %}
</ul>
<div class="pagination bottom">{% paginate %}</div>
</div>
{% endif %}
{% endwith %}


{% with project.team_set.all|dictsort:"language.name" as teams %}
{% if teams %}
{% autopaginate teams 20 %}
<div class="list">
<h4>{% trans "List of available teams:" %}</h4>
<ul>
{% for team in teams %}
    <li class="i16 team">
        <a class="name" href="{% url team_detail team.project.slug team.language.code %}">{{ team.language.name }}</a> 
          <span class="details">- {% blocktrans count team.coordinators.all|length as counter %}Coordinator:{% plural %}Coordinators:{% endblocktrans %} 
            {% for c in team.coordinators.all %}
              <a href="{% url profile_public c.username %}">{{c}}</a> {% if not forloop.last %},{% endif %}
            {% endfor %}
          </span>
    </li>
{% endfor %}
</ul>
<div class="pagination bottom">{% paginate %}</div>
</div>
{% else %}
<p>{% trans "No translation team created yet. :(" %}</p>
{% endif %}

{% if team_request_form %}
{% if request.user.is_authenticated and not is_maintainer %}
<span class="i16 add submit_button buttonized" title="{% trans "Request a new translation team for this project" %}">{% trans "Request a new team" %}</span>
<form method="post" enctype="multipart/form-data" action="{% url team_request project.slug %}" class="add-permission microform submit_form">
  <fieldset style="margin-top: 1em;">
   <legend>Request a new translation team</legend>
    <table>
        <tbody>
        {% form_as_table_rows team_request_form %}
        </tbody>
    </table>
    <p class="submit">
        <input class="i16 submit" type="submit" value="{% trans "Request team" %}"/>
    </p>
   </fieldset>
</form>
{% endif %}
{% endif %}
{% endwith %}
</div>


</div>
{% endblock %}

