mirror of
https://github.com/grocy/grocy.git
synced 2025-08-15 02:04:38 +00:00
Added a little barcode scanner testing page (references #362)
This commit is contained in:
95
public/viewjs/barcodescannertesting.js
Normal file
95
public/viewjs/barcodescannertesting.js
Normal file
@@ -0,0 +1,95 @@
|
||||
Grocy.BarCodeScannerTestingHitCount = 0;
|
||||
Grocy.BarCodeScannerTestingMissCount = 0;
|
||||
|
||||
$("#scanned_barcode").on("blur", function (e)
|
||||
{
|
||||
OnBarcodeScanned($("#scanned_barcode").val());
|
||||
});
|
||||
|
||||
$("#scanned_barcode").keydown(function(event)
|
||||
{
|
||||
if (event.keyCode === 13) //Enter
|
||||
{
|
||||
event.preventDefault();
|
||||
OnBarcodeScanned($("#scanned_barcode").val());
|
||||
}
|
||||
});
|
||||
|
||||
$("#expected_barcode").on("keyup", function(e)
|
||||
{
|
||||
if ($("#expected_barcode").val().length > 1)
|
||||
{
|
||||
$("#scanned_barcode").removeAttr("disabled");
|
||||
$("#barcodescanner-start-button").removeAttr("disabled");
|
||||
$("#barcodescanner-start-button").removeClass("disabled");
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#scanned_barcode").attr("disabled", "");
|
||||
$("#barcodescanner-start-button").attr("disabled", "");
|
||||
$("#barcodescanner-start-button").addClass("disabled");
|
||||
}
|
||||
});
|
||||
|
||||
$("#expected_barcode").focus();
|
||||
setTimeout(function()
|
||||
{
|
||||
$("#barcodescanner-start-button").attr("disabled", "");
|
||||
$("#barcodescanner-start-button").addClass("disabled");
|
||||
}, 200);
|
||||
|
||||
if (GetUriParam("barcode") !== undefined)
|
||||
{
|
||||
$("#expected_barcode").val(GetUriParam("barcode"));
|
||||
setTimeout(function ()
|
||||
{
|
||||
$("#expected_barcode").keyup();
|
||||
$("#scanned_barcode").focus();
|
||||
}, 200);
|
||||
}
|
||||
|
||||
function OnBarcodeScanned(barcode)
|
||||
{
|
||||
if (barcode.length === 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var bgClass = "";
|
||||
if (barcode != $("#expected_barcode").val())
|
||||
{
|
||||
Grocy.BarCodeScannerTestingMissCount++;
|
||||
bgClass = "bg-danger";
|
||||
|
||||
$("#miss-count").fadeOut(200, function ()
|
||||
{
|
||||
$(this).text(Grocy.BarCodeScannerTestingMissCount).fadeIn(200);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
Grocy.BarCodeScannerTestingHitCount++;
|
||||
bgClass = "bg-success";
|
||||
|
||||
$("#hit-count").fadeOut(200, function ()
|
||||
{
|
||||
$(this).text(Grocy.BarCodeScannerTestingHitCount).fadeIn(200);
|
||||
});
|
||||
}
|
||||
|
||||
$("#scanned_codes").prepend("<option class='" + bgClass + "'>" + barcode + "</option>");
|
||||
setTimeout(function()
|
||||
{
|
||||
$("#scanned_barcode").val("");
|
||||
|
||||
if (!$(":focus").is($("#expected_barcode")))
|
||||
{
|
||||
$("#scanned_barcode").focus();
|
||||
}
|
||||
}, 200);
|
||||
}
|
||||
|
||||
$(document).on("Grocy.BarcodeScanned", function(e, barcode)
|
||||
{
|
||||
OnBarcodeScanned(barcode);
|
||||
});
|
Reference in New Issue
Block a user