{% extends "layout/2-columns-left.html" %}
{% load i18n waffle_tags %}

{% block head %}
    {{ block.super }}

    <link rel="stylesheet" href="{{ STATIC_URL }}css/jquery.datetimepicker.css" type="text/css" media="screen" charset="utf-8" />

    <script type="text/javascript" src="{{ STATIC_URL }}common/js/ajax-modal.js"></script>
    <script type="text/javascript" src="{{ STATIC_URL }}common/js/modernizr.min.js"></script>
    <script type="text/javascript" src="{{ STATIC_URL }}trainings/js/jquery.datetimepicker.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            // Checking support for <input type="date"> using Modernizr:
            // http://modernizr.com/
            if (!Modernizr.inputtypes.date) {
                var options = {
                    format: '{{ DATE_INPUT_FORMAT }}',
                    lang:'{{ LANGUAGE_CODE }}',
                    timepicker: false
                };
                $( "#id_start_date_0" ).datetimepicker(options);
                $( "#id_start_date_1" ).datetimepicker(options);
            }
        });
    </script>
{% endblock %}

{% block subtitle %}
    {% trans 'Sessions list' %}
{% endblock %}

{% block actions %}
    {% if user.is_staff %}
        {% switch 'enable_assessments' %}
            <div style="display: inline-block" id="sessions-scores-exportation-wrapper" data-toggle="popover">
                <a href="{% url 'assessments:export_sessions_scores' %}?{{ view.request.GET.urlencode }}"
                   class="btn btn-info {% if not selected_training.is_assessing %}disabled{% endif %}">
                    <i class="fa fa-download"></i> {% trans 'Export Assessment Scores' %}
                </a>
            </div>
        {% endswitch %}
        <a href="{% url 'trainings:session-add' %}" class="btn btn-primary">
            <i class="fa fa-plus"></i> {% trans 'Create a session' %}
        </a>
    {% endif %}
{% endblock %}

{% block column_left %}
    <form action="" method="get">
        {% include 'extras/form.html' with form=filter.form display='inline' %}
        <div class="clearfix">
            <a href="{% url 'trainings:session-list' %}" class="pull-left btn btn-warning">
                {% trans 'Reset' %}
            </a>
            <input type="submit" class="btn btn-primary pull-right" value="{% trans 'Apply' %}" />
        </div>
    </form>
{% endblock %}

{% block column_main %}
    {% if trainingsession_list %}
        <div class="panel panel-default">
            <table class="table table-hover table-bordered">
                <thead>
                    <tr>
                        <th>{% trans 'Training' %}</th>
                        <th>{% trans 'Trainer' %}</th>
                        <th>{% trans 'Start date' %}</th>
                        <th>{% trans 'End date' %}</th>
                        <th>{% trans 'Participants' %}</th>
                        <th></th>
                    </tr>
                </thead>
                <tbody>
                    {% for session in trainingsession_list %}
                        {% spaceless %}
                            <tr class="
                                {% if session.state == session.STATE_CHOICES.CLOSED %}
                                    danger
                                {% elif session.state == session.STATE_CHOICES.DURING %}
                                    success
                                {% elif session.state != session.STATE_CHOICES.NOT_OPEN %}
                                    info
                                {% endif %}
                            ">
                        {% endspaceless %}
                        <td>
                            {% if user.is_staff %}
                                <a href="{{ session.get_absolute_url }}">
                                    {{ session.training.name }}
                                </a>
                            {% else %}
                                {{ session.training.name }}
                            {% endif %}
                        </td>
                        <td>{{ session.trainer.last_name }}</td>
                        <td>{{ session.start_date }}</td>
                        <td>{{ session.end_date }}</td>
                        <td>{{ session.users.all.count }}</td>
                        <td>
                            <div class="btn-group">
                                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                                    {% trans "Actions" %}
                                    <span class="caret"></span>
                                </button>
                                <ul class="dropdown-menu pull-right">
                                    {% if user.is_trainee and user in session.users.all %}
                                        {% comment 'Commenting this until we make it work' %}
                                        <li>
                                            <a href="{% url 'trainings:session_trainee_content' session_uuid=session.id trainee_id=user.id %}">
                                                <i class="fa fa-file"></i> {% trans 'Download contents' %}
                                            </a>
                                        </li>
                                        <li>
                                            <a href="{% url 'trainings:training_contents' training_uuid=session.training.id %}">
                                                <i class="fa fa-file"></i> {% trans 'View contents' %}
                                            </a>
                                        </li>
                                        {% endcomment %}
                                    {% endif %}
                                    {% if user.is_staff %}
                                        {% comment %}
                                            <li>
                                              <a href="{% url 'accounts:users_import' session_id=session.id %}">
                                                <i class="fa fa-file"></i> {% trans 'Import trainees' %}</a>
                                            </li>
                                            <li>
                                              <a href="{% url 'trainings:session_stats' session_uuid=session.id %}">
                                                <i class="fa fa-arrow-down"></i> {% trans 'Export quizz' %}</a>
                                            </li>
                                        {% endcomment %}
                                        <li>
                                            <a href="{{ session.get_evaluation_export_statistics_url }}">
                                                <i class="fa fa-arrow-down"></i> {% trans 'Export eval' %}
                                            </a>
                                        </li>
                                        <li>
                                            <a href="{{ session.get_workshop_export_statistics_url }}">
                                                <i class="fa fa-arrow-down"></i> {% trans 'Export quizz' %}
                                            </a>
                                        </li>
                                        <li>
                                            <a href="{{ session.get_podium_url }}">
                                                <i class="fa fa-signal"></i> {% trans 'Podium' %}
                                            </a>
                                        </li>
                                        {% if session.state == session.STATE_CHOICES.DURING %}
                                            <li>
                                                <a href="{{ session.get_token_url }}" class="dialog-box">
                                                    <i class="fa fa-key"></i>
                                                    {% trans 'Token' %}
                                                </a>
                                            </li>
                                        {% endif %}
                                        {% comment 'Commenting this until we make it work' %}
                                            <li>
                                                <a href="{{ session.get_whoswho_url }}">
                                                    <i class="fa fa-th"></i> {% trans 'Whoswho' %}
                                                </a>
                                            </li>
                                        {% endcomment %}
                                        <li>
                                            <a href="{% url 'metaplans:list_by_session' session_id=session.id %}">
                                                <i class="fa fa-th-large"></i> {% trans 'Metaplan' %}
                                            </a>
                                        </li>
                                        <li>
                                            <a href="{{ session.get_brainstormer_list_url }}">
                                                <i class="fa fa-cogs"></i> {% trans 'Brainstormers' %}
                                            </a>
                                        </li>
                                        {% if user.is_superuser or session.trainer == user %}
                                            {% if session.state != session.STATE_CHOICES.CLOSED %}
                                                <li>
                                                    <a href="{{ session.get_close_url }}" class="dialog-box">
                                                        <i class="fa fa-close"></i> {% trans 'Close' %}
                                                    </a>
                                                </li>
                                            {% endif %}
                                        {% endif %}
                                    {% endif %}
                                </ul>
                            </div>
                        </td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
        <div class="panel-footer">
            {% include 'extras/pagination.html' %}
        </div>
    </div>
    {% else %}
        <div class="alert alert-info">
            {% trans 'No sessions to show.' %}
        </div>
    {% endif %}
    <script type="text/javascript">
        $(document).ready(function(){
            // We implement a popover for sessions scores exportation button
            {% if not selected_training.is_assessing %}
                $('#sessions-scores-exportation-wrapper').popover({
                    trigger: 'hover',
                    content: '{% trans "Please, select an assessing training to activate consolidated export." %}',
                    placement: 'bottom',
                });
            {% endif %}
        });
    </script>
{% endblock %}
