{% extends "app.html" %}
{% import 'bootstrap/wtf.html' as wtf %}

{% block app_content %}
    <div class="row">
        <div class="hidden">{{ wtf.quick_form(delete_user_form, id="delete-user-form") }}</div>
        <div class="col-md-12">
            <table id="users" class="table table-striped table-bordered table-hover">
            <caption><a href="{{ url_for('app.user-create') }}"><span class="glyphicon glyphicon-plus"></span> Add User</a></caption>
                <thead>
                    <tr>
                        <th scope="col">#</th>
                        <th scope="col">Name</th>
                        <th scope="col">Email</th>
                        <th scope="col"></th>
                        <th scope="col"></th>
                    </tr>
                </thead>
                <tbody>
                    {% for user in users %}
                    <tr>
                         <td>{{ user.id }}</td>
                         <td>{{ user.name }}</td>
                         <td>{{ user.email }}</td>
                         <td><a href="{{ url_for('app.user', user_id=user.id) }}">
                             <span class="glyphicon glyphicon-pencil submenu"></span>
                         </a></td>
                         <td data-href="{{ url_for('app.user', user_id=user.id) }}"
                             data-toggle="modal"
                             data-target="#confirm-delete"
                             data-form-id="#delete-user-form"
                             data-message="<ul><li>Delete user: <strong>{{ user.email }}</strong></li></ul>">
                             <span class="glyphicon glyphicon-trash"></span>
                         </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
{% endblock %}

{% block scripts %}
{{super()}}
<script type="text/javascript">
var table = $('#users').dataTable( {
    "responsive": true,
    "order": [[1, 'desc']],
    "columnDefs": [{ "orderable": false, "targets": [0, 3, 4] }]
} );
</script>
{% endblock %}
