{% extends "base.html" %}

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

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

{% block header %}
    <link href="{% static 'css/dataTables/dataTables.bootstrap.css' %}" type="text/css" rel="stylesheet">
{% endblock %}

{% block javascript %}
    <script src="{% static 'js/jquery/jquery.dataTables.min.js' %}" type="text/javascript"></script>
    <script src="{% static 'js/jquery/dataTables.bootstrap.js' %}" type="text/javascript"></script>
{% endblock %}

{% block content %}
    <h1>{% trans "Elections" %}
        <small class="pull-right">
        {% if perms.assignment.can_manage_assignment %}
            <a href="{% url 'assignment_create' %}" class="btn btn-mini btn-primary" rel="tooltip" data-original-title="{% trans 'New election' %}"><i class="icon-plus icon-white"></i> {% trans "New" %}</a>
        {% endif %}
        {% if perms.core.can_manage_tags %}
            <a href="{% url 'core_tag_list' %}" class="btn btn-mini" rel="tooltip" data-original-title="{% trans 'Manage tags' %}">
                <i class="icon-tags"></i>
                <span class="optional-small"> {% trans 'Tags' %}</span>
            </a>
        {% endif %}
        {% if perms.assignment.can_see_assignment %}
            <a href="{% url 'assignment_list_pdf' %}" class="btn btn-mini" rel="tooltip" data-original-title="{% trans 'Print all elections as PDF' %}" target="_blank"><i class="icon-print"></i><span class="optional-small"> PDF</span></a>
        {% endif %}
        </small>
    </h1>

    <table id="dataTable" class="table table-striped table-bordered">
    <thead>
        <tr>
            <th>{% trans "Election" %}</th>
            <th class="optional">{% trans "Candidates" %}</th>
            <th>{% trans "Status" %}</th>
            {% if perms.assignment.can_manage_assignment or perms.core.can_manage_projector %}
                <th class="mini_width">{% trans "Actions" %}</th>
            {% endif %}
        </tr>
    </thead>
    {% for object in object_list %}
        <tr class="{% if object.is_active_slide %}activeline{% endif %}">
            <td><a href="{{ object|absolute_url:'detail' }}">{{ object }}</a>
                {% for tag in object.tags.all %}
                    <span class="optional label">{{ tag }}</span>
                {% endfor %}
            </td>
            <td  class="optional">
                <!-- posts -->
                {% trans "Posts" context "Number of searched candidates for an election" %}:
                <span class="badge badge-info">{{ object.posts }}</span>
                <!-- candidates -->
                {% if object.status != 'fin' %}
                    | {% trans "Candidates" %}: <span class="badge badge-warning">{{ object.get_participants|length }}</span>
                {% endif %}
                <!-- elected candidates -->
                | {% trans "Elected" %}: <span class="badge badge-success">{{ object.elected|length }}</span>
            </td>
            <td><span class="label label-info">{{ object.get_status_display }}</status></td>
            {% if perms.assignment.can_manage_assignment or perms.core.can_manage_projector %}
            <td>
                <span style="width: 1px; white-space: nowrap;">
                {% if perms.core.can_manage_projector %}
                    <a href="{{ object|absolute_url:'projector' }}"
                        class="activate_link btn {% if object.is_active_slide %}btn-primary{% endif %} btn-mini"
                        rel="tooltip" data-original-title="{% trans 'Show election' %}">
                        <i class="icon-facetime-video {% if object.is_active_slide %}icon-white{% endif %}"></i>
                    </a>
                {% endif %}
                {% if perms.assignment.can_manage_assignment %}
                    <a href="{{ object|absolute_url:'update' }}"
                        rel="tooltip" data-original-title="{% trans 'Edit' %}"
                        class="btn btn-mini"><i class="icon-pencil"></i>
                    </a>
                    <a href="{% url 'assignment_delete' object.id %}"
                        rel="tooltip" data-original-title="{% trans 'Delete' %}"
                        class="btn btn-mini"><i class="icon-remove"></i>
                    </a>
                {% endif %}
                </span>
            </td>
            {% endif %}
        </tr>
    {% endfor %}
    </table>
{% endblock %}
