{% extends "trainings/training_details.html" %}
{% load i18n %}

{% block head %}
    {{ block.super }}
    {% include "cms/includes/orderable-head.html" %}
    <script type="text/javascript" src="{{ STATIC_URL }}common/js/ajaxForm.jquery.min.js"></script>
    <script type="text/javascript" src="{{ STATIC_URL }}common/js/autoAjaxForm.js"></script>
{% endblock %}

{% block section_heading %}
    <div class="clearfix">
        {% comment 'Hiding training as asked in #1747' %}
            <div class="pull-left">
                {% if training.is_editable %}
                    <a href="{{ training.options.get_edit_url }}" class="btn btn-primary dialog-box">
                        <i class="fa fa-gear"></i>
                        {% trans 'Options' %}
                    </a>
                {% endif %}
            </div>
        {% endcomment %}
        <div class="pull-right">
            {% if training.options.activate_qrcode_launcher %}
                <a href="{{ training.get_qrcodes_url }}" class="btn btn-info">
                    <i class="fa fa-qrcode"></i> QRCodes
                </a>
            {% endif %}
            {% if training.is_editable %}
                {% if training.original_version %}
                    <div class="btn-group">
                        <button class="btn btn-info dropdown-toggle" type="button" id="dropdownTranslation" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
                            {% trans "Translation" %} <span class="caret"></span>
                        </button>
                        <ul class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownTranslation">
                            <li>
                            <a href="{% url 'translation:export-content' training_uuid=training.pk %}">
                                {% trans "Export Translation" %}
                            </a>
                            </li>
                            <li>
                            <a href="{% url 'translation:import-content' training_uuid=training.pk %}">
                                {% trans "Import Translation" %}
                            </a>
                            </li>
                        </ul>
                    </div>
                {% endif %}
                <div class="btn-group">
                    <button type="button"
                            class="btn btn-info dropdown-toggle {% if not training.is_editable %}disabled{% endif %}"
                            data-toggle="dropdown">
                        {% trans 'Import content' %} <span class="caret"></span>
                    </button>
                    <ul class="dropdown-menu">
                        {% for activity_type in training.available_activity_types %}
                            {% if activity_type.import_url  %}
                            <li>
                                <a href="{{ activity_type.import_url }}">
                                    {{ activity_type.verbose_name }}
                                </a>
                            </li>
                            {% endif %}
                        {% endfor %}
                    </ul>
                </div>
                <a href="" class="btn btn-primary" data-toggle="modal" data-target="#activity-create">
                    {% trans 'Add new content' %}
                </a>
            {% endif %}
        </div>
    </div>
    <hr>
{% endblock %}

{% block section_content %}
    <table class="table table-hover table-striped orderable">{% csrf_token %}
        <thead>
            <tr>
                <th></th>
                <th>
                    {% trans 'Activity type' %}
                </th>
                <th>
                    {% trans 'Title' %}
                </th>
                <th class="text-right"><span class="orderable-message-holder"></span></th>
            </tr>
        </thead>
        <tbody>
            {% for activity in trainingactivity_list %}
                <tr>
                    <td>
                        {{ activity.sort_order_display|safe }}
                    </td>
                    <td>
                        <i class="icon-{{ activity.activity_type }}"></i>
                        {{ activity.verbose_activity_name }}
                    </td>
                    <td>
                        <strong>
                            {{ activity.name }}
                        </strong>
                    </td>
                    <td class="text-right">
                        {% if training.options.activate_qrcode_launcher %}
                            {% if activity.get_qrcode_url %}
                                <a href="{{ activity.get_qrcode_url }}" class="btn btn-info">
                                    <i class="fa fa-qrcode"></i>
                                </a>
                            {% endif %}
                        {% endif %}
                        {% if activity.get_export_url %}
                            <a href="{{ activity.get_export_url }}" class="btn btn-info">
                                <i class="fa fa-download"></i>
                            </a>
                        {% endif %}
                        {% if activity.activity_type in ideas_model_types and training.is_editable %}
                            <a href="{{ activity.get_absolute_url }}" class="btn btn-primary dialog-box">
                                {% trans 'Details' %}
                            </a>
                        {% else %}
                            <a href="{{ activity.get_absolute_url }}" class="btn btn-primary">
                                {% trans 'Details' %}
                            </a>
                        {% endif %}
                        {% if training.is_editable %}
                            {% comment %}
                            <a href="{{ activity.get_duplicate_url }}" class="dialog-box btn btn-warning">
                                <i class="fa fa-files-o"></i>
                                {% trans 'Copy' %}
                            </a>
                            {% endcomment %}
                            <a href="{{ activity.get_delete_url }}" class="dialog-box btn btn-danger">
                                <i class="fa fa-trash"></i>
                            </a>
                        {% endif %}
                    </td>
                </tr>
            {% endfor %}
        </tbody>
    </table>
    <div class="modal fade" id="activity-create">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
	                <h4 class="modal-title">{% trans 'New content' %}</h4>
                </div>
                <div class="modal-body clearfix">
                    <div class="row">
                        {% for activity_type in training.available_activity_types %}
                            <div class="col-md-3">
                                <a href="{{ activity_type.create_url }}" class="dialog-box">
                                    <div class="thumbnail activity-thumbnail text-center" style="padding-top: 20px;">
                                        <i class="icon-{{ activity_type.type }} h1"></i>
                                        <div class="caption">{{ activity_type.verbose_name }}</div>
                                    </div>
                                </a>
                            </div>
                        {% endfor %}
                    </div>
                </div>
            </div>
        </div>
    </div>
{% endblock %}
