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

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

<h4>{% trans "Part Attachments" %}</h4>

<hr>

{% include "attachment_table.html" with attachments=part.part_attachments %}

{% endblock %}

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

    enableDragAndDrop(
        '#attachment-dropzone',
        "{% url 'part-attachment-create' %}",
        {
            data: {
                part: {{ part.id }},
            },
            label: 'attachment',
            success: function(data, status, xhr) {
                location.reload();
            }
        }
    );

    $("#new-attachment").click(function() {
        launchModalForm("{% url 'part-attachment-create' %}?part={{ part.id }}",
            {
                reload: true, 
            });
    });

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

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

        launchModalForm(url, 
            {
                reload: true,
            });
    });

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

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

        launchModalForm(url, {
            success: function() {
                location.reload();
            }
        });
    });

    $("#attachment-table").inventreeTable({
    });

{% endblock %}