{% extends "users_admin/base.html" %}
{% load i18n %}
{% load staticfiles %}

{% block title %}Accueil{% endblock %}

{% block nav %}
 <li><a href="create"><i class="icon-plus"></i> Créer des utilisateurs</a></li>
 <li><a href="import"><i class="icon-download"></i> Importer des utilisateurs</a></li>
{% endblock %}

{% block title_content %}
<div class="row">
<div class="span8">
<h1>Liste des utilisateurs</h1>
</div>
<div class="span4">
<form method="get" action="" class="form-inline pull-right">
<div class="input-prepend input-append">
<span class="add-on"><a href="./?filter="><i class="icon-remove-circle"></i></a></span>
<input id="filter" type="text" name="filter" value="{{ filter }}" style="color: red; font-weight: bold;" placeholder="Filtre (avec * et ?)"/>
<input type="submit" value="Filtrer" class="btn" />
</div>
</form>
</div>
</div>

{% endblock %}

{% block content %}

<form action="multiple" method="post">

<br />
<table class="table table-condensed table-striped" id="usersTable">
  <thead>
    <tr>
      <th></th>
      <th data-sort="string">login</th>
      <th data-sort="string">actif?</th>
      <th data-sort="string">expiration</th>
      <th data-sort="string">nom complet</th>
      <th><input type="checkbox" id="check-all" /></th>
      <script>
      $('#check-all').click(function (event) {
        $('input[name="users"]').each(function () {
            this.click();
        });
      });
      </script>
    </tr>
  </thead>
  <tbody>
	  {% for user in users.values|dictsort:"name" %}
	  <tr {% if user.disabled or user.ttl == 0 %} class="disabled"{% endif %}>
                  <td style="text-align: right;">
                          <a href="update/{{ user.name }}"><i class="icon-edit"></i></a>
                  </td>
		  <td data-order-by="{{ user.name }}">
			  <a href="read/{{ user.name }}" {% if user.disabled or user.ttl == 0 %} class="disabled"{% endif %}>{{ user.name }}</a>
			  {% if 'univnautes-idp-multiple' in user.priv %} &mdash; multiple{% endif %}
			  {% if user.disabled %} &mdash; désactivé{% endif %}
			  {% if user.ttl == 0 %} &mdash; expiré{% endif %}
		  </td>
		  <td data-order-by="{% if user.disabled %}DIS{% elif user.ttl == 0 %}EXP{% else %}ACT{% endif %}">
			  {% if user.disabled %}<i class="icon-pause"></i>
			  {% elif user.ttl == 0 %}<i class="icon-stop"></i>
			  {% endif %}
		  </td>
		  <td data-order-by="{{ user.expires|date:"c"|default:"2999-12-31" }}">
			  {{ user.expires|default:"jamais" }}
			  {% if user.ttl > 0 %} ({{ user.ttl }} jour{% if user.ttl > 1 %}s{% endif %})
			  {% elif user.ttl == 0 %} &mdash; expiré{% endif %}
		  </td>
		  <td>{{ user.descr }}</td>
		  <td><input type="checkbox" name="users" value="{{ user.name }}" /></td>
	  </tr>
	  {% endfor %}
  </tbody>
</table>

<div class="form-actions">

<a href="create" class="btn"><i class="icon-plus"></i> Créer des utilisateurs</a>
<a href="import" class="btn"><i class="icon-download"></i> Importer des utilisateurs</a>
<div class=" pull-right">
	<input type="submit" value="Ok" class="btn pull-right" />
	<select name="action" class="pull-right">
	  <option value="none" selected="selected">Choisir une action ...</option>
	  <option value="desactivate">Désactiver les utilisateurs choisis</option>
	  <option value="activate">Activer les utilisateurs choisis</option>
	  <option value="delete">Supprimer les utilisateurs choisis</option>
	  <option value="csv">Exporter la liste en CSV</option>
	  <!-- option value="expire">Changer la date d'expiration des utilisateurs choisis</option -->
	</select>
</div>
</div>

{% csrf_token %}
</form>

<script src="{% static "jquery/js/stupidtable.js" %}"></script>
<script>
  $(function(){ $("#usersTable").stupidtable(); });
</script>

{% endblock %}
