mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-18 13:05:42 +00:00
Add translation layer for build.js
This commit is contained in:
@ -105,7 +105,6 @@ InvenTree
|
||||
<script type='text/javascript' src="{% static 'script/inventree/bom.js' %}"></script>
|
||||
<script type='text/javascript' src="{% static 'script/inventree/filters.js' %}"></script>
|
||||
<script type='text/javascript' src="{% static 'script/inventree/tables.js' %}"></script>
|
||||
<script type='text/javascript' src="{% static 'script/inventree/build.js' %}"></script>
|
||||
<script type='text/javascript' src="{% static 'script/inventree/modals.js' %}"></script>
|
||||
<script type='text/javascript' src="{% static 'script/inventree/order.js' %}"></script>
|
||||
<script type='text/javascript' src="{% static 'script/inventree/company.js' %}"></script>
|
||||
@ -114,6 +113,7 @@ InvenTree
|
||||
|
||||
<script type='text/javascript' src="{% url 'part.js' %}"></script>
|
||||
<script type='text/javascript' src="{% url 'stock.js' %}"></script>
|
||||
<script type='text/javascript' src="{% url 'build.js' %}"></script>
|
||||
|
||||
<script type='text/javascript' src="{% static 'fontawesome/js/solid.js' %}"></script>
|
||||
<script type='text/javascript' src="{% static 'fontawesome/js/brands.js' %}"></script>
|
||||
|
178
InvenTree/templates/js/build.js
Normal file
178
InvenTree/templates/js/build.js
Normal file
@ -0,0 +1,178 @@
|
||||
{% load i18n %}
|
||||
|
||||
function loadBuildTable(table, options) {
|
||||
// Display a table of Build objects
|
||||
|
||||
var params = options.params || {};
|
||||
|
||||
var filters = loadTableFilters("build");
|
||||
|
||||
for (var key in params) {
|
||||
filters[key] = params[key];
|
||||
}
|
||||
|
||||
setupFilterList("build", table);
|
||||
|
||||
table.inventreeTable({
|
||||
method: 'get',
|
||||
formatNoMatches: function() {
|
||||
return "{% trans "No builds matching query" %}";
|
||||
},
|
||||
url: options.url,
|
||||
queryParams: filters,
|
||||
groupBy: false,
|
||||
original: params,
|
||||
columns: [
|
||||
{
|
||||
field: 'pk',
|
||||
title: 'ID',
|
||||
visible: false,
|
||||
},
|
||||
{
|
||||
field: 'title',
|
||||
title: '{% trans "Build" %}',
|
||||
sortable: true,
|
||||
formatter: function(value, row, index, field) {
|
||||
return renderLink(value, '/build/' + row.pk + '/');
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'part',
|
||||
title: '{% trans "Part" %}',
|
||||
sortable: true,
|
||||
formatter: function(value, row, index, field) {
|
||||
|
||||
var name = row.part_detail.full_name;
|
||||
|
||||
return imageHoverIcon(row.part_detail.thumbnail) + renderLink(name, '/part/' + row.part + '/');
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'quantity',
|
||||
title: '{% trans "Quantity" %}',
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
title: '{% trans "Status" %}',
|
||||
sortable: true,
|
||||
formatter: function(value, row, index, field) {
|
||||
return buildStatusDisplay(value);
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'creation_date',
|
||||
title: '{% trans "Created" %}',
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
field: 'completion_date',
|
||||
title: '{% trans "Completed" %}',
|
||||
sortable: true,
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function updateAllocationTotal(id, count, required) {
|
||||
|
||||
count = parseFloat(count);
|
||||
|
||||
$('#allocation-total-'+id).html(count);
|
||||
|
||||
var el = $("#allocation-panel-" + id);
|
||||
el.removeClass('part-allocation-pass part-allocation-underallocated part-allocation-overallocated');
|
||||
|
||||
if (count < required) {
|
||||
el.addClass('part-allocation-underallocated');
|
||||
} else if (count > required) {
|
||||
el.addClass('part-allocation-overallocated');
|
||||
} else {
|
||||
el.addClass('part-allocation-pass');
|
||||
}
|
||||
}
|
||||
|
||||
function loadAllocationTable(table, part_id, part, url, required, button) {
|
||||
|
||||
// Load the allocation table
|
||||
table.bootstrapTable({
|
||||
url: url,
|
||||
sortable: false,
|
||||
formatNoMatches: function() { return '{% trans "No parts allocated for" %} ' + part; },
|
||||
columns: [
|
||||
{
|
||||
field: 'stock_item_detail',
|
||||
title: '{% trans "Stock Item" %}',
|
||||
formatter: function(value, row, index, field) {
|
||||
return '' + parseFloat(value.quantity) + ' x ' + value.part_name + ' @ ' + value.location_name;
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'stock_item_detail.quantity',
|
||||
title: '{% trans "Available" %}',
|
||||
formatter: function(value, row, index, field) {
|
||||
return parseFloat(value);
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'quantity',
|
||||
title: '{% trans "Allocated" %}',
|
||||
formatter: function(value, row, index, field) {
|
||||
var html = parseFloat(value);
|
||||
|
||||
var bEdit = "<button class='btn item-edit-button btn-sm' type='button' title='{% trans "Edit stock allocation" %}' url='/build/item/" + row.pk + "/edit/'><span class='fas fa-edit'></span></button>";
|
||||
var bDel = "<button class='btn item-del-button btn-sm' type='button' title='{% trans "Delete stock allocation" %}' url='/build/item/" + row.pk + "/delete/'><span class='fas fa-trash-alt icon-red'></span></button>";
|
||||
|
||||
html += "<div class='btn-group' style='float: right;'>" + bEdit + bDel + "</div>";
|
||||
|
||||
return html;
|
||||
}
|
||||
}
|
||||
],
|
||||
});
|
||||
|
||||
// Callback for 'new-item' button
|
||||
button.click(function() {
|
||||
launchModalForm(button.attr('url'), {
|
||||
success: function() {
|
||||
table.bootstrapTable('refresh');
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
table.on('load-success.bs.table', function(data) {
|
||||
// Extract table data
|
||||
var results = table.bootstrapTable('getData');
|
||||
|
||||
var count = 0;
|
||||
|
||||
for (var i = 0; i < results.length; i++) {
|
||||
count += parseFloat(results[i].quantity);
|
||||
}
|
||||
|
||||
updateAllocationTotal(part_id, count, required);
|
||||
});
|
||||
|
||||
// Button callbacks for editing and deleting the allocations
|
||||
table.on('click', '.item-edit-button', function() {
|
||||
var button = $(this);
|
||||
|
||||
launchModalForm(button.attr('url'), {
|
||||
success: function() {
|
||||
table.bootstrapTable('refresh');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
table.on('click', '.item-del-button', function() {
|
||||
var button = $(this);
|
||||
|
||||
launchModalForm(button.attr('url'), {
|
||||
success: function() {
|
||||
table.bootstrapTable('refresh');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
}
|
Reference in New Issue
Block a user