{% extends "part/part_base.html" %}
{% load static %}
{% load i18n %}
{% block details %}

{% include 'part/tabs.html' with tab='tests' %}

<h4>{% trans "Part Test Templates" %}</h4>
<hr>

<div id='button-toolbar'>
    <div class='button-toolbar container-fluid' style="float: right;">
        <div class='btn-group' role='group'>
            <button type='button' class='btn btn-success' id='add-test-template'>{% trans "Add Test Template" %}</button>
        </div>
        <div class='filter-list' id='filter-list-parttests'>
            <!-- Empty div -->
        </div>
    </div>
</div>

<table class='table table-striped table-condensed' data-toolbar='#button-toolbar' id='test-template-table'></table>

{% endblock %}

{% block js_ready %}
{{ block.super }}

loadPartTestTemplateTable(
    $("#test-template-table"),
    {
        part: {{ part.pk }},
        params: {
            part: {{ part.pk }},
        }
    }
);

function reloadTable() {
    $("#test-template-table").bootstrapTable("refresh");
}

$("#add-test-template").click(function() {
    launchModalForm(
        "{% url 'part-test-template-create' %}",
        {
            data: {
                part: {{ part.id }},
            },
            success: reloadTable,
        }
    );
});

$("#test-template-table").on('click', '.button-test-edit', function() {
    var button = $(this);

    var url = `/part/test-template/${button.attr('pk')}/edit/`;

    launchModalForm(url, {
        success: reloadTable,
    });
});

$("#test-template-table").on('click', '.button-test-delete', function() {
    var button = $(this);

    var url = `/part/test-template/${button.attr('pk')}/delete/`;

    launchModalForm(url, {
        success: reloadTable,
    });
});

{% endblock %}