{% extends get_active_back_theme()+"/base.html" %}

{%block head%}
    <script src="{{url_for('static', filename='jquery_3.2.1.min.js')}}"></script>
{%endblock%}
{% block content %}
<br>
<script type="text/javascript">
$(function() {
    $('.delete_me').click(function() {
        var id = $(this).data('id');
        console.log(id);
        var ask = confirm("Do you want to delete ?");
        if (ask == true) {
            window.open("/appadmin/delete/" + id, "_self")
        } else {

        }
    });
});
</script>
<div class="container">
    <div class="card">
        <div class="card-body">
            <h2>List users</h2>
            <table class="table table-responsive table-bordered">
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>Email</th>
                        <th>Password</th>
                        <th>Admin</th>
                        <th>Roles</th>
                        <th style="border: none;"></th>
                    </tr>
                </thead>
                <tbody>
                    {% for user in users %}
                    <tr>
                        <td>{{user.id}}</td>
                        <td>{{user.email}}</td>
                        <td>*******</td>
                        <td>{{user.is_admin}}</td>
                        <td>
                            {%for role in user.roles%}
                            <div class="badge badge-primary">
                                {{role.name}}
                            </div>
                            {%endfor%}
                        </td>
                        <td style="border: none;">
                            <div style='display: inline-block; '>
                                <a style="text-decoration: none;">
                                    <button id='delete' data-id="{{ user.id }}" class="delete_me btn btn-dark" type="" name="{{ user.id }}">delete</button>
                                </a>
                                &nbsp;
                                <a href="/appadmin/edit/{{ user.id }}" style="text-decoration: none;">
                                    <button data-name="{{ user.id }}" class="btn btn-warning">edit
                                    </button>
                                </a>
                            </div>
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>
{% endblock %}
