{% extends "sentry/bases/admin.html" %}

{% load i18n %}
{% load sentry_helpers %}

{% block title %}{% trans "Manage Users" %} | {{ block.super }}{% endblock %}

{% block admin-nav-users %} class="active"{% endblock %}

{% block page_header %}
    <a href="{% url 'sentry-admin-new-user' %}" class="btn pull-right btn-primary">{% trans "Create a new user" %}</a>
    {{ block.super }}
{% endblock %}

{% block inner %}
    {% paginator user_list from request as user_list per_page 50 %}

    <form class="btn-toolbar" method="GET" action="">
        <input type="text" name="uquery" value="{% if user_query %}{{ user_query }}{% endif %}" placeholder="search by email address">
        <div class="btn-group pull-right">
            <a class="btn prev{% if not user_list.paginator.has_previous %} disabled{% endif %}" href="?{{ user_list.query_string|escape }}&amp;p={{ user_list.paginator.previous_page }}"><span>{% trans "Previous" %}</span></a>
            <a class="btn next{% if not user_list.paginator.has_next %} disabled{% endif %}" href="?{{ user_list.query_string|escape }}&amp;p={{ user_list.paginator.next_page }}"><span>{% trans "Next" %}</span></a>
        </div>
    </form>

    {% if user_list.paginator.objects %}
        {% querystring from request without sort as sort_querystring %}

        <table class="table table-bordered table-striped">
            <colgroup>
                <col>
                <col style="width:150px;">
                <col style="width:150px;">
            </colgroup>
            <thead>
                <tr>
                    <th><a href="?{{ sort_querystring }}&amp;sort=name">{% trans "Name" %}</a></th>
                    <th style="text-align:center;"><a href="?{{ sort_querystring }}&amp;sort=joined">{% trans "Joined" %}</a></th>
                    <th style="text-align:center;"><a href="?{{ sort_querystring }}&amp;sort=login">{% trans "Last Login" %}</a></th>
                </tr>
            </thead>
            <tbody>
                {% for user in user_list.paginator.objects %}
                    <tr>
                        <td>
                            <a href="{% url 'sentry-admin-edit-user' user.pk %}">
                                {{ user.username }}
                            </a>
                            {% if not user.is_active %}
                                <em>inactive account</em>
                            {% endif %}
                            <br/>
                            <small>
                                {% if user.first_name %}
                                    {{ user.first_name }} ({{ user.email }})
                                {% else %}
                                    {{ user.email }}
                                {% endif %}
                            </small>
                        </td>
                        <td style="text-align:center; vertical-align:middle;">
                            {{ user.date_joined|date }}
                        </td>
                        <td style="text-align:center; vertical-align:middle;">
                            {{ user.last_login|date }}
                        </td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>

    {% else %}
        <p class="alert alert-notice">{% trans "There are no users matching your query in Sentry." %}</p>
    {% endif %}

    <div class="btn-toolbar">
        <div class="btn-group pull-right">
            <a class="btn prev{% if not user_list.paginator.has_previous %} disabled{% endif %}" href="?{{ user_list.query_string|escape }}&amp;p={{ user_list.paginator.previous_page }}"><span>{% trans "Previous" %}</span></a>
            <a class="btn next{% if not user_list.paginator.has_next %} disabled{% endif %}" href="?{{ user_list.query_string|escape }}&amp;p={{ user_list.paginator.next_page }}"><span>{% trans "Next" %}</span></a>
        </div>
    </div>

{% endblock %}
