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

{% block title %}{{ block.super }} | {{ project.name }}{% endblock %}

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

{% block content_main %}
{% get_permission "project_perm.submit_file" for request.user and team as "can_submit_file" %}
{% get_permission "project_perm.coordinate_team" for request.user and project,team.language as "is_coordinator" %}

<div class="obj_bigdetails">

<h2 class="name">
{% blocktrans with team.language.name as language_name and team.language.code as language_code %}
  Translation Teams - {{ language_name }} <sup class="entry_metalink">{{ language_code }}</sup>
{% endblocktrans %}</h2>

{% if perms.projects.change_team or is_coordinator %}
<div class="addteam editlinks">
    <a class="i16 buttonized edit" href="{% url team_update team.project.slug team.language.code %}">{% trans "Edit" %}</a>
</div>
{% endif %}

 <div class="team_detail separate">
  <table class="definition">
    {% if team.mainlist %}
    <tr>
      <th class="i16 email">{% trans "Mainlist:" %}</th>
      <td>{{ team.mainlist|mungify:team.mainlist }} </a></td>
    </tr>
    {% endif %}
    
    {% with team.coordinators.all as coordinators %}
    {% if coordinators %}
    <tr>
      <th class="i16 coordinators">{% blocktrans count coordinators|length as counter %}Coordinator:{% plural %}Coordinators:{% endblocktrans %}</th>
      <td>
        {% for c in coordinators|slice:"0:6" %}
          {% if c.first_name and c.last_name %}
            {{ c.first_name }} {{ c.last_name }} ({{c.email|mungify:c.username}})
          {% else %}
            {{c.email|mungify:c.username}}{% endif %}{% if not forloop.last %},{% endif %}
        {% endfor %}
      </td>
    </tr>
    {% endif %}
    {% endwith %}

    {% if request.user.is_authenticated and not perms.projects.submit_file and not can_submit_file and not user_access_request %}
    <tr>
      <th class="i16 user">{% trans "Become a translator:" %}</th>
      <td>
        <form method="post" action="{% url team_join_request team.project.slug team.language.code %}" class="microform">
            <input class="i16 team_join" type="submit" title="{% trans "Join this Team" %}"  value="{% trans "Join this Team" %}">
        </form>
      </td>
    </tr>
   {% endif %} 

  </table>
</div>

{% if team_access_requests %}
<div class="list separate ">
<h4>{% trans "People waiting for team membership approving:" %}</h4>
<ul>
{% for access_request in team_access_requests|dictsort:"user.username" %}
    <li class="i16 team_user_request ">
        <a class="name notice" href="{% url profile_public access_request.user.username %}">{{ access_request.user }}</a>
        {% if can_submit_file %}
          <span>- {{m.user.email|mungify}}</span>
        {% endif %}
        
        {% if is_coordinator %}
        <form class="microform" method="post" action="{% url team_join_approve access_request.team.project.slug access_request.team.language.code access_request.user.username %}">
            <input class="i16 submit" type="submit" value="{% trans "Approve" %}"/>
        </form>
        
        <form class="microform" method="post" action="{% url team_join_deny access_request.team.project.slug access_request.team.language.code access_request.user.username %}">
            <input class="i16 delete" type="submit" value="{% trans "Deny" %}"/>
        </form>
        {% endif %}
        
        {% ifequal request.user.pk access_request.user.pk %}
        <form class="microform" method="post" action="{% url team_join_withdraw access_request.team.project.slug access_request.team.language.code %}">
            <input class="i16 delete" type="submit" value="{% trans "Withdraw" %}"/>
        </form>
        {% endifequal %}
    </li>
{% endfor %}
</ul>
</div>
{% endif %}


{% with team.members.all as members %}
{% if members %}
<div class="list separate ">
<h4>{% trans "Team Members:" %}</h4>
<ul>
{% for m in members|dictsort:"username" %}
    <li class="i16 user">
        <a class="name" href="{% url profile_public m.username %}">{{ m }}</a>
        {% if can_submit_file %}
          <span>- {{m.email|mungify}}</span>
        {% endif %}
        {% ifequal request.user.pk m.pk %}
        <form class="microform" method="post" action="{% url team_leave team.project.slug team.language.code %}">
            <input class="i16 user_delete" type="submit" value="{% trans "Leave" %}"/>
        </form>
        {% endifequal %}
    </li>
{% endfor %}
</ul>
</div>
{% endif %}
{% endwith %}
</div>

{% hook "team_detail.html" extra_content %}

<h3>{% trans 'History' %}</h3>
{% load tx_action_log %}
{% get_log 5 as action_log for_object team %}
{% 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 project as "is_maintainer" %}
    {% if perms.teams.delete_team or is_maintainer %}
    <div class="deletelink">
      <a class="i16 delete buttonized" href="{% url team_delete project.slug team.language.code %}">{% trans "Delete team" %}</a>
    </div>
    {% endif %}
  </div>
{% endblock %}
