{% extends 'base_training.html' %}

{% load url_replace from filters %}
{% load paginator from filters %}
{% load linkornone from filters %}
{% load button from filters %}
{% load colour_from_depth from tags %}
{% load static %}

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

{% block preload_js %}
<script src="{% static 'js/selects.js' %}"></script>
{% endblock %}

{% block js %}
<script src="{% static 'js/tooltip.js' %}"></script>
<script>
    $('document').ready(function(){
        $('#edit').click(function (e) {
         e.preventDefault();
         var url = $(this).attr("href");
         $.ajax({
            url: url,
            success: function(){
                $link = $(this);
                    // Anti modal inception
                    if ($link.parents('#modal').length === 0) {
                        modaltarget = $link.data('target');
                        modalobject = "";
                        $('#modal').load(url, function (e) {
                            $('#modal').modal();
                        });
                    }
                }
        });
     });
    });
</script>
{% endblock %}

{% block content %}
<p class="text-muted text-right">Search by supervisor name, item name or item ID</p>{% include 'partials/list_search.html' %}
<div class="row pt-2">
    <div class="col">
        <div class="table-responsive">
            <table class="table table-striped table-sm">
                <thead>
                    <tr>
                        <th scope="col">Training Item</th>
                        <th>Depth</th>
                        <th>Date</th>
                        <th>Supervisor</th>
                        <th>Notes</th>
                        {% if request.user.is_supervisor %}
                        <th></th>
                        {% endif %}
                    </tr>
                </thead>
                <tbody>
                {% for object in object_list %}
                    <tr id="row_item" {% if request.user.is_superuser and not object.item.active %}class="text-warning"{%endif%}>
                        <th scope="row" class="align-middle" id="cell_name">{{ object.item }}</th>
                        <td class="table-{% colour_from_depth object.depth %}">{{ object.get_depth_display }}</td>
                        <td>{{ object.date }}</td>
                        <td><a href="{{ object.supervisor.get_absolute_url}}">{{ object.supervisor }}</a></td>
                        <td>{{ object.notes }}</td>
                        {% if request.user.is_supervisor %}
                        <td>{% button 'edit' 'edit_qualification' object.pk id="edit" %}</td>
                        {% endif %}
                    </tr>
                {% empty %}
                <tr class="table-warning">
                    <td colspan="6" class="text-center">Nothing found</td>
                </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>
<div class="row">
    <div class="col text-right">
        {% include 'partials/last_edited.html' with target="trainee_history" object=trainee %}
    </div>
</div>
{% endblock %}
