{% extends "motion/base_motion.html" %}

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

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

{% block content %}
    <h1>{% trans "Motions" %}</h1>
    <p><form action="{{ request.url }}" name="filter" method="get">
        {% trans "Filter" %}:
        {% if min_supporters > 0 %}
        <input type="checkbox" name="needsup" onchange="document.forms['filter'].submit()"
            {% if 'on' in request.GET.needsup %}checked{% endif %}> {% trans "Need supporters" %} &nbsp;
        {% endif %}
        <input type="checkbox" name="number" onchange="document.forms['filter'].submit()"
            {% if 'on' in request.GET.number %}checked{% endif %}> {% trans "Without number" %} &nbsp;
        <input type="checkbox" name="status" onchange="document.forms['filter'].submit()"
            {% if 'on' in request.GET.status %}checked{% endif %}> {% trans "Status" %}:
        <select class="default-input" name="statusvalue" onchange="{% if 'on' in request.GET.status %}document.forms['filter'].submit(){% endif %}">
            <option value="pub" {% if 'pub' in request.GET.statusvalue %}selected{% endif %}>{% trans "Not yet authorized" %}</option>
            <option value="per" {% if 'on' in request.GET.status and 'per' in request.GET.statusvalue %}selected{% endif %}>{% trans "Authorized" %}</option>
            <option value="acc" {% if 'on' in request.GET.status and 'acc' in request.GET.statusvalue %}selected{% endif %}>{% trans "Accepted" %}</option>
            <option value="rej" {% if 'on' in request.GET.status and 'rej' in request.GET.statusvalue %}selected{% endif %}>{% trans "Rejected" %}</option>
            <option value="wit" {% if 'on' in request.GET.status and 'wit' in request.GET.statusvalue %}selected{% endif %}>{% trans "Withdrawen (by submitter)" %}</option>
            <option value="rev" {% if 'rev' in request.GET.statusvalue %}selected{% endif %}>{% trans "Needs Review" %}</option>
        </select>
        </form>
    </p>
    {{ motions|length }}
    {% blocktrans count counter=motions|length context "number of motions"%}motion{% plural %}motions{% endblocktrans %}
    <table>
        <tr>
            <th><a href="?sort=number{% if 'number' in request.GET.sort and 'reverse' not in request.GET %}&reverse{%endif%}">{% trans "Number" %}</a></th>
            <th><a href="?sort=title{% if 'title' in request.GET.sort and 'reverse' not in request.GET %}&reverse{%endif%}">{% trans "Motion title" %}</a></th>
            {% if min_supporters > 0 %}
            <th><a href="?sort=supporter{% if 'supporter' in request.GET.sort and 'reverse' not in request.GET %}&reverse{%endif%}">{% trans "Number of supporters" %}</a></th>
            {% endif %}
            <th><a href="?sort=status{% if 'status' in request.GET.sort and 'reverse' not in request.GET %}&reverse{%endif%}">{% trans "Status" %}</a></th>
            <th><a href="?sort=submitter{% if 'submitter' in request.GET.sort and 'reverse' not in request.GET %}&reverse{%endif%}">{% trans "Submitter" %}</a></th>
            <th><a href="?sort=time{% if 'time' in request.GET.sort and 'reverse' not in request.GET %}&reverse{%endif%}">{% trans "Creation Time" %}<a></th>
            <th style="width: 1px;">{% trans "Actions" %}</th>
        </tr>
    {% for app_info in motions %}
    {% with motion=app_info.motion useractions=app_info.actions %}
        <tr class="{% cycle '' 'odd' %}
            {% if motion.active %}activeline{% endif %}">
            <td>{% if motion.number %}{{ motion.number }}{% else %}-{% endif %}</td>
            <td><a href="{% url motion_view motion.id %}">{{ motion.public_version.title }}</a></td>
        {% if min_supporters > 0 %}
            <td>{{ motion.count_supporters }}</td>
        {% endif %}
            <td>{% if motion.status != "pub" %}
                {{ motion.get_status_display }}<br>
                {% endif %}
                {% for note in motion.notes %}
                {{ note }}
                {% if not forloop.last %}<br>{%endif%}
                {% endfor %}
            </td>
            <td>{{ motion.submitter }}</td>
            <td>{{ motion.creation_time }}</td>
            <td>
                <span style="width: 1px; white-space: nowrap;">
                {% if perms.projector.can_manage_projector %}
                    <a class="activate_link {% if motion.active %}active{% endif %}" href="{% url projector_activate_slide motion.sid %}" title="{% trans 'Activate motion' %}">
                        <span></span>
                    </a>
                {% endif %}
                {% if perms.motion.can_manage_motion %}
                    <a href="{% url motion_edit motion.id %}"><img src="{% static 'images/icons/edit.png' %}" title="{% trans 'Edit motion' %}"></a>
                    {% if "delete" in useractions %}
                    <a href="{% url motion_delete motion.id %}"><img src="{% static 'images/icons/delete.png' %}" title="{% trans 'Delete motion' %}"></a>
                    {% endif %}
                {% endif %}
                <a href="{% url print_motion motion.id  %}" title="{% trans 'Motion as PDF' %}"><img src="{% static 'images/icons/pdf.png' %}"></a>
                </span>
            </td>
        </tr>
    {% endwith %}
    {% empty %}
        <tr>
        <td colspan="7"><i>{% trans "No motions available." %}</i></td>
        </tr>
    {% endfor %}
    </table>
{% endblock %}
