{% 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><span class="optional-small"> {% trans "Back to election" %}</span></a>
        <!-- activate projector -->
        {% if perms.core.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>
            <a class="btn btn-mini activate_link {% if poll.is_active_slide %}btn-primary{% endif %}" href="{{ poll|absolute_url:'projector' }}"
                rel="tooltip" data-original-title="{% trans 'Show election result' %}">
                <i class="icon-facetime-video {% if poll.is_active_slide %}icon-white{% endif %}"></i> {% trans "Election result" %}</a>
        {% endif %}
        {% if perms.motion.can_manage_motion %}
            <a class="btn btn-mini" href="{{ poll|absolute_url:'delete' }}"
                rel="tooltip" data-original-title="{% trans 'Delete ballot' %}"><i class="icon-remove"></i></a>
        {% endif %}
    </small>
</h1>

<form action="" method="post" class="small-form">{% csrf_token %}
    <p>
      {% trans "Special values" %}:
        <span class="badge badge-success">-1</span> = {% trans 'majority' %}|
        <span class="badge">-2</span> = {% trans 'undocumented' %}
    </p>

    <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 class="total warning">
            <td>{% trans "Valid votes" %}</td>
            {% for value in poll.get_vote_values %}
                {% if forloop.first %}
                    <td>{{ pollform.votesvalid.errors }}{{ pollform.votesvalid }}</td>
                {% else %}
                    <td></td>
                {% endif %}
            {% endfor %}
        </tr>
        <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><strong>{% trans "Short description (for ballot paper)" %}:</strong></p>
    <p class="normal-form">{{ pollform.description }}</p>
    <p>
        <a href="{% url 'assignmentpoll_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 %}
