{% extends "order/sales_order_base.html" %}

{% load inventree_extras %}
{% load i18n %}
{% load static %}

{% block details %}

{% include 'order/so_tabs.html' with tab='attachments' %}

<h4>{% trans "Sales Order Attachments" %}</h4>

<hr>

{% include "attachment_table.html" with attachments=order.attachments.all %}

{% endblock %}

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

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

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

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

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

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

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

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

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

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

{% endblock %}