{% extends "participant/base_participant.html" %}

{% load i18n %}
{% load staticfiles %}
{% load tags %}

{% block title %}{{ block.super }} – {% trans "Participants" %}{% endblock %}

{% block header %}
    {% if perms.agenda.can_manage_agenda %}
        <link type="text/css" rel="stylesheet" media="all" href="{% static 'styles/participant.css' %}" />
        <script type="text/javascript" src="{% static 'javascript/participant.js' %}"></script>
    {% endif %}
{% endblock %}


{% block content %}
    <h1>{% trans "Participants" %}</h1>

    <p>
        <form action="" name="filter" method="get">
            {% trans "Filter" %}:
            <select class="default-input" name="gender" onchange="document.forms['filter'].submit()">
                <option value="---">-- {% trans "Gender" %} --</option>
                <option value="male"{% if 'male' in sortfilter.gender %} selected{% endif %}>{% trans "Male" %}</option>
                <option value="female"{% if 'female' in sortfilter.gender %} selected{% endif %}>{% trans "Female" %}</option>
                <option value=""{% if '' in sortfilter.gender %} selected{% endif %}>{% trans "Not specified" %}</option>
            </select>
            <select class="default-input" name="structure_level" onchange="document.forms['filter'].submit()">
                <option value="---">-- {% trans "Structure level" %} --</option>
                {% for level in structure_levels %}
                    <option value="{{ level }}"{% if level in sortfilter.structure_level %} selected{% endif %}>
                    {{ level }}</option>
                {% endfor %}
            </select>
            <select class="default-input" name="type" onchange="document.forms['filter'].submit()">
                <option value="---">-- {% trans "Type" %} --</option>
                <option value="delegate"{% if 'delegate' in sortfilter.type %} selected{% endif %}>{% trans "Delegate" %}</option>
                <option value="observer"{% if 'observer' in sortfilter.type %} selected{% endif %}>{% trans "Observer" %}</option>
                <option value="staff"{% if 'staff' in sortfilter.type %} selected{% endif %}>{% trans "Staff" %}</option>
                <option value="guest"{% if 'guest' in sortfilter.type %} selected{% endif %}>{% trans "Guest" %}</option>
                <option value=""{% if '' in sortfilter.type %} selected{% endif %}>{% trans "Not specified" %}</option>
            </select>
            <select class="default-input" name="committee" onchange="document.forms['filter'].submit()">
                <option value="---">-- {% trans "Committee" %} --</option>
                {% for committee in committees %}
                    <option value="{{ committee }}"{% if committee in sortfilter.committee %} selected{% endif %}>
                    {{ committee }}</option>
                {% endfor %}
            </select>
            <select class="default-input" name="status" onchange="document.forms['filter'].submit()">
                <option value="---">-- {% trans "Status" %} --</option>
                <option value="1"{% if '1' in sortfilter.status %} selected{% endif %}>{% trans "Active" %}</option>
                <option value="0"{% if '0' in sortfilter.status %} selected{% endif %}>{% trans "Inactive" %}</option>
            </select>
        </form>
    </p>
    {% if users.count == allusers %}
        {{ users.count }}
        {% blocktrans count counter=users.count %}participant{% plural %}participants{% endblocktrans %}
    {% else %}
        {{ users.count }} {% trans "of" %} {{ allusers }} {% trans "Participants" %} (= {{ percent }} %)
    {% endif %}
    <table>
        <tr>
            <th><a href="?sort=first_name&reverse={% if 'first_name' in sortfilter.sort and 'reverse' not in sortfilter %}1{% else %}---{%endif%}">{% trans "First Name" %}</a></th>
            <th><a href="?sort=last_name&reverse={% if 'last_name' in sortfilter.sort and 'reverse' not in sortfilter %}1{% else %}---{%endif%}">{% trans "Last Name" %}</a></th>
            <th><a href="?sort=structure_level&reverse={% if 'structure_level' in sortfilter.sort and 'reverse' not in sortfilter %}1{% else %}---{%endif%}">{% trans "Structure level" %}</a></th>
            <th><a href="?sort=type&reverse={% if 'type' in sortfilter.sort and 'reverse' not in sortfilter %}1{% else %}---{%endif%}">{% trans "Type" %}</a></th>
            <th><a href="?sort=committee&reverse={% if 'committee' in sortfilter.sort and 'reverse' not in sortfilter %}1{% else %}---{%endif%}">{% trans "Committee" %}</a></th>
            {% if perms.participant.can_manage_participant %}
                <th><a href="?sort=comment&reverse={% if 'comment' in sortfilter.sort and 'reverse' not in sortfilter %}1{% else %}---{%endif%}">{% trans "Comment" %}</a></th>
                <th><a href="?sort=last_login&reverse={% if 'last_login' in sortfilter.sort and 'reverse' not in sortfilter %}1{% else %}---{%endif%}">{% trans "Last Login" %}</a></th>
                <th>{% trans "Actions" %}</th>
            {% endif %}
        </tr>
        {% for user in users %}
            <tr class="{% cycle '' 'odd' %}">
                <td><a href="{% model_url user 'view' %}">{{ user.first_name }}</a></td>
                <td><a href="{% model_url user 'view' %}">{{ user.last_name }}</a></td>
                <td>{{ user.structure_level }}</td>
                <td>{{ user.get_type_display }}</td>
                <td>{{ user.committee }}</td>
                {% if perms.participant.can_manage_participant %}
                    <td>{{ user.comment|first_line }}</td>
                    <td>
                        {% if user.last_login > user.date_joined %}
                            {{ user.last_login }}
                        {% endif %}
                    </td>
                    <td>
                        <span style="width: 1px; white-space: nowrap;">
                            <a href="{% url user_edit user.id %}">
                                <img src="{% static 'images/icons/edit.png' %}" title="{% trans 'Edit participant' %}">
                            </a>
                            {% if user != request_user %}
                            <a href="{% url user_delete user.id %}">
                                <img src="{% static 'images/icons/delete.png' %}" title="{% trans 'Delete participant' %}">
                            </a>
                            {% endif %}
                            {% if user != request_user and not user.is_superuser %}
                            <a class="status_link deactivate" href="{% url user_status_deactivate user.id %}" title="{% trans 'Change status to inactive' %}"{% if not user.is_active %} style="display:none"{% endif %}>
                                <span></span>
                            </a>
                            <a class="status_link activate" href="{% url user_status_activate user.id %}" title="{% trans 'Change status to active' %}"{% if user.is_active %} style="display:none"{% endif %}>
                                <span></span>
                            </a>
                            {% endif %}
                        </span>
                    </td>
                {% endif %}
            </tr>
        {% empty %}
            <tr>
                <td colspan="9"><i>{% trans "No participants available." %}</i></td>
            </tr>
        {% endfor %}
    </table>
{% endblock %}
