{% extends "stock/location.html" %}

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

{% block menubar %}
{% include "stock/location_navbar.html" with tab="sublocations" %}
{% endblock %}


{% block location_content %}

<div class='panel panel-default panel-inventree'>
    <div class='panel-heading'>
        <h4>{% trans "Sublocations" %}</h4>
    </div>

    <div id='button-toolbar'>
        <div class='button-toolbar container-fluid' style='float: right;'>
            <!-- Printing actions menu -->
            <div class='btn-group'>
                <button id='location-print-options' class='btn btn-primary dropdown-toggle' type='button' data-toggle="dropdown" title='{% trans "Printing Actions" %}'>
                    <span class='fas fa-print'></span> <span class='caret'></span>
                </button>
                <ul class='dropdown-menu'>
                    <li><a href='#' id='multi-location-print-label' title='{% trans "Print labels" %}'><span class='fas fa-tags'></span> {% trans "Print labels" %}</a></li>
                </ul>
            </div>
            <div class='filter-list' id='filter-list-location'>
                <!-- An empty div in which the filter list will be constructed -->
            </div>
        </div>
    </div>
    
    <table class='table table-striped table-condensed' data-toolbar='#button-toolbar' id='sublocation-table'></table>
</div>

{% endblock %}

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

loadStockLocationTable($('#sublocation-table'), {
    params: {
        {% if location %}
        parent: {{ location.pk }},
        {% else %}
        parent: 'null',
        {% endif %}
    }
});

linkButtonsToSelection(
    $('#sublocation-table'),
    [
        '#location-print-options',
    ]
);

$('#multi-location-print-label').click(function() {

    var selections = $('#sublocation-table').bootstrapTable('getSelections');

    var locations = [];

    selections.forEach(function(loc) {
        locations.push(loc.pk);
    });

    printStockLocationLabels(locations);
})

{% endblock %}