{% extends "base.html" %}

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

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

It includes ``cms/includes/orderable-head.html`` for the sortable logic in javascript,
with the table listing pools having the ``orderable`` class, and displaying the
``sort_order_display`` attribute of the pools.

New order is saved via ajax after each change.

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 'Sort the global pools of questions' %}
    {% else %}
        {% trans 'Sort your pools of questions' %}
    {% endif %}
{% endblock %}

{% block actions %}
    <a class="btn btn-default" href="{{ view.model.get_list_url }}">{% trans 'Back to the list of pools' %}</a>
{% endblock %}

{% block head %}
    {{ block.super }}
    {% include "cms/includes/orderable-head.html" %}
{% endblock %}

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

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

            <th class="orderable-message-holder">{% trans 'Order' %}</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>{{ pool.sort_order_display|safe }}</td>

            </tr>
        {% endfor %}
    </tbody>
</table>

{% endblock %}
