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

{% block menubar %}
{% include 'part/navbar.html' with tab='manufacturers' %}
{% endblock %}

{% block heading %}
{% trans "Part Manufacturers" %}
{% endblock %}

{% block details %}

<div id='button-toolbar'>
    <div class='btn-group'>
        <button class="btn btn-success" id='manufacturer-create'>
            <span class='fas fa-plus-circle'></span> {% trans "New Manufacturer Part" %}
        </button>
        <div id='opt-dropdown' class="btn-group">
            <button id='manufacturer-part-options' class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">{% trans "Options" %}<span class="caret"></span></button>
            <ul class="dropdown-menu">
                <li><a href='#' id='manufacturer-part-delete' title='{% trans "Delete manufacturer parts" %}'>{% trans "Delete" %}</a></li>
            </ul>
        </div>
    </div>
</div>

<table class="table table-striped table-condensed" id='manufacturer-table' data-toolbar='#button-toolbar'>
</table>

{% endblock %}

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

    $('#manufacturer-create').click(function () {
        launchModalForm(
            "{% url 'manufacturer-part-create' %}",
            {
                reload: true,
                data: {
                    part: {{ part.id }}
                },
                secondary: [
                    {
                        field: 'manufacturer',
                        label: '{% trans "New Manufacturer" %}',
                        title: '{% trans "Create new manufacturer" %}',
                        url: "{% url 'manufacturer-create' %}",
                    }
                ]
            });
    });

    $("#manufacturer-part-delete").click(function() {
        
        var selections = $("#manufacturer-table").bootstrapTable("getSelections");

        var parts = [];

        selections.forEach(function(item) {
            parts.push(item.pk);
        });

        launchModalForm("{% url 'manufacturer-part-delete' %}", {
            data: {
                parts: parts,
            },
            reload: true,
        });
    });

    loadManufacturerPartTable(
        "#manufacturer-table",
        "{% url 'api-manufacturer-part-list' %}",
        {
            params: {
                part: {{ part.id }},
                part_detail: false,
                manufacturer_detail: true,
            },
        }
    );

    linkButtonsToSelection($("#manufacturer-table"), ['#manufacturer-part-options'])

{% endblock %}