{% extends "base.html" %}

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

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

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

{% block javascript %}
    <script src="{% static 'javascript/jquery.dataTables.min.js' %}" type="text/javascript"></script>
    <script src="{% static 'javascript/naturalSort.js' %}" type="text/javascript"></script>
    <script src="{% static 'javascript/dataTables.bootstrap.js' %}" type="text/javascript"></script>
    <script type="text/javascript" charset="utf-8">
        $('#dataTable').dataTable( {
            "aoColumnDefs": [
                { "sType": "natural", "aTargets": [ 0 ] }
            ],
        });
    </script>
{% endblock %}

{% block content %}
    <h1>
        {% trans "Motions" %}
        <small class="pull-right">
        {% if perms.motion.can_create_motion %}
            {% if not 'motion_stop_submitting'|get_config or perms.motion.can_manage_motion %}
                <a href="{% url 'motion_new' %}" class="btn btn-mini btn-primary" rel="tooltip" data-original-title="{% trans 'New motion' %}"><i class="icon-plus icon-white"></i> {% trans 'New' %}</a>
            {% endif %}
        {% endif %}
        {% if perms.motion.can_manage_motion %}
            <a href="{% url 'motion_category_list' %}" class="btn btn-mini" rel="tooltip" data-original-title="{% trans 'Manage categories' %}"><i class="icon-th-large"></i> {% trans 'Categories' %}</a>
            <a href="{% url 'motion_csv_import' %}" class="btn btn-mini" rel="tooltip" data-original-title="{% trans 'Import motions' %}"><i class="icon-import"></i> {% trans 'Import' %}</a>
        {% endif %}
        <a href="{% url 'motion_list_pdf' %}" class="btn btn-mini" rel="tooltip" data-original-title="{% trans 'Print all motions as PDF' %}" target="_blank"><i class="icon-print"></i> PDF</a>
        </small>
    </h1>

    <table id="dataTable" class="table table-striped table-bordered">
    <thead>
        <tr>
            <th>{% trans "#" %}</th>
            <th>{% trans "Motion title" %}</th>
            <th class="optional">{% trans 'Category' %}</th>
            <th>{% trans "Status" %}</th>
            <th class="optional">{% trans "Submitter" %}</th>
            {% if 'motion_min_supporters'|get_config > 0 %}
                <th class="optional">{% trans "Supporters" %}</th>
            {% endif %}
            <th class="optional">{% trans "Last changes" %}</th>
            <th class="mini_width">{% trans "Actions" %}</th>
        </tr>
    </thead>
    {% for motion in motion_list %}
        <tr class="{% if motion.is_active_slide %}activeline{% endif %}">
            <td class="nobr">{{ motion.identifier|default:'' }}</td>
            <td><a href="{{ motion|absolute_url }}">{{ motion }}</a></td>
            <td class="optional">{% if motion.category %}{{ motion.category }}{% else %}–{% endif %}</td>
            <td><span class="label label-info">{% trans motion.state.name %}</span></td>
            <td class="optional">
                {% for submitter in motion.submitter.all %}
                    {{ submitter.person }}{% if not forloop.last %}, {% endif %}
                {% endfor %}
            </td>
            {% if 'motion_min_supporters'|get_config > 0 %}
                {% with supporters=motion.supporters|length %}
                    <td class="optional">
                    {% if supporters >= 'motion_min_supporters'|get_config %}
                        <a class="badge badge-success" rel="tooltip" data-original-title="{% trans 'Enough supporters' %}">{{ supporters }}</a>
                    {% endif %}
                    {% if supporters < 'motion_min_supporters'|get_config %}
                        <a class="badge badge-warning" rel="tooltip" data-original-title="{% trans 'Needs supporters' %}">{{ supporters }}</a>
                    {% endif %}
                    </td>
                {% endwith %}
            {% endif %}
            <td class="optional">{{ motion.get_last_version.creation_time }}
                {% if motion.get_last_version.version_number != motion.active_version.version_number %}
                    <a href="{{ motion.get_last_version|absolute_url }}" class="label label-warning" rel="tooltip" data-original-title="{% trans 'There is a newer (unauthorized) version.' %}">
                        <i class="icon-warning-sign icon-white"></i>
                    </a>
                {% endif %}</td>
            <td>
                <span style="width: 1px; white-space: nowrap;">
                {% if perms.projector.can_manage_projector %}
                    <a href="{{ motion|absolute_url:'projector' }}" class="activate_link btn {% if motion.is_active_slide %}btn-primary{% endif %} btn-mini"
                        rel="tooltip" data-original-title="{% trans 'Show motion' %}">
                        <i class="icon-facetime-video {% if motion.is_active_slide %}icon-white{% endif %}"></i>
                    </a>
                {% endif %}
                {% if perms.motion.can_manage_motion %}
                    <a href="{{ motion|absolute_url:'update' }}" rel="tooltip" data-original-title="{% trans 'Edit' %}"
                        class="btn btn-mini"><i class="icon-pencil"></i>
                    </a>
                    <a href="{{ motion|absolute_url:'delete' }}" rel="tooltip" data-original-title="{% trans 'Delete' %}"
                        class="btn btn-mini"><i class="icon-remove"></i>
                    </a>
                {% endif %}
                <a href="{% url 'motion_detail_pdf' motion.id  %}" data-original-title="{% trans 'Print motion as PDF' %}"
                    class="btn btn-mini tooltip-left" target="_blank"><i class="icon-print"></i> PDF
                </a>
                </span>
            </td>
        </tr>
    {% endfor %}
    </table>
{% endblock %}
