Update javascript callbacks

This commit is contained in:
Oliver Walters 2020-10-27 21:47:24 +11:00
parent 06a3899325
commit 54d5d2899e
2 changed files with 42 additions and 30 deletions

View File

@ -11,33 +11,31 @@ InvenTree | Allocate Parts
{% include "build/tabs.html" with tab='allocate' %}
<div id='build-item-toolbar'>
{% if build.status == BuildStatus.PENDING %}
<div class='btn-group'>
<button class='btn btn-primary' type='button' id='btn-order-parts' title='Order Parts'>{% trans "Order Parts" %}</button>
<button class='btn btn-primary' type='button' id='btn-allocate' title='{% trans "Automatically allocate stock" %}'>{% trans "Auto Allocate" %}</button>
<button class='btn btn-danger' type='button' id='btn-unallocate' title='Unallocate Stock'>{% trans "Unallocate" %}</button>
</div>
{% endif %}
</div>
<!--
<table class='table table-striped table-condensed' id='build-item-list' data-toolbar='#build-item-toolbar'></table>
-->
<h4>{% trans "Allocated Stock" %}</h4>
<div class="panel-group" id="build-output-accordion" role="tablist" aria-multiselectable="true">
{% include "build/allocation_card.html" %}
</div>
{% if build.incomplete_outputs %}
<h4>{% trans "Build Ouputs" %}</h4>
<h4>{% trans "Tracked Build Ouputs" %}</h4>
<div class="panel-group" id="build-output-accordion" role="tablist" aria-multiselectable="true">
{% for item in build.incomplete_outputs %}
{% include "build/allocation_card.html" with item=item %}
{% endfor %}
</div>
<hr>
<h4>{% trans "Untracked Parts" %}</h4>
{% endif %}
<div id='build-item-toolbar'>
{% if build.status == BuildStatus.PENDING %}
<div class='btn-group'>
<button class='btn btn-primary' type='button' id='btn-order-parts' title='Order Parts'><span class='fas fa-shopping-cart'></span> {% trans "Order Parts" %}</button>
<button class='btn btn-primary' type='button' id='btn-allocate' title='{% trans "Automatically allocate stock" %}'><span class='fas fa-magic'></span> {% trans "Auto Allocate" %}</button>
<button class='btn btn-danger' type='button' id='btn-unallocate' title='Unallocate Stock'><span class='fas fa-minus-circle'></span> {% trans "Unallocate" %}</button>
</div>
{% endif %}
</div>
<table class='table table-striped table-condensed' id='build-item-list' data-toolbar='#build-item-toolbar'></table>
{% endblock %}
{% block js_ready %}
@ -50,7 +48,13 @@ InvenTree | Allocate Parts
part: {{ build.part.pk }},
};
loadBuildOutputAllocationTable(buildInfo, null);
loadBuildOutputAllocationTable(
buildInfo,
null,
{
table: '#build-item-list',
}
);
{% for item in build.incomplete_outputs %}
// Get the build output as a javascript object

View File

@ -53,14 +53,13 @@ function makeBuildOutputActionButtons(output, buildInfo) {
var html = `<div class='btn-group float-right' role='group'>`;
// Add a button to "auto allocate" against the particular build output
html += makeIconButton(
'fa-magic icon-blue', 'button-output-auto', outputId,
'{% trans "Auto-allocate stock items to this output" %}',
{
disabled: true,
}
);
// Add a button to "auto allocate" against the build
if (!output) {
html += makeIconButton(
'fa-magic icon-blue', 'button-output-auto', outputId,
'{% trans "Auto-allocate stock items to this output" %}',
);
}
if (output) {
// Add a button to "complete" the particular build output
@ -75,7 +74,7 @@ function makeBuildOutputActionButtons(output, buildInfo) {
// Add a button to "cancel" the particular build output (unallocate)
html += makeIconButton(
'fa-times-circle icon-red', 'button-output-unallocate', outputId,
'fa-minus-circle icon-red', 'button-output-unallocate', outputId,
'{% trans "Unallocate stock from build output" %}',
);
@ -239,9 +238,18 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) {
`/api/stock/${value}/`, {},
{
success: function(response) {
// How many items are actually available for the given stock item?
var available = response.quantity - response.allocated;
console.log('available: ' + available);
var field = getFieldByName('#modal-form', 'quantity');
// Allocation quantity initial value
var initial = field.attr('value');
if (available < initial) {
field.val(available);
}
}
}
)