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

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

<h4>Part Stock</h4>
<hr>

{% if part.is_template %}
<div class='alert alert-info alert-block'>
    Showing stock for all variants of <i>{{ part.full_name }}</i>
</div>
{% endif %}

{% include "stock_table.html" %}

{% endblock %}

{% block js_load %}
{{ block.super }}
{% endblock %}
{% block js_ready %}
{{ block.super }}

    $('#add-stock-item').click(function () {
        launchModalForm(
                        "{% url 'stock-item-create' %}",
                        {
                            reload: true,
                            data: {
                                part: {{ part.id }}
                            }
                        });
    });

    loadStockTable($("#stock-table"), {
        params: {
            part: {{ part.id }},
            location_detail: true,
            part_detail: true,
        },
        groupByField: 'location',
        buttons: [
            '#stock-options',
        ],
        url: "{% url 'api-stock-list' %}",
    });

    $('#item-create').click(function () {
        launchModalForm("{% url 'stock-item-create' %}", {
            reload: true,
            data: {
                part: {{ part.id }}
            },
            secondary: [
                {
                    field: 'part',
                    label: 'New Part',
                    title: 'Create New Part',
                    url: "{% url 'part-create' %}",
                },
                {
                    field: 'supplier_part',
                    label: 'New Supplier Part',
                    title: 'Create new Supplier Part',
                    url: "{% url 'supplier-part-create' %}",
                    data: {
                        part: {{ part.id }}
                    },
                },
                {
                    field: 'location',
                    label: 'New Location',
                    title: 'Create New Location',
                    url: "{% url 'stock-location-create' %}",
                }
            ]
        });

        return false;
    });

{% endblock %}