{% extends "docbow/base_user.html" %}
{% load crispy_forms_tags %}
{% load i18n %}

{% block title %}
{% trans "Delegations" %}
{% endblock %}

{% block extra_scripts %}
{{ form.media }}
{% endblock %}

{% block main-column %}
{% if delegations %}
<form method="post">
{% csrf_token %}
<h3>{% trans "Delegations" %}</h3>
<table id="delegations">
<thead>
 <tr>
  <th id="firstname">Prénom</th>
  <th id="lastname">Nom</th>
  <th id="email">Courriel</th>
  <th id="username">Identifiant</th>
  <th></th>
 </tr>
</thead>
<tbody>
{% for delegation in delegations %}
 <tr class="{% cycle 'odd' 'even' %}">
  <td>{{ delegation.to.first_name }}</td>
  <td>{{ delegation.to.last_name }}</td>
  <td>{{ delegation.to.email }}</td>
  <td>{{ delegation.to.username }}</td>
  <td><input type="image" name="delegate-delete-{{ delegation.to.username }}" src="{{ STATIC_URL }}/docbow/css/images/poubelle.png" alt="{% trans "Delete" %}"/></td>
 </tr>
 <tr class="last-connection {% cycle 'odd' 'even' %}">
   {% if delegation.journals %}
   <td colspan="5">Dernière(s) connexion(s): {% for connection_time in delegation.journals %}
     {{ connection_time }}
     {% if not forloop.last %}, {% endif %}
     {% endfor %}</td>
   {% else %}
      {% if delegation.to.date_joined != delegation.to.last_login %}
        <td colspan="5">Dernière connexion: {{ delegation.to.last_login }}</td>
      {% else %}
        <td colspan="5">Aucune connexion.</td>
      {% endif %}
   {% endif %}
 </tr>
{% endfor %}
</tbody>
</table>
</form>
{% endif %}

<h3>{% trans "Create a new delegation" %}</h3>
<div id="new-delegation-form">
{% with form.helper as helper %}
{% crispy form helper %}
{% endwith %}
</div>

<h3>{% trans "Received delegations" %}</h3>
<ul id="received-delegations">
  {% for delegation in received_delegations %}
  <li>{% firstof delegation.by.get_full_name delegation.by.username %}</li>
  {% endfor %}
</div>

{% endblock %}
