mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Refactor tractor
This commit is contained in:
parent
5e5bced0c7
commit
c61631a380
@ -45,6 +45,61 @@ function makeNotesField(options={}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* POST data to the server, and handle standard responses.
|
||||||
|
*/
|
||||||
|
function postBarcodeData(barcode_data, options={}) {
|
||||||
|
|
||||||
|
var modal = options.modal || '#modal-form';
|
||||||
|
|
||||||
|
var url = options.url || '/api/barcode/';
|
||||||
|
|
||||||
|
var data = options.data || {};
|
||||||
|
|
||||||
|
data.barcode = barcode_data;
|
||||||
|
|
||||||
|
inventreePut(
|
||||||
|
url,
|
||||||
|
data,
|
||||||
|
{
|
||||||
|
method: 'POST',
|
||||||
|
error: function() {
|
||||||
|
enableBarcodeInput(modal, true);
|
||||||
|
showBarcodeMessage(modal, '{% trans "Server error" %}');
|
||||||
|
},
|
||||||
|
success: function(response, status) {
|
||||||
|
modalEnable(modal, false);
|
||||||
|
enableBarcodeInput(modal, true);
|
||||||
|
|
||||||
|
if (status == 'success') {
|
||||||
|
|
||||||
|
if ('success' in response) {
|
||||||
|
if (options.onScan) {
|
||||||
|
options.onScan(response);
|
||||||
|
}
|
||||||
|
} else if ('error' in response) {
|
||||||
|
showBarcodeMessage(
|
||||||
|
modal,
|
||||||
|
response.error,
|
||||||
|
'warning'
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
showBarcodeMessage(
|
||||||
|
modal,
|
||||||
|
'{% trans "Unknown response from server" %}',
|
||||||
|
'warning'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Invalid response returned from server
|
||||||
|
showInvalidResponseError(modal, response, status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function showBarcodeMessage(modal, message, style='danger') {
|
function showBarcodeMessage(modal, message, style='danger') {
|
||||||
|
|
||||||
var html = `<div class='alert alert-block alert-${style}'>`;
|
var html = `<div class='alert alert-block alert-${style}'>`;
|
||||||
@ -106,9 +161,7 @@ function barcodeDialog(title, options={}) {
|
|||||||
|
|
||||||
if (barcode && barcode.length > 0) {
|
if (barcode && barcode.length > 0) {
|
||||||
|
|
||||||
if (options.onScan) {
|
postBarcodeData(barcode, options);
|
||||||
options.onScan(barcode);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,40 +261,20 @@ function barcodeScanDialog() {
|
|||||||
barcodeDialog(
|
barcodeDialog(
|
||||||
"Scan Barcode",
|
"Scan Barcode",
|
||||||
{
|
{
|
||||||
onScan: function(barcode) {
|
onScan: function(response) {
|
||||||
enableBarcodeInput(modal, false);
|
if ('url' in response) {
|
||||||
inventreePut(
|
$(modal).modal('hide');
|
||||||
'/api/barcode/',
|
|
||||||
{
|
|
||||||
barcode: barcode,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
method: 'POST',
|
|
||||||
success: function(response, status) {
|
|
||||||
|
|
||||||
enableBarcodeInput(modal, true);
|
// Redirect to the URL!
|
||||||
|
window.location.href = response.url;
|
||||||
if (status == 'success') {
|
} else {
|
||||||
|
showBarcodeMessage(
|
||||||
if ('success' in response) {
|
modal,
|
||||||
if ('url' in response) {
|
'{% trans "No URL in response" %}',
|
||||||
// Redirect to the URL!
|
'warning'
|
||||||
$(modal).modal('hide');
|
);
|
||||||
window.location.href = response.url;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if ('error' in response) {
|
|
||||||
showBarcodeMessage(modal, response.error, 'warning');
|
|
||||||
} else {
|
|
||||||
showBarcodeMessage(modal, "{% trans 'Unknown response from server' %}", 'warning');
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
showInvalidResponseError(modal, response, status);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -257,37 +290,14 @@ function linkBarcodeDialog(stockitem, options={}) {
|
|||||||
barcodeDialog(
|
barcodeDialog(
|
||||||
"{% trans 'Link Barcode to Stock Item' %}",
|
"{% trans 'Link Barcode to Stock Item' %}",
|
||||||
{
|
{
|
||||||
onScan: function(barcode) {
|
url: '/api/barcode/link/',
|
||||||
enableBarcodeInput(modal, false);
|
data: {
|
||||||
inventreePut(
|
stockitem: stockitem,
|
||||||
'/api/barcode/link/',
|
},
|
||||||
{
|
onScan: function(response) {
|
||||||
barcode: barcode,
|
|
||||||
stockitem: stockitem,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
method: 'POST',
|
|
||||||
success: function(response, status) {
|
|
||||||
|
|
||||||
enableBarcodeInput(modal, true);
|
$(modal).modal('hide');
|
||||||
|
location.reload();
|
||||||
if (status == 'success') {
|
|
||||||
|
|
||||||
if ('success' in response) {
|
|
||||||
$(modal).modal('hide');
|
|
||||||
location.reload();
|
|
||||||
} else if ('error' in response) {
|
|
||||||
showBarcodeMessage(modal, response.error, 'warning');
|
|
||||||
} else {
|
|
||||||
showBarcodeMessage(modal, "{% trans 'Unknown response from server' %}", warning);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
showInvalidResponseError(modal, response, status);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -458,62 +468,39 @@ function barcodeCheckIn(location_id, options={}) {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
onScan: function(barcode) {
|
onScan: function(response) {
|
||||||
enableBarcodeInput(modal, false);
|
if ('stockitem' in response) {
|
||||||
inventreePut(
|
stockitem = response.stockitem;
|
||||||
'/api/barcode/',
|
|
||||||
{
|
|
||||||
barcode: barcode,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
method: 'POST',
|
|
||||||
error: function() {
|
|
||||||
enableBarcodeInput(modal, true);
|
|
||||||
showBarcodeMessage(modal, '{% trans "Server error" %}');
|
|
||||||
},
|
|
||||||
success: function(response, status) {
|
|
||||||
|
|
||||||
enableBarcodeInput(modal, true);
|
var duplicate = false;
|
||||||
|
|
||||||
if (status == 'success') {
|
items.forEach(function(item) {
|
||||||
if ('stockitem' in response) {
|
if (item.pk == stockitem.pk) {
|
||||||
stockitem = response.stockitem;
|
duplicate = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
var duplicate = false;
|
if (duplicate) {
|
||||||
|
showBarcodeMessage(modal, '{% trans "Stock Item already scanned" %}', "warning");
|
||||||
|
} else {
|
||||||
|
|
||||||
items.forEach(function(item) {
|
if (stockitem.location == location_id) {
|
||||||
if (item.pk == stockitem.pk) {
|
showBarcodeMessage(modal, '{% trans "Stock Item already in this location" %}');
|
||||||
duplicate = true;
|
return;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
if (duplicate) {
|
// Add this stock item to the list
|
||||||
showBarcodeMessage(modal, '{% trans "Stock Item already scanned" %}', "warning");
|
items.push(stockitem);
|
||||||
} else {
|
|
||||||
|
|
||||||
if (stockitem.location == location_id) {
|
showBarcodeMessage(modal, '{% trans "Added stock item" %}', "success");
|
||||||
showBarcodeMessage(modal, '{% trans "Stock Item already in this location" %}');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add this stock item to the list
|
reloadTable();
|
||||||
items.push(stockitem);
|
}
|
||||||
|
|
||||||
showBarcodeMessage(modal, '{% trans "Added stock item" %}', "success");
|
} else {
|
||||||
|
// Barcode does not match a stock item
|
||||||
reloadTable();
|
showBarcodeMessage(modal, '{% trans "Barcode does not match Stock Item" %}', "warning");
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
|
||||||
// Barcode does not match a stock item
|
|
||||||
showBarcodeMessage(modal, '{% trans "Barcode does not match Stock Item" %}', "warning");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
showInvalidResponseError(modal, response, status);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -605,47 +592,23 @@ function scanItemsIntoLocation(item_id_list, options={}) {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
onScan: function(barcode) {
|
onScan: function(response) {
|
||||||
updateLocationInfo(null);
|
updateLocationInfo(null);
|
||||||
enableBarcodeInput(modal, false);
|
if ('stocklocation' in response) {
|
||||||
inventreePut(
|
// Barcode corresponds to a StockLocation
|
||||||
'/api/barcode/',
|
stock_location = response.stocklocation;
|
||||||
{
|
|
||||||
barcode: barcode,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
method: 'POST',
|
|
||||||
error: function() {
|
|
||||||
enableBarcodeInput(modal, true);
|
|
||||||
showBarcodeMessage(modal, '{% trans "Server error" %}');
|
|
||||||
},
|
|
||||||
success: function(response, status) {
|
|
||||||
modalEnable(modal, false);
|
|
||||||
enableBarcodeInput(modal, true);
|
|
||||||
|
|
||||||
if (status == 'success') {
|
updateLocationInfo(stock_location);
|
||||||
if ('stocklocation' in response) {
|
modalEnable(modal, true);
|
||||||
// Barcode corresponds to a StockLocation
|
|
||||||
stock_location = response.stocklocation;
|
|
||||||
|
|
||||||
updateLocationInfo(stock_location);
|
} else {
|
||||||
modalEnable(modal, true);
|
// Barcode does *NOT* correspond to a StockLocation
|
||||||
|
showBarcodeMessage(
|
||||||
} else {
|
modal,
|
||||||
// Barcode does *NOT* correspond to a StockLocation
|
'{% trans "Barcode does not match a valid location" %}',
|
||||||
showBarcodeMessage(
|
"warning",
|
||||||
modal,
|
);
|
||||||
'{% trans "Barcode does not match a valid location" %}',
|
}
|
||||||
"warning",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Invalid response returned from server
|
|
||||||
showInvalidResponseError(modal, response, status);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user