This commit is contained in:
Oliver Walters 2021-08-30 19:52:28 +10:00
parent 2112c6a9ad
commit 6177fe0c5a
2 changed files with 52 additions and 35 deletions

View File

@ -14,6 +14,7 @@
*/ */
$.urlParam = function(name){ $.urlParam = function(name){
// eslint-disable-next-line no-useless-escape
var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href); var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
if (results==null) { if (results==null) {
return null; return null;

View File

@ -1,6 +1,33 @@
{% load i18n %} {% load i18n %}
{% load inventree_extras %} {% load inventree_extras %}
/* globals
buildStatusDisplay,
constructForm,
getFieldByName,
global_settings,
imageHoverIcon,
inventreeGet,
launchModalForm,
linkButtonsToSelection,
loadTableFilters,
makeIconBadge,
makeIconButton,
makePartIcons,
makeProgressBar,
renderLink,
setupFilterList,
*/
/* exported
editBuildOrder,
loadAllocationTable,
loadBuildOrderAllocationTable,
loadBuildOutputAllocationTable,
loadBuildPartsTable,
loadBuildTable,
*/
function buildFormFields() { function buildFormFields() {
return { return {
@ -32,7 +59,7 @@ function buildFormFields() {
} }
function editBuildOrder(pk, options={}) { function editBuildOrder(pk) {
var fields = buildFormFields(); var fields = buildFormFields();
@ -76,10 +103,10 @@ function makeBuildOutputActionButtons(output, buildInfo, lines) {
var buildId = buildInfo.pk; var buildId = buildInfo.pk;
var outputId = 'untracked';
if (output) { if (output) {
outputId = output.pk; outputId = output.pk;
} else {
outputId = 'untracked';
} }
var panel = `#allocation-panel-${outputId}`; var panel = `#allocation-panel-${outputId}`;
@ -400,10 +427,8 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) {
// Callback for 'buy' button // Callback for 'buy' button
$(table).find('.button-buy').click(function() { $(table).find('.button-buy').click(function() {
var pk = $(this).attr('pk');
var idx = $(this).closest('tr').attr('data-index'); var pk = $(this).attr('pk');
var row = $(table).bootstrapTable('getData')[idx];
launchModalForm('{% url "order-parts" %}', { launchModalForm('{% url "order-parts" %}', {
data: { data: {
@ -573,8 +598,6 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) {
element.html(html); element.html(html);
var lineItem = row;
var subTable = $(`#${subTableId}`); var subTable = $(`#${subTableId}`);
subTable.bootstrapTable({ subTable.bootstrapTable({
@ -595,7 +618,7 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) {
width: '50%', width: '50%',
field: 'quantity', field: 'quantity',
title: '{% trans "Assigned Stock" %}', title: '{% trans "Assigned Stock" %}',
formatter: function(value, row, index, field) { formatter: function(value, row) {
var text = ''; var text = '';
var url = ''; var url = '';
@ -618,7 +641,7 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) {
{ {
field: 'location', field: 'location',
title: '{% trans "Location" %}', title: '{% trans "Location" %}',
formatter: function(value, row, index, field) { formatter: function(value, row) {
if (row.stock_item_detail.location) { if (row.stock_item_detail.location) {
var text = row.stock_item_detail.location_name; var text = row.stock_item_detail.location_name;
var url = `/stock/location/${row.stock_item_detail.location}/`; var url = `/stock/location/${row.stock_item_detail.location}/`;
@ -631,7 +654,7 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) {
}, },
{ {
field: 'actions', field: 'actions',
formatter: function(value, row, index, field) { formatter: function(value, row) {
/* Actions available for a particular stock item allocation: /* Actions available for a particular stock item allocation:
* *
* - Edit the allocation quantity * - Edit the allocation quantity
@ -678,7 +701,7 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) {
field: 'sub_part_detail.full_name', field: 'sub_part_detail.full_name',
title: '{% trans "Required Part" %}', title: '{% trans "Required Part" %}',
sortable: true, sortable: true,
formatter: function(value, row, index, field) { formatter: function(value, row) {
var url = `/part/${row.sub_part}/`; var url = `/part/${row.sub_part}/`;
var thumb = row.sub_part_detail.thumbnail; var thumb = row.sub_part_detail.thumbnail;
var name = row.sub_part_detail.full_name; var name = row.sub_part_detail.full_name;
@ -709,7 +732,7 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) {
field: 'allocated', field: 'allocated',
title: '{% trans "Allocated" %}', title: '{% trans "Allocated" %}',
sortable: true, sortable: true,
formatter: function(value, row, index, field) { formatter: function(value, row) {
var allocated = 0; var allocated = 0;
if (row.allocations) { if (row.allocations) {
@ -757,7 +780,7 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) {
{ {
field: 'actions', field: 'actions',
title: '{% trans "Actions" %}', title: '{% trans "Actions" %}',
formatter: function(value, row, index, field) { formatter: function(value, row) {
// Generate action buttons for this build output // Generate action buttons for this build output
var html = `<div class='btn-group float-right' role='group'>`; var html = `<div class='btn-group float-right' role='group'>`;
@ -846,7 +869,7 @@ function loadBuildTable(table, options) {
title: '{% trans "Build" %}', title: '{% trans "Build" %}',
sortable: true, sortable: true,
switchable: true, switchable: true,
formatter: function(value, row, index, field) { formatter: function(value, row) {
var prefix = global_settings.BUILDORDER_REFERENCE_PREFIX; var prefix = global_settings.BUILDORDER_REFERENCE_PREFIX;
@ -873,7 +896,7 @@ function loadBuildTable(table, options) {
title: '{% trans "Part" %}', title: '{% trans "Part" %}',
sortable: true, sortable: true,
sortName: 'part__name', sortName: 'part__name',
formatter: function(value, row, index, field) { formatter: function(value, row) {
var html = imageHoverIcon(row.part_detail.thumbnail); var html = imageHoverIcon(row.part_detail.thumbnail);
@ -887,7 +910,7 @@ function loadBuildTable(table, options) {
field: 'quantity', field: 'quantity',
title: '{% trans "Completed" %}', title: '{% trans "Completed" %}',
sortable: true, sortable: true,
formatter: function(value, row, index, field) { formatter: function(value, row) {
return makeProgressBar( return makeProgressBar(
row.completed, row.completed,
row.quantity, row.quantity,
@ -901,7 +924,7 @@ function loadBuildTable(table, options) {
field: 'status', field: 'status',
title: '{% trans "Status" %}', title: '{% trans "Status" %}',
sortable: true, sortable: true,
formatter: function(value, row, index, field) { formatter: function(value) {
return buildStatusDisplay(value); return buildStatusDisplay(value);
}, },
}, },
@ -914,7 +937,7 @@ function loadBuildTable(table, options) {
field: 'issued_by', field: 'issued_by',
title: '{% trans "Issued by" %}', title: '{% trans "Issued by" %}',
sortable: true, sortable: true,
formatter: function(value, row, index, field) { formatter: function(value, row) {
if (value) if (value)
{ {
return row.issued_by_detail.username; return row.issued_by_detail.username;
@ -929,7 +952,7 @@ function loadBuildTable(table, options) {
field: 'responsible', field: 'responsible',
title: '{% trans "Responsible" %}', title: '{% trans "Responsible" %}',
sortable: true, sortable: true,
formatter: function(value, row, index, field) { formatter: function(value, row) {
if (value) if (value)
{ {
return row.responsible_detail.name; return row.responsible_detail.name;
@ -991,21 +1014,21 @@ function loadAllocationTable(table, part_id, part, url, required, button) {
{ {
field: 'stock_item_detail', field: 'stock_item_detail',
title: '{% trans "Stock Item" %}', title: '{% trans "Stock Item" %}',
formatter: function(value, row, index, field) { formatter: function(value) {
return '' + parseFloat(value.quantity) + ' x ' + value.part_name + ' @ ' + value.location_name; return '' + parseFloat(value.quantity) + ' x ' + value.part_name + ' @ ' + value.location_name;
} }
}, },
{ {
field: 'stock_item_detail.quantity', field: 'stock_item_detail.quantity',
title: '{% trans "Available" %}', title: '{% trans "Available" %}',
formatter: function(value, row, index, field) { formatter: function(value) {
return parseFloat(value); return parseFloat(value);
} }
}, },
{ {
field: 'quantity', field: 'quantity',
title: '{% trans "Allocated" %}', title: '{% trans "Allocated" %}',
formatter: function(value, row, index, field) { formatter: function(value, row) {
var html = parseFloat(value); 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 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>";
@ -1028,7 +1051,7 @@ function loadAllocationTable(table, part_id, part, url, required, button) {
}); });
}); });
table.on('load-success.bs.table', function(data) { table.on('load-success.bs.table', function() {
// Extract table data // Extract table data
var results = table.bootstrapTable('getData'); var results = table.bootstrapTable('getData');
@ -1106,9 +1129,6 @@ function loadBuildPartsTable(table, options={}) {
$(table).find('.button-buy').click(function() { $(table).find('.button-buy').click(function() {
var pk = $(this).attr('pk'); var pk = $(this).attr('pk');
var idx = $(this).closest('tr').attr('data-index');
var row = $(table).bootstrapTable('getData')[idx];
launchModalForm('{% url "order-parts" %}', { launchModalForm('{% url "order-parts" %}', {
data: { data: {
parts: [ parts: [
@ -1122,10 +1142,6 @@ function loadBuildPartsTable(table, options={}) {
$(table).find('.button-build').click(function() { $(table).find('.button-build').click(function() {
var pk = $(this).attr('pk'); var pk = $(this).attr('pk');
// Extract row data from the table
var idx = $(this).closest('tr').attr('data-index');
var row = $(table).bootstrapTable('getData')[idx];
newBuildOrder({ newBuildOrder({
part: pk, part: pk,
parent: options.build, parent: options.build,
@ -1139,7 +1155,7 @@ function loadBuildPartsTable(table, options={}) {
title: '{% trans "Part" %}', title: '{% trans "Part" %}',
switchable: false, switchable: false,
sortable: true, sortable: true,
formatter: function(value, row, index, field) { formatter: function(value, row) {
var url = `/part/${row.sub_part}/`; var url = `/part/${row.sub_part}/`;
var html = imageHoverIcon(row.sub_part_detail.thumbnail) + renderLink(row.sub_part_detail.full_name, url); var html = imageHoverIcon(row.sub_part_detail.thumbnail) + renderLink(row.sub_part_detail.full_name, url);
@ -1177,7 +1193,7 @@ function loadBuildPartsTable(table, options={}) {
switchable: false, switchable: false,
field: 'sub_part_detail.stock', field: 'sub_part_detail.stock',
title: '{% trans "Available" %}', title: '{% trans "Available" %}',
formatter: function(value, row, index, field) { formatter: function(value, row) {
return makeProgressBar( return makeProgressBar(
value, value,
row.quantity * options.build_remaining, row.quantity * options.build_remaining,
@ -1201,7 +1217,7 @@ function loadBuildPartsTable(table, options={}) {
field: 'actions', field: 'actions',
title: '{% trans "Actions" %}', title: '{% trans "Actions" %}',
switchable: false, switchable: false,
formatter: function(value, row, index, field) { formatter: function(value, row) {
// Generate action buttons against the part // Generate action buttons against the part
var html = `<div class='btn-group float-right' role='group'>`; var html = `<div class='btn-group float-right' role='group'>`;
@ -1228,7 +1244,7 @@ function loadBuildPartsTable(table, options={}) {
sortable: true, sortable: true,
search: true, search: true,
onPostBody: setupTableCallbacks, onPostBody: setupTableCallbacks,
rowStyle: function(row, index) { rowStyle: function(row) {
var classes = []; var classes = [];
// Shade rows differently if they are for different parent parts // Shade rows differently if they are for different parent parts