{% extends "base.html" %}

{% comment %}This view is used to display a list of ``mtp.apps.surveys.Pool`` instances.

Pools authors are only displayed if the user is a superuser.

Context
-------
user : instance of ``mtp.apps.accounts.MTPUser``
    The user is expected to be a superuser or a trainer.
pool_list : queryset of ``mtp.apps.surveys.models.Pool``
    It contains all the pools to display.

{% endcomment %}

{% load i18n %}

{% block body_class %}{{ block.super }} page-cms-surveys page-cms-surveys-pools{% endblock %}

{% block subtitle %}
    {% if user.is_superuser %}
        {% trans 'Global pools of questions' %}
    {% else %}
        {% trans 'Your pools of questions' %}
    {% endif %}
{% endblock %}

{% block actions %}
    {%  if pool_list|length > 1 %}
        <a href="{{ view.model.get_sort_url }}" class="btn btn-primary">
            <i class="fa fa-sort"></i> {% trans "Sort pools" %}
        </a>
    {% endif %}
    <a href="{{ view.model.get_create_url }}" class="btn btn-primary">
        <i class="fa fa-plus"></i> {% trans "Add a pool of questions" %}
    </a>
{% endblock %}

{% block main %}
<table class="table table-hover">
    <thead>
        <tr>
            <th>{% trans 'Name'%}</th>

            {# Only superusers can see pools from many users #}
            {% if  user.is_superuser %}
                <th>{% trans 'Author'%}</th>
            {% endif %}

            <th>{% trans 'Edit'%}</th>
            <th>{% trans 'Questions'%}</th>
            <th>{% trans 'Delete'%}</th>
        </tr>
    </thead>
    <tbody>
        {% for pool in pool_list %}
            <tr>
                <td>{{ pool.name }}</td>

                {# Only superusers can see pools from many users #}
                {% if user.is_superuser %}
                    <td>{{ pool.author }}</td>
                {% endif %}

                <td><a class="btn btn-default" href="{{ pool.get_absolute_url }}" title="{% trans 'Edit' %}"><i class="fa fa-pencil"></i></a></td>
                <td><a class="btn btn-default" href="{{ pool.get_questions_list_url }}" title="{% trans 'Questions' %}">
                    <span class="badge{% if not pool.count_questions %} no-questions{% endif %}">{{ pool.count_questions }}</span>
                </a></td>
                <td><a class="btn btn-danger" href="{{ pool.get_delete_url }}" title="{% trans 'Delete' %}"><i class="fa fa-trash"></i></a></td>
            </tr>
        {% endfor %}
    </tbody>
</table>

{% endblock %}
