{% extends "layout/2-columns-left.html" %}
{% load i18n %}

{% block head %}
    <script type="text/javascript" src="{{ STATIC_URL }}common/js/ajax-modal.js"></script>
{% endblock %}

{% block subtitle %}
    {% trans 'User list' %}
{% endblock %}

{% block actions %}
    {% block extra_actions_before %}{% endblock %}
    {% if user.is_staff %}
        <a href="{% url 'accounts:user-create' %}" class="btn btn-primary">
            <i class="fa fa-plus icon-white"></i>
            {% trans 'Add trainee' %}
        </a>
    {% if user.is_superuser %}
        <a href="{% url 'accounts:user-create' %}?trainer=true" class="btn btn-danger">
            <i class="fa fa-plus icon-white"></i>
            {% trans 'Add trainer' %}
        </a>
    {% endif %}
        <a href="{% url 'accounts:user-import' %}" class="btn btn-default">
            <i class="fa fa-file"></i>
            {% trans 'Import users' %}
        </a>
    {% endif %}
    {% block extra_actions_after %}{% endblock %}
{% endblock %}

{% block column_left %}
    <form action="" method="get">
        {% include 'extras/form.html' with form=filter.form %}
        <div class="clearfix">
            <a href="{% url 'accounts:user-list' %}" class="pull-left btn btn-warning">
                {% trans 'Reset' %}
            </a>
            <input type="submit" class="btn btn-primary pull-right" value="{% trans 'Apply' %}" />
        </div>
    </form>
{% endblock %}

{% block column_main %}
    <div class="row">
        <div class="col-md-12">
            <div class="panel panel-default">
                <table class="table table-hover">
                    <thead>
                        <tr>
                            <th>{% trans 'Username'%}</th>
                            <th>{% trans 'First name'%}</th>
                            <th>{% trans 'Last name'%}</th>
                            <th>{% trans 'Email'%}</th>
                            {% if user.is_superuser %}
                                <th>{% trans 'Actions'%}</th>
                            {% endif %}
                            {% comment 'Deactivate this until we revamp the email templates' %}
                                {% if user.is_staff %}
                                    <th>{% trans 'Resend email'%}</th>
                                {% endif %}
                            {% endcomment %}
                        </tr>
                    </thead>
                    <tbody>
                        {% for mtpuser in mtpuser_list %}
                            <tr>
                                <td>{{ mtpuser.username }}</td>
                                <td>{{ mtpuser.first_name }}</td>
                                <td>{{ mtpuser.last_name }}</td>
                                <td>{{ mtpuser.email }}</td>
                                {% if user.is_superuser and not mtpuser.is_superuser %}
                                    <td>
                                        <div class="btn-group">
                                            <button type="button"
                                                    class="btn btn-default dropdown-toggle"
                                                    data-toggle="dropdown"
                                                    aria-expanded="false"
                                            >
                                                {% trans "Actions" %}
                                                <span class="caret"></span>
                                            </button>
                                            <ul class="dropdown-menu pull-right">
                                                {% if mtpuser.is_deleted %}
                                                    <li>
                                                        <a class="dialog-box" href="{{ mtpuser.get_delete_url }}">
                                                            <i class="fa fa-check"></i> {% trans 'Activate' %}
                                                        </a>
                                                    </li>
                                                {% else %}
                                                    <li>
                                                        <a href="{{ mtpuser.get_edit_url }}">
                                                            <i class="fa fa-pencil"></i> {% trans 'Edit' %}
                                                        </a>
                                                    </li>
                                                    <li>
                                                        <a class="dialog-box" href="{{ mtpuser.get_delete_url }}">
                                                            <i class="fa fa-times"></i> {% trans 'Deactivate' %}
                                                        </a>
                                                    </li>
                                                {% endif %}
                                            </ul>
                                        </div>
                                    </td>
                                {% endif %}
                                {% comment 'Deactivate this until we revamp the email templates' %}
                                    {% if user.is_staff %}
                                        <td>
                                            <a class="btn btn-default btn-sm" href="{{ mtpuser.get_welcome_url }}">
                                                <i class="fa fa-envelope"></i>
                                            </a>
                                        </td>
                                    {% endif %}
                                {% endcomment %}
                            </tr>
                        {% endfor %}
                    </tbody>
                </table>
                <div class="panel-footer">
                    {% include 'extras/pagination.html' %}
                </div>
            </div>
        </div>
    </div>
{% endblock %}
