2019-09-21 20:01:49 +02:00
|
|
|
|
Grocy.BarCodeScannerTestingHitCount = 0;
|
|
|
|
|
Grocy.BarCodeScannerTestingMissCount = 0;
|
|
|
|
|
|
2020-08-30 12:18:16 +02:00
|
|
|
|
$("#scanned_barcode").on("blur", function(e)
|
2019-09-21 20:01:49 +02:00
|
|
|
|
{
|
|
|
|
|
OnBarcodeScanned($("#scanned_barcode").val());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$("#scanned_barcode").keydown(function(event)
|
|
|
|
|
{
|
2022-03-30 18:00:28 +02:00
|
|
|
|
if (event.keyCode === 13) // Enter
|
2019-09-21 20:01:49 +02:00
|
|
|
|
{
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
OnBarcodeScanned($("#scanned_barcode").val());
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$("#expected_barcode").on("keyup", function(e)
|
|
|
|
|
{
|
|
|
|
|
if ($("#expected_barcode").val().length > 1)
|
|
|
|
|
{
|
|
|
|
|
$("#scanned_barcode").removeAttr("disabled");
|
2025-01-14 17:54:06 +01:00
|
|
|
|
$("#camerabarcodescanner-start-button").removeAttr("disabled");
|
|
|
|
|
$("#camerabarcodescanner-start-button").removeClass("disabled");
|
2019-09-21 20:01:49 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$("#scanned_barcode").attr("disabled", "");
|
2025-01-14 17:54:06 +01:00
|
|
|
|
$("#camerabarcodescanner-start-button").attr("disabled", "");
|
|
|
|
|
$("#camerabarcodescanner-start-button").addClass("disabled");
|
2019-09-21 20:01:49 +02:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
setTimeout(function()
|
|
|
|
|
{
|
2025-01-14 17:54:06 +01:00
|
|
|
|
$("#camerabarcodescanner-start-button").attr("disabled", "");
|
|
|
|
|
$("#camerabarcodescanner-start-button").addClass("disabled");
|
2025-01-12 17:57:50 +01:00
|
|
|
|
$("#expected_barcode").focus();
|
2025-01-11 15:41:04 +01:00
|
|
|
|
}, 500);
|
2019-09-21 20:01:49 +02:00
|
|
|
|
|
|
|
|
|
if (GetUriParam("barcode") !== undefined)
|
|
|
|
|
{
|
|
|
|
|
$("#expected_barcode").val(GetUriParam("barcode"));
|
2020-08-30 12:18:16 +02:00
|
|
|
|
setTimeout(function()
|
2019-09-21 20:01:49 +02:00
|
|
|
|
{
|
|
|
|
|
$("#expected_barcode").keyup();
|
|
|
|
|
$("#scanned_barcode").focus();
|
2025-01-11 15:41:04 +01:00
|
|
|
|
}, 500);
|
2019-09-21 20:01:49 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function OnBarcodeScanned(barcode)
|
|
|
|
|
{
|
|
|
|
|
if (barcode.length === 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-08-29 16:41:27 +02:00
|
|
|
|
|
2019-09-21 20:01:49 +02:00
|
|
|
|
var bgClass = "";
|
|
|
|
|
if (barcode != $("#expected_barcode").val())
|
|
|
|
|
{
|
|
|
|
|
Grocy.BarCodeScannerTestingMissCount++;
|
|
|
|
|
bgClass = "bg-danger";
|
|
|
|
|
|
2020-01-28 19:27:18 +01:00
|
|
|
|
$("#miss-count").text(Grocy.BarCodeScannerTestingMissCount);
|
2025-01-16 21:34:01 +01:00
|
|
|
|
animateCSS("#miss-count", "flash");
|
2019-09-21 20:01:49 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Grocy.BarCodeScannerTestingHitCount++;
|
|
|
|
|
bgClass = "bg-success";
|
|
|
|
|
|
2020-01-28 19:27:18 +01:00
|
|
|
|
$("#hit-count").text(Grocy.BarCodeScannerTestingHitCount);
|
2025-01-16 21:34:01 +01:00
|
|
|
|
animateCSS("#hit-count", "flash");
|
2019-09-21 20:01:49 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$("#scanned_codes").prepend("<option class='" + bgClass + "'>" + barcode + "</option>");
|
|
|
|
|
setTimeout(function()
|
|
|
|
|
{
|
|
|
|
|
$("#scanned_barcode").val("");
|
|
|
|
|
|
|
|
|
|
if (!$(":focus").is($("#expected_barcode")))
|
|
|
|
|
{
|
|
|
|
|
$("#scanned_barcode").focus();
|
|
|
|
|
}
|
2025-01-11 15:41:04 +01:00
|
|
|
|
}, 500);
|
2019-09-21 20:01:49 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-13 15:55:27 +02:00
|
|
|
|
$(document).on("Grocy.BarcodeScanned", function(e, barcode, target)
|
2019-09-21 20:01:49 +02:00
|
|
|
|
{
|
2020-12-22 19:06:41 +01:00
|
|
|
|
if (target !== "#scanned_barcode")
|
2020-04-13 15:55:27 +02:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-08-29 16:41:27 +02:00
|
|
|
|
|
2019-09-21 20:01:49 +02:00
|
|
|
|
OnBarcodeScanned(barcode);
|
|
|
|
|
});
|