{% extends "base.html" %}
{% import '_macros.html' as macros %}

{% block title %}Utilisateurs | {{ super() }}{% endblock %}

{% block content %}

<h3>Utilisateurs</h3>

<form role="form" method="post" class="form-table"
      action="{{ url_for('users') }}">
{{ user_form.hidden_tag() }}
<table class="table table-centered">
    <thead>
        <tr>
            <th>Nom</th>
            <th>Email de connexion</th>
            <th>Graphes</th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        <tr>
            {{ macros.render_field_table(user_form.name) }}
            {{ macros.render_field_table(user_form.email) }}
            <td></td>
            <td>
                <button type="submit" name="action" value="add" title="Ajouter"
                        class="btn btn-sm btn-primary">
                    <span class="glyphicon glyphicon-plus"></span>
                </button>
            </td>
        </tr>
        {% for user in users %}
        <tr>
            <td>
                <input type="text" name="name" class="form-control input-sm" value="{{ user.name }}" />
            </td>
            <td>{{ user.email }}</td>
            <td>
                {% for perm in user.permissions %}
                    {{ perm.graph.name }} ({{ perm.level_as_string }})
                    {% if not loop.last -%}, {% endif %}
                {% endfor %}
            </td>
            <td>
                <input type="hidden" name="email" value="{{ user.email }}" />
                <button name="action" value="edit" data-loading-text="..."
                        class="btn btn-sm btn-info" title="Mettre à jour">
                    <span class="glyphicon glyphicon-edit"></span>
                </button>
                <button name="action" value="delete" data-loading-text="..."
                        class="btn btn-sm btn-warning" title="Supprimer">
                    <span class="glyphicon glyphicon-remove"></span>
                </button>
            </td>
        </tr>
        {% endfor %}
    </tbody>
</table>
</form>

{% endblock %}
