{% extends "base.html" %}

{% load i18n %}
{% load mptt_tags %}
{% load staticfiles %}

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

{% block header %}
    <link type="text/css" rel="stylesheet" media="all" href="{% static 'styles/agenda.css' %}" />
    <link type="text/css" rel="stylesheet" media="all" href="{% static 'styles/agenda_sort.css' %}" />
{% endblock %}

{% block javascript %}
    <script type="text/javascript" src="{% static 'javascript/agenda.js' %}"></script>
    <script type="text/javascript" src="{% static 'javascript/jquery.cookie.js' %}"></script>
    {% if perms.agenda.can_manage_agenda %}
        <script type="text/javascript" src="{% static 'javascript/jquery.once.js' %}"></script>
        <script type="text/javascript" src="{% static 'javascript/jquery-ui.custom.min.js' %}"></script>
        <script type="text/javascript" src="{% static 'javascript/jquery.tmpl.js' %}"></script>
        <script type="text/javascript" src="{% static 'javascript/jquery.mjs.nestedSortable.js' %}"></script>
    {% endif %}
    <script type="text/javascript" src="{% static 'javascript/agenda_sort.js' %}"></script>
{% endblock %}

{% block content %}
    <form action="" method="post">{% csrf_token %}
        {% if perms.agenda.can_manage_agenda %}
            <div id="changed-order-message" style="display:none" class="alert alert-warning">
                <button type="button" class="close" data-dismiss="alert">×</button>
                {% trans "Do you want to save the changed order of agenda items?" %}<br>
                <button class="btn btn-mini" type="submit">{% trans 'Yes' %}</button>
                <a href="{% url 'item_overview' %}" class="btn btn-mini">{% trans 'No' %}</a>
            </div>
        {% endif %}

        <h1>{% trans "Agenda" %}
            <small class="pull-right">
            {% if perms.agenda.can_manage_agenda %}
                <a href="{% url 'item_new' %}" class="btn btn-mini btn-primary" rel="tooltip" data-original-title="{% trans 'New item' %}"><i class="icon-plus icon-white"></i> {% trans "New" %}</a>
            {% endif %}
            <a href="{% url 'print_agenda' %}" class="btn btn-mini" rel="tooltip" data-original-title="{% trans 'Print agenda as PDF' %}" target="_blank"><i class="icon-print"></i> PDF</a>
            </small>
        </h1>

        <div class="row-fluid">
            <div class="span6">
                <label class="checkbox">
                    <input type="checkbox" id="hide_closed_items"> {% trans "Hide closed items" %}
                </label>
                <small><i>{{ items|length }}
                {% blocktrans count counter=items|length %}item{% plural %}items{% endblocktrans %}<span id="hiddencount"></span>
                </i></small>
            </div>
            <div class="span6">
                {% if perms.agenda.can_see_orga_items %}
                    {% if start and end %}
                        <table id="agendatime" class="table table-bordered pull-right">
                            <tr>
                                <td>{% trans "Start of event" %}:</td>
                                <td>{{ start|date:"DATETIME_FORMAT" }}</td>
                            </tr>
                            <tr>
                                <td>{% trans "Estimated end" %}:</td>
                                <td>{{ end|date:"DATETIME_FORMAT" }}</td>
                            </tr>
                        </table>
                    {% else %}
                        <a href="{% url 'config_agenda' %}" class="btn btn-mini pull-right">{% trans 'Set start time of event' %}</a>
                    {% endif %}
                {% endif %}
            </div>
        </div>

        <table id="menu-overview" class="table table-striped table-bordered">
            <tr>
                <th class="title">{% trans "Item" %}</th>
                {% if perms.agenda.can_manage_agenda %}
                    <th class="optional">{% trans "Comment" %}</th>
                {% endif %}
                {% if perms.agenda.can_see_orga_items %}
                    <th class="duration">{% trans "Duration" %}</th>
                {% endif %}
                {% if perms.agenda.can_manage_agenda or perms.projector.can_manage_projector %}
                    <th class="manage">{% trans "Actions" %}</th>
                {% endif %}
            </tr>
            <tr class="topline{% if agenda_is_active %} activeline{% endif %}">
                <td class="title">
                    {% trans "Agenda" %}
                </td>
                {% if perms.agenda.can_manage_agenda %}
                <td class="optional"></td>
                {% endif %}
                {% if perms.agenda.can_see_orga_items %}
                <td class="duration">{{ duration }} h</td>
                {% endif %}
                {% if perms.agenda.can_manage_agenda or perms.projector.can_manage_projector %}
                <td class="manage">
                {% if perms.projector.can_manage_projector %}
                    <span>
                    <a href="{% url 'projector_activate_slide' 'agenda' %}"
                        class="activate_link btn {% if agenda_is_active %}btn-primary{% endif %} btn-mini"
                        rel="tooltip" data-original-title="{% trans 'Show agenda' %}">
                        <i class="icon-facetime-video {% if agenda_is_active %}icon-white{% endif %}"></i>
                    </a>
                    </span>
                {% endif %}
                </td>
                {% endif %}
            </tr>
        </table>
        {% if items %}
        <ol class="agenda_list {% if perms.agenda.can_manage_agenda %}sortable{% endif %}">
            {% recursetree items %}
            <li class="draggable">
                {% include "agenda/item_row.html" %}
                {% if not node.is_leaf_node %}
                <ol>
                    {{ children }}
                </ol>
                {% endif %}
            </li>
            {% endrecursetree %}
        </ol>
        {% else %}
        <div class="overview_no_items">{% trans "No items available." %}</div>
        {% endif %}
    </form>
{% endblock %}
