{% extends 'base.html' %}

{% load i18n %}
{% load humanize %}
{% load tags %}

{% block title %}{% trans "Election" %} "{{ assignment }}", {{ ballotnumber }}. {% trans "ballot" %} – {{ block.super }}{% endblock %}

{% block content %}
<h1>
    {{ assignment }}
    <small>
    {{ ballotnumber|ordinal|safe }} {% trans "ballot" %}
    </small>
    <small class="pull-right">
    <a href="{{ assignment|absolute_url:'detail' }}" class="btn btn-mini"><i class="icon-chevron-left"></i> {% trans "Back to election" %}</a>
    <!-- activate projector -->
    {% if perms.projector.can_manage_projector %}
        <a href="{{ assignment|absolute_url:'projector' }}"
            class="activate_link btn {% if assignment.is_active_slide %}btn-primary{% endif %} btn-mini"
            rel="tooltip" data-original-title="{% trans 'Show election' %}">
            <i class="icon-facetime-video {% if assignment.is_active_slide %}icon-white{% endif %}"></i>
        </a>
    {% endif %}
    </small>
</h1>

{% if assignment.polldescription %}
    <p><b>{% trans "Short description (for ballot paper)" %}:</b> {{ assignment.polldescription }}</p>
{% endif %}

<p>
{% trans "Special values" %}: <span class="badge badge-success">-1</span> = {% trans 'majority' %} | <span class="badge">-2</span> = {% trans 'undocumented' %}
</p>
<form action="" method="post" class="small-form">{% csrf_token %}
    <table class="table table-striped table-bordered" style="width: auto;">
        <tr>
            <th>{% trans "Candidates" %}</th>
            {% for value in poll.get_vote_values %}
                <th>{% trans value %}</th>
            {% endfor %}
        </tr>
        {% for form in forms %}
            <tr>
                <td>{{ form.option }}</td>
                {% for value in form %}
                <td>
                    {{ value.errors }}
                    {{ value }}
                </td>
                {% endfor %}
            </tr>
        {% endfor %}
        <tr>
            <td>{% trans "Invalid votes" %}</td>
            {% for value in poll.get_vote_values %}
                {% if forloop.first %}
                    <td>{{ pollform.votesinvalid.errors }}{{ pollform.votesinvalid }}</td>
                {% else %}
                    <td></td>
                {% endif %}
            {% endfor %}
        </tr>
        <tr class="total warning">
            <td>{% trans "Votes cast" %}</td>
            {% for value in poll.get_vote_values %}
                {% if forloop.first %}
                    <td>{{ pollform.votescast.errors }}{{ pollform.votescast }}</td>
                {% else %}
                    <td></td>
                {% endif %}
            {% endfor %}
        </tr>
    </table>

    <p>
    <a href="{% url 'assignment_poll_pdf' poll.id %}" class="btn" target="_blank">
        <i class="icon-print"></i> {% trans 'Ballot paper as PDF' %}
    </a>
    </p>
    <!-- Control buttons -->
    <div class="control-group">
        <button type="submit" class="btn btn-primary">
            {% trans 'Save' %}
        </button>
        <button type="submit" name="apply" class="btn">
            {% trans 'Apply' %}
        </button>
        <a href="{{ poll.assignment|absolute_url:'detail' }}" class="btn">
            {% trans 'Cancel' %}
        </a>
    </div>
</form>
{% endblock %}
