{% extends "page_base.html" %}

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

{% block page_title %}
{% inventree_title %}{% if title %} | {{ title }}{% endif %}
{% endblock page_title %}

{% block heading %}
{{ title }}
{% endblock heading %}

{% block actions %}
{% if pagetype == 'manufacturers' and roles.purchase_order.add or pagetype == 'suppliers' and roles.purchase_order.add or pagetype == 'customers' and roles.sales_order.add %}
<button type='button' class="btn btn-success" id='new-company'>
    <span class='fas fa-plus-circle'></span> {{ button_text }}
</button>
{% endif %}
{% endblock actions %}

{% block page_info %}

<div class='panel-content'>

    <div id='company-button-toolbar'>
        {% include "filter_list.html" with id='company' %}
    </div>

    <table class='table table-striped table-condensed' id='company-table' data-toolbar='#company-button-toolbar'>
    </table>
</div>

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

    $('#new-company').click(function() {

        var fields = companyFormFields();

        // Field overrides
        fields.is_supplier.value = {% if pagetype == 'suppliers' %}true{% else %}false{% endif %};
        fields.is_manufacturer.value = {% if pagetype == 'manufacturers' %}true{% else %}false{% endif %};
        fields.is_customer.value = {% if pagetype == 'customers' %}true{% else %}false{% endif %};

        createCompany({
            fields: fields,
        });
    });

    loadCompanyTable("#company-table", "{% url 'api-company-list' %}",
        {
            pagetype: '{{ pagetype }}',
            params: {
                {% for key,value in filters.items %}{{ key }}: "{{ value }}",{% endfor %}
            }
        }
    );

{% endblock js_ready %}
