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

{% include "part/tabs.html" with tab="allocation" %}

<h3>Part Allocation</h3>

{% if part.allocated_build_count > 0 %}
<h4>Allocated to Part Builds</h4>
<table class='table table-striped table-condensed' id='build-table'>
<tr>
    <th>Build</th>
    <th>Making</th>
    <th>Allocated</th>
    <th>Status</th>
</tr>
{% for allocation in part.build_allocation %}
<tr>
    <td><a href="{% url 'build-detail' allocation.build.id %}">{{ allocation.build.title }}</a></td>
    <td>{{ allocation.build.quantity }} &times <a href="{% url 'part-detail' allocation.build.part.id %}">{{ allocation.build.part.full_name }}</a></td>
    <td>{{ allocation.quantity }}</td>
    <td>{% include "build_status.html" with build=allocation.build %}</td>
</tr>
{% endfor %}
</table>
{% endif %}

{% endblock %}

{% block js_ready %}

    $("#build-table").bootstrapTable({
        search: true,
        sortable: true,
        columns: [
            {
                title: 'Build',
                sortable: true,
            },
            {
                title: 'Making',
                sortable: true,
            },
            {
                title: 'Allocated',
                sortable: false,
            },
            {
                title: 'Status',
                sortable: false,
            }
        ]
    });

{% endblock %}
