This commit is contained in:
Oliver Walters 2021-08-30 14:07:34 +10:00
parent 65874447ed
commit c846aeb60f
5 changed files with 157 additions and 68 deletions

View File

@ -1,5 +1,5 @@
env: env:
commonjs: true commonjs: false
es6: true es6: true
browser: true browser: true
es2021: true es2021: true
@ -7,7 +7,7 @@ env:
extends: 'eslint:recommended' extends: 'eslint:recommended'
parserOptions: parserOptions:
ecmaVersion: 12 ecmaVersion: 12
sourceType: module sourceType: 'script'
rules: rules:
accessor-pairs: error accessor-pairs: error
array-bracket-newline: 'off' array-bracket-newline: 'off'

View File

@ -1,5 +1,18 @@
{% load i18n %} {% load i18n %}
/* exported
blankImage,
deleteButton,
editButton,
imageHoverIcon,
makeIconBadge,
makeIconButton,
makeProgressBar,
renderLink,
select2Thumbnail,
yesNoLabel,
*/
function yesNoLabel(value) { function yesNoLabel(value) {
if (value) { if (value) {
return `<span class='label label-green'>{% trans "YES" %}</span>`; return `<span class='label label-green'>{% trans "YES" %}</span>`;
@ -9,9 +22,14 @@ function yesNoLabel(value) {
} }
/* function editButton(url, text='{% trans "Edit" %}') {
* A set of simple helper functions return "<button class='btn btn-success edit-button btn-sm' type='button' url='" + url + "'>" + text + "</button>";
*/ }
function deleteButton(url, text='{% trans "Delete" %}') {
return "<button class='btn btn-danger delete-button btn-sm' type='button' url='" + url + "'>" + text + "</button>";
}
function blankImage() { function blankImage() {
@ -165,5 +183,5 @@ function renderLink(text, url, options={}) {
text = `${text_start}...${text_end}`; text = `${text_start}...${text_end}`;
} }
return '<a href="' + url + '">' + text + '</a>'; return `<a href="${url}">${text}</a>`;
} }

View File

@ -2,6 +2,63 @@
{% load inventree_extras %} {% load inventree_extras %}
{% load status_codes %} {% load status_codes %}
/* globals
attachSelect,
attachToggle,
blankImage,
enableField,
clearField,
clearFieldOptions,
closeModal,
constructFormBody,
constructNumberInput,
createNewModal,
getFormFieldValue,
global_settings,
handleFormErrors,
imageHoverIcon,
inventreeDelete,
inventreeGet,
inventreePut,
launchModalForm,
linkButtonsToSelection,
loadTableFilters,
makeIconBadge,
makeIconButton,
makeOptionsList,
makePartIcons,
modalEnable,
modalSetContent,
modalSetTitle,
modalSubmit,
moment,
openModal,
printStockItemLabels,
printTestReports,
renderLink,
reloadFieldOptions,
scanItemsIntoLocation,
showAlertDialog,
setFieldValue,
setupFilterList,
showApiError,
stockStatusDisplay,
*/
/* exported
createNewStockItem,
exportStock,
loadInstalledInTable,
loadStockLocationTable,
loadStockTable,
loadStockTestResultsTable,
loadStockTrackingTable,
loadTableFilters,
locationFields,
removeStockRow,
stockStatusCodes,
*/
function locationFields() { function locationFields() {
return { return {
@ -209,7 +266,7 @@ function adjustStock(action, items, options={}) {
title: readonly ? '{% trans "Quantity cannot be adjusted for serialized stock" %}' : '{% trans "Specify stock quantity" %}', title: readonly ? '{% trans "Quantity cannot be adjusted for serialized stock" %}' : '{% trans "Specify stock quantity" %}',
} }
) )
}; }
var buttons = `<div class='btn-group float-right' role='group'>`; var buttons = `<div class='btn-group float-right' role='group'>`;
@ -283,7 +340,7 @@ function adjustStock(action, items, options={}) {
confirm: true, confirm: true,
confirmMessage: '{% trans "Confirm stock adjustment" %}', confirmMessage: '{% trans "Confirm stock adjustment" %}',
modal: modal, modal: modal,
onSubmit: function(fields, opts) { onSubmit: function(fields) {
// "Delete" action gets handled differently // "Delete" action gets handled differently
if (action == 'delete') { if (action == 'delete') {
@ -327,7 +384,7 @@ function adjustStock(action, items, options={}) {
}); });
// Add in extra field data // Add in extra field data
for (field_name in extraFields) { for (var field_name in extraFields) {
data[field_name] = getFormFieldValue( data[field_name] = getFormFieldValue(
field_name, field_name,
fields[field_name], fields[field_name],
@ -342,7 +399,7 @@ function adjustStock(action, items, options={}) {
data, data,
{ {
method: 'POST', method: 'POST',
success: function(response, status) { success: function() {
// Destroy the modal window // Destroy the modal window
$(modal).modal('hide'); $(modal).modal('hide');
@ -544,7 +601,7 @@ function loadStockTestResultsTable(table, options) {
{ {
success: function(data) { success: function(data) {
// Iterate through the returned test data // Iterate through the returned test data
data.forEach(function(item, index) { data.forEach(function(item) {
var match = false; var match = false;
var override = false; var override = false;
@ -683,8 +740,8 @@ function loadStockTable(table, options) {
var original = {}; var original = {};
for (var key in params) { for (var k in params) {
original[key] = params[key]; original[k] = params[k];
} }
setupFilterList(filterKey, table, filterListElement); setupFilterList(filterKey, table, filterListElement);
@ -700,10 +757,13 @@ function loadStockTable(table, options) {
grouping = options.grouping; grouping = options.grouping;
} }
var col = null;
// Explicitly disable part grouping functionality // Explicitly disable part grouping functionality
// Might be able to add this in later on, // Might be able to add this in later on,
// but there is a bug which makes this crash if paginating on the server side. // but there is a bug which makes this crash if paginating on the server side.
// Ref: https://github.com/wenzhixin/bootstrap-table/issues/3250 // Ref: https://github.com/wenzhixin/bootstrap-table/issues/3250
// eslint-disable-next-line no-unused-vars
grouping = false; grouping = false;
var columns = [ var columns = [
@ -727,22 +787,24 @@ function loadStockTable(table, options) {
sortName: 'part__name', sortName: 'part__name',
visible: params['part_detail'], visible: params['part_detail'],
switchable: params['part_detail'], switchable: params['part_detail'],
formatter: function(value, row, index, field) { formatter: function(value, row) {
var url = `/stock/item/${row.pk}/`; var url = `/stock/item/${row.pk}/`;
var thumb = row.part_detail.thumbnail; var thumb = row.part_detail.thumbnail;
var name = row.part_detail.full_name; var name = row.part_detail.full_name;
html = imageHoverIcon(thumb) + renderLink(name, url); var html = imageHoverIcon(thumb) + renderLink(name, url);
html += makePartIcons(row.part_detail); html += makePartIcons(row.part_detail);
return html; return html;
} }
}; };
if (!options.params.ordering) { if (!options.params.ordering) {
col['sortable'] = true; col['sortable'] = true;
}; }
columns.push(col); columns.push(col);
col = { col = {
@ -751,13 +813,15 @@ function loadStockTable(table, options) {
sortName: 'part__IPN', sortName: 'part__IPN',
visible: params['part_detail'], visible: params['part_detail'],
switchable: params['part_detail'], switchable: params['part_detail'],
formatter: function(value, row, index, field) { formatter: function(value, row) {
return row.part_detail.IPN; return row.part_detail.IPN;
}, },
}; };
if (!options.params.ordering) { if (!options.params.ordering) {
col['sortable'] = true; col['sortable'] = true;
}; }
columns.push(col); columns.push(col);
columns.push({ columns.push({
@ -765,7 +829,7 @@ function loadStockTable(table, options) {
title: '{% trans "Description" %}', title: '{% trans "Description" %}',
visible: params['part_detail'], visible: params['part_detail'],
switchable: params['part_detail'], switchable: params['part_detail'],
formatter: function(value, row, index, field) { formatter: function(value, row) {
return row.part_detail.description; return row.part_detail.description;
} }
}); });
@ -773,7 +837,7 @@ function loadStockTable(table, options) {
col = { col = {
field: 'quantity', field: 'quantity',
title: '{% trans "Stock" %}', title: '{% trans "Stock" %}',
formatter: function(value, row, index, field) { formatter: function(value, row) {
var val = parseFloat(value); var val = parseFloat(value);
@ -834,51 +898,61 @@ function loadStockTable(table, options) {
return html; return html;
} }
}; };
if (!options.params.ordering) { if (!options.params.ordering) {
col['sortable'] = true; col['sortable'] = true;
}; }
columns.push(col); columns.push(col);
col = { col = {
field: 'status', field: 'status',
title: '{% trans "Status" %}', title: '{% trans "Status" %}',
formatter: function(value, row, index, field) { formatter: function(value) {
return stockStatusDisplay(value); return stockStatusDisplay(value);
}, },
}; };
if (!options.params.ordering) { if (!options.params.ordering) {
col['sortable'] = true; col['sortable'] = true;
}; }
columns.push(col); columns.push(col);
col = { col = {
field: 'batch', field: 'batch',
title: '{% trans "Batch" %}', title: '{% trans "Batch" %}',
}; };
if (!options.params.ordering) { if (!options.params.ordering) {
col['sortable'] = true; col['sortable'] = true;
}; }
columns.push(col); columns.push(col);
col = { col = {
field: 'location_detail.pathstring', field: 'location_detail.pathstring',
title: '{% trans "Location" %}', title: '{% trans "Location" %}',
formatter: function(value, row, index, field) { formatter: function(value, row) {
return locationDetail(row); return locationDetail(row);
} }
}; };
if (!options.params.ordering) { if (!options.params.ordering) {
col['sortable'] = true; col['sortable'] = true;
}; }
columns.push(col); columns.push(col);
col = { col = {
field: 'stocktake_date', field: 'stocktake_date',
title: '{% trans "Stocktake" %}', title: '{% trans "Stocktake" %}',
}; };
if (!options.params.ordering) { if (!options.params.ordering) {
col['sortable'] = true; col['sortable'] = true;
}; }
columns.push(col); columns.push(col);
col = { col = {
@ -887,18 +961,22 @@ function loadStockTable(table, options) {
visible: global_settings.STOCK_ENABLE_EXPIRY, visible: global_settings.STOCK_ENABLE_EXPIRY,
switchable: global_settings.STOCK_ENABLE_EXPIRY, switchable: global_settings.STOCK_ENABLE_EXPIRY,
}; };
if (!options.params.ordering) { if (!options.params.ordering) {
col['sortable'] = true; col['sortable'] = true;
}; }
columns.push(col); columns.push(col);
col = { col = {
field: 'updated', field: 'updated',
title: '{% trans "Last Updated" %}', title: '{% trans "Last Updated" %}',
}; };
if (!options.params.ordering) { if (!options.params.ordering) {
col['sortable'] = true; col['sortable'] = true;
}; }
columns.push(col); columns.push(col);
columns.push({ columns.push({
@ -963,7 +1041,7 @@ function loadStockTable(table, options) {
if (!options.params.ordering) { if (!options.params.ordering) {
col.sortable = true; col.sortable = true;
col.sortName = 'purchase_price'; col.sortName = 'purchase_price';
}; }
columns.push(col); columns.push(col);
@ -1368,8 +1446,8 @@ function loadStockLocationTable(table, options) {
var original = {}; var original = {};
for (var key in params) { for (var k in params) {
original[key] = params[key]; original[k] = params[k];
} }
setupFilterList(filterKey, table, filterListElement); setupFilterList(filterKey, table, filterListElement);
@ -1437,7 +1515,7 @@ function loadStockTrackingTable(table, options) {
field: 'date', field: 'date',
title: '{% trans "Date" %}', title: '{% trans "Date" %}',
sortable: true, sortable: true,
formatter: function(value, row, index, field) { formatter: function(value) {
var m = moment(value); var m = moment(value);
if (m.isValid()) { if (m.isValid()) {
@ -1453,7 +1531,7 @@ function loadStockTrackingTable(table, options) {
cols.push({ cols.push({
field: 'label', field: 'label',
title: '{% trans "Description" %}', title: '{% trans "Description" %}',
formatter: function(value, row, index, field) { formatter: function(value, row) {
var html = "<b>" + value + "</b>"; var html = "<b>" + value + "</b>";
if (row.notes) { if (row.notes) {
@ -1468,7 +1546,7 @@ function loadStockTrackingTable(table, options) {
cols.push({ cols.push({
field: 'deltas', field: 'deltas',
title: '{% trans "Details" %}', title: '{% trans "Details" %}',
formatter: function(details, row, index, field) { formatter: function(details, row) {
var html = `<table class='table table-condensed' id='tracking-table-${row.pk}'>`; var html = `<table class='table table-condensed' id='tracking-table-${row.pk}'>`;
if (!details) { if (!details) {
@ -1603,7 +1681,7 @@ function loadStockTrackingTable(table, options) {
cols.push({ cols.push({
field: 'user', field: 'user',
title: '{% trans "User" %}', title: '{% trans "User" %}',
formatter: function(value, row, index, field) { formatter: function(value, row) {
if (value) if (value)
{ {
// TODO - Format the user's first and last names // TODO - Format the user's first and last names
@ -1741,26 +1819,6 @@ function loadInstalledInTable(table, options) {
* Display a table showing the stock items which are installed in this stock item. * Display a table showing the stock items which are installed in this stock item.
*/ */
function updateCallbacks() {
// Setup callback functions when buttons are pressed
table.find('.button-install').click(function() {
var pk = $(this).attr('pk');
launchModalForm(
`/stock/item/${options.stock_item}/install/`,
{
data: {
part: pk,
},
success: function() {
// Refresh entire table!
table.bootstrapTable('refresh');
}
}
);
});
}
table.inventreeTable({ table.inventreeTable({
url: "{% url 'api-stock-list' %}", url: "{% url 'api-stock-list' %}",
queryParams: { queryParams: {
@ -1802,7 +1860,7 @@ function loadInstalledInTable(table, options) {
{ {
field: 'status', field: 'status',
title: '{% trans "Status" %}', title: '{% trans "Status" %}',
formatter: function(value, row) { formatter: function(value) {
return stockStatusDisplay(value); return stockStatusDisplay(value);
} }
}, },

View File

@ -8,6 +8,19 @@
{% include "status_codes.html" with label='purchaseOrder' options=PurchaseOrderStatus.list %} {% include "status_codes.html" with label='purchaseOrder' options=PurchaseOrderStatus.list %}
{% include "status_codes.html" with label='salesOrder' options=SalesOrderStatus.list %} {% include "status_codes.html" with label='salesOrder' options=SalesOrderStatus.list %}
/* globals
global_settings
*/
/* exported
buildStatusDisplay,
getAvailableTableFilters,
purchaseOrderStatusDisplay,
salesOrderStatusDisplay,
stockHistoryStatusDisplay,
stockStatusDisplay,
*/
function getAvailableTableFilters(tableKey) { function getAvailableTableFilters(tableKey) {

View File

@ -1,21 +1,21 @@
{% load i18n %} {% load i18n %}
/* global
inventreeLoad,
inventreeSave,
*/
/* exported
customGroupSorter,
reloadtable,
renderLink,
reloadTableFilters,
*/
function reloadtable(table) { function reloadtable(table) {
$(table).bootstrapTable('refresh'); $(table).bootstrapTable('refresh');
} }
function editButton(url, text='{% trans "Edit" %}') {
return "<button class='btn btn-success edit-button btn-sm' type='button' url='" + url + "'>" + text + "</button>";
}
function deleteButton(url, text='{% trans "Delete" %}') {
return "<button class='btn btn-danger delete-button btn-sm' type='button' url='" + url + "'>" + text + "</button>";
}
function renderLink(text, url, options={}) { function renderLink(text, url, options={}) {
if (url === null || url === undefined || url === '') { if (url === null || url === undefined || url === '') {
return text; return text;