{% extends "base.html" %}

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

{% block title %}{% trans "Participants" %} – {{ 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 "Participants" %}
        <small class="pull-right">
        {% if perms.participant.can_manage_participant %}
            <a href="{% url 'user_new' %}" class="btn btn-mini btn-primary" rel="tooltip" data-original-title="{% trans 'New participant' %}"><i class="icon-plus icon-white"></i> {% trans "New" %}</a>
            <a href="{% url 'user_new_multiple' %}" class="btn btn-mini" rel="tooltip" data-original-title="{% trans 'New multiple participants' %}"><i class="icon-plus"></i> {% trans 'New multiple' %}</a>
            <a href="{% url 'user_group_overview' %}" class="btn btn-mini" rel="tooltip" data-original-title="{% trans 'All groups' %}"><i class="icon-group"></i> {% trans "Groups" %}</a>
            <a href="{% url 'user_csv_import' %}" class="btn btn-mini" rel="tooltip" data-original-title="{% trans 'Import participants' %}"><i class="icon-import"></i> {% trans 'Import' %}</a>
        {% endif %}
        {% if perms.participant.can_see_participant and perms.participant.can_manage_participant %}
            <div class="btn-group">
                <a data-toggle="dropdown" class="btn btn-mini dropdown-toggle">
                    <i class="icon-print"></i> PDF <span class="caret"></span>
                </a>
                <ul class="dropdown-menu  pull-right">
                    {% url 'user_settings' as url_usersettings %}
                    <li><a href="{% url 'user_print' %}" target="_blank"><i class="icon-list"></i> {% trans 'List of participants' %}</a></li>
                    <li><a href="{% url 'print_passwords' %}" target="_blank"><i class="icon-th-large"></i> {% trans 'List of access data' %}</a></li>
                </ul>
            </div>
        {% else %}
            <a href="{% url 'user_print' %}" class="btn btn-mini" rel="tooltip" data-original-title="{% trans 'Print list of participants as PDF' %}" target="_blank"><i class="icon-print"></i> PDF</a>
        {% endif %}
        </small>
    </h1>

    <table id="dataTable" class="table table-striped table-bordered" cellpadding="0" cellspacing="0" border="0">
    <thead>
        <tr>
            <th>{% trans "Present" %}</th>
            <th class="optional">{% trans "Title" %}</th>
            <th>{% trans "Name" %}</th>
            <th class="optional">{% trans "Structure level" %}</th>
            <th class="optional">{% trans "Group" %}</th>
            <th class="optional">{% trans "Committee" %}</th>
            {% if perms.participant.can_manage_participant %}
                <th class="optional">{% trans "Comment" %}</th>
                <th class="optional">{% trans "Last Login" %}</th>
                <th class="mini_width">{% trans "Actions" %}</th>
            {% endif %}
        </tr>
    </thead>
    <tbody>
        {% for user in users %}
            <tr class="{% if user.is_active_slide %}activeline{% endif %}">
                <td>{% if perms.participant.can_manage_participant %}
                        {% if user != request_user %}
                         <a href="{% url 'user_status_toggle' user.id %}"
                           class="status_link btn btn-mini {% if user.is_active %}btn-success{% endif %}"
                           rel="tooltip" data-original-title="{% if user.is_active %}{% trans 'present' %}{% else %}{% trans 'absent' %}{% endif %}">
                             <i class="{% if user.is_active %}icon-on{% else %}icon-off{% endif %}"></i>
                         </a>
                         {% endif %}
                    {% else %}
                        <span class="status_link">
                         <i class="status_link {% if user.is_active %}icon-on{% else %}icon-off{% endif %} tooltip-bottom"
                            data-original-title="{% if user.is_active %}{% trans 'present' %}{% else %}{% trans 'absent' %}{% endif %}"></i>
                    {% endif %}
                </td>
                <td class="optional">{{ user.title }}</td>
                <td>
                    {% if 'participant_sort_users_by_first_name'|get_config %}
                        <a href="{% url 'user_view' user.id %}">{{ user.first_name }} {{ user.last_name }}</a>
                    {% else %}
                        <a href="{% url 'user_view' user.id %}">{{ user.last_name }}{% if user.last_name and user.first_name %},{% endif %} {{ user.first_name }}</a>
                    {% endif %}
                </td>
                <td class="optional">{{ user.structure_level }}</td>
                <td class="optional">
                    {% for group in user.groups.all %}
                        {% if group.pk != 2 %}
                            {% trans group.name %}
                            {% if not forloop.last %}<br>{% endif %}
                        {% endif %}
                    {% endfor %}
                </td>
                <td class="optional">{{ user.committee }}</td>
                {% if perms.participant.can_manage_participant %}
                    <td class="optional">
                        {% if user.comment %}
                            <a class="btn btn-mini" rel="popover" data-content="{{ user.comment|linebreaks }}">
                                <i class="icon icon-search"></i>
                            </a>
                        {% endif %}
                    </td>
                    <td class="optional">
                        {% if user.last_login > user.date_joined %}
                            {{ user.last_login }}
                        {% endif %}
                    </td>
                    <td>
                        <span style="width: 1px; white-space: nowrap;">
                            {% if perms.core.can_manage_projector %}
                                <a href="{{ user|absolute_url:'projector' }}" class="activate_link btn {% if user.is_active_slide %}btn-primary{% endif %} btn-mini"
                                    rel="tooltip" data-original-title="{% trans 'Show participant' %}">
                                    <i class="icon-facetime-video {% if user.is_active_slide %}icon-white{% endif %}"></i>
                                </a>
                            {% endif %}
                            <a href="{% url 'user_edit' user.id %}" rel="tooltip" data-original-title="{% trans 'Edit' %}"
                                class="btn btn-mini">
                                <i class="icon-pencil"></i>
                            </a>
                            {% if user != request_user %}
                            <a href="{% url 'user_delete' user.id %}" rel="tooltip" data-original-title="{% trans 'Delete' %}"
                                class="btn btn-mini">
                                <i class="icon-remove"></i>
                            </a>
                            {% endif %}
                        </span>
                    </td>
                {% endif %}
            </tr>
        {% endfor %}
    </tbody>
    </table>
{% endblock %}
