{% extends 'base.html' %}
{% load i18n %}

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

{% block subtitle %}
    {% trans "Groups list" %}
{% endblock %}

{% block actions %}
    {% if user.is_staff %}
        <a href="{% url 'accounts:group-create' %}" class="btn btn-primary">
            <i class="icon-plus icon-white"></i> {% trans "Add group" %}
        </a>
    {% endif %}
{% endblock %}

{% block main %}
    <div class="panel panel-default">
        <table class="table table-hover">
            <thead>
                <tr>
                    <th>{% trans "Name" %}</th>
                    <th>{% trans "Type" %}</th>
                    {% if user.is_superuser %}
                        <th>{% trans "Edit"%}</th>
                        <th>{% trans "Delete"%}</th>
                    {% endif %}
                </tr>
            </thead>
            <tbody>
            {% for group in group_list %}
                <tr>
                    <td>{{ group.name }}</td>
                    <td>{{ group.type }}</td>
                    {% if user.is_superuser %}
                        <td>
                            <a class="btn btn-default" href="{{ group.get_edit_url }}">
                                <i class="fa fa-pencil"></i>
                            </a>
                        </td>
                        <td>
                            <a class="btn btn-danger dialog-box" href="{{ group.get_delete_url }}">
                                <i class="fa fa-trash"></i>
                            </a>
                        </td>
                    {% endif %}
                </tr>
            {% endfor %}
            </tbody>
        </table>
        {% if is_paginated %}
            <div class="panel-footer">
                <nav>
                    <ul class="pagination">
                        {% if page_obj.has_previous %}
                            <li>
                                <a data-page="{{ page_obj.previous_page_number }}" href="?page={{ page_obj.previous_page_number }}">
                                    Prev
                                </a>
                            </li>
                        {% endif %}

                        <li>
                            <a class="disabled">
                                Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}.
                            </a>
                        </li>

                        {% if page_obj.has_next %}
                            <li>
                                <a data-page="{{ page_obj.next_page_number }}" href="?page={{ page_obj.next_page_number }}">
                                    Next
                                </a>
                            </li>
                        {% endif %}
                    </ul>
                </nav>
            </div>
        {% endif %}
    </div>
{% endblock %}
