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

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

{% block details %}

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

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

<hr>

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

{% endblock %}

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

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

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

$("#attachment-table").on('click', '.attachment-edit-button', function() {
    var button = $(this);
    
    var url = `/order/purchase-order/attachment/${button.attr('pk')}/edit/`;

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

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

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

    console.log("url: " + url);

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

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

{% endblock %}