Improve barcode handling

This commit is contained in:
Skylar Ittner 2020-10-22 09:37:46 -06:00
parent 808ff0f4a8
commit b99e577d63

View File

@ -16,35 +16,39 @@ $("#clientsearchbar").submit(function (evt) {
router.navigate("/clients/" + $("#clientsearchbar input[type=search]").val()); router.navigate("/clients/" + $("#clientsearchbar input[type=search]").val());
}); });
function openMachineInfoByBarcode(code) {
if (code.startsWith("http") || !code.match(/^([A-Z0-9])+$/)) {
matches = code.match(/[0-9A-Z]{8,}/g);
if (matches == null || matches.length == 0) {
app.dialog.alert("No IDs detected in barcode.", "Error");
} else if (matches.length == 1) {
router.navigate("/machine/" + matches[0]);
} else if (matches.length > 1) {
var buttons = [];
for (var i = 0; i < matches.length; i++) {
buttons.push({
text: matches[i]
});
}
app.dialog.create({
title: 'Multiple IDs',
text: 'Multiple potential IDs exist in that barcode. Select the correct one.',
buttons: buttons,
verticalButtons: true,
onClick: function (dialog, index) {
var id = matches[index];
router.navigate("/machine/" + id);
}
}).open();
}
} else {
router.navigate("/machine/" + code);
}
}
function scanBarcodeOpenMachine() { function scanBarcodeOpenMachine() {
scanBarcode(function (code) { scanBarcode(function (code) {
if (code.startsWith("http")) { openMachineInfoByBarcode(code);
matches = code.match(/[0-9]{8,}/g);
if (matches.length == 0) {
app.dialog.alert("No IDs detected in barcode.", "Error");
} else if (matches.length == 1) {
router.navigate("/machine/" + matches[0]);
} else if (matches.length > 1) {
var buttons = [];
for (var i = 0; i < matches.length; i++) {
buttons.push({
text: matches[i]
});
}
app.dialog.create({
title: 'Multiple IDs',
text: 'Multiple potential IDs exist in that barcode. Select the correct one.',
buttons: buttons,
verticalButtons: true,
onClick: function (dialog, index) {
var id = matches[index];
router.navigate("/machine/" + id);
}
}).open();
}
} else {
router.navigate("/machine/" + code);
}
}, function (error) { }, function (error) {
app.dialog.alert(error, "Error"); app.dialog.alert(error, "Error");
}); });