{% extends "assignment/base_assignment.html" %}

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

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

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

    <p><form action="{{request.url}}" name="filter" method="get">
        {% trans "Filter" %}:
        <select class="default-input" name="status" onchange="document.forms['filter'].submit()">
            <option value="---">-- {% trans "Status" %}--</option>
            <option value="sea" {% if 'sea' in request.GET.status %}selected{% endif %}>{% trans "Searching for candidates" %}</option>
            <option value="vot" {% if 'vot' in request.GET.status %}selected{% endif %}>{% trans "Voting" %}</option>
            <option value="fin" {% if 'fin' in request.GET.status %}selected{% endif %}>{% trans "Finished" %}</option>
        </select>
        </form>
    </p>
   {{ assignments|length }}
   {% blocktrans count counter=assignments|length %}election{% plural %}elections{% endblocktrans %}
    <table>
        <tr>
            <th><a href="?sort=name{% if 'name' in request.GET.sort and 'reverse' not in request.GET %}&reverse{%endif%}">{% trans "Election" %}</a></th>
            <th>{% trans "Candidates" %}</th>
            <th><a href="?sort=status{% if 'status' in request.GET.sort and 'reverse' not in request.GET %}&reverse{%endif%}">{% trans "Status" %}</a></th>
            <th style="width: 1px;">{% trans "Actions" %}</th>
        </tr>
    {% for assignment in assignments %}
        <tr class="{% cycle '' 'odd' %}
            {% if assignment.active %}activeline{% endif %}">
            <td><a href="{% url assignment_view assignment.id %}">{{ assignment }}</a></td>
            <td>
                {% blocktrans with posts=assignment.posts %}posts: {{ posts }}{% endblocktrans %}
                {% if assignment.status != 'fin' %}
                    | {% blocktrans with candidates=assignment.get_participants|length %}candidates: {{ candidates }}{% endblocktrans %}
                {% endif %}
                | {% blocktrans with elected=assignment.elected|length %}elected: {{ elected }}{% endblocktrans %}
            </td>
            <td>{{ assignment.get_status_display }}</td>
            <td>
                <span style="width: 1px; white-space: nowrap;">
                {% if perms.projector.can_manage_projector %}
                    <a class="activate_link {% if assignment.active %}active{% endif %}" href="{% url projector_activate_slide assignment.sid %}" title="{% trans 'Activate election' %}">
                        <span></span>
                    </a>
                {% endif %}
                {% if perms.assignment.can_manage_assignment %}
                    <a href="{% url assignment_edit assignment.id %}"><img src="{% static 'images/icons/edit.png' %}" title="{% trans 'Edit election' %}"></a>
                    <a href="{% url assignment_delete assignment.id %}"><img src="{% static 'images/icons/delete.png' %}" title="{% trans 'Delete election' %}"></a>
                {% endif %}
                <a href="{% url print_assignment assignment.id %}" title="{% trans 'Election as PDF' %}"><img src="{% static 'images/icons/pdf.png' %}"></a>
                </span>
            </td>
        </tr>
    {% empty %}
        <tr>
            <td colspan="4"><i>{% trans "No assignments available." %}</i></td>
        </tr>
    {% endfor %}
    </table>
{% endblock %}
