mirror of
https://github.com/grocy/grocy.git
synced 2025-08-20 12:20:22 +00:00
Support camera barcode scanning in recipepicker (references #1562)
This commit is contained in:
@@ -279,8 +279,14 @@ $(document).on("click", "#barcodescanner-start-button", async function(e)
|
||||
Grocy.Components.BarcodeScanner.StartScanning();
|
||||
});
|
||||
|
||||
setTimeout(function()
|
||||
Grocy.Components.BarcodeScanner.InitDone = false;
|
||||
Grocy.Components.BarcodeScanner.Init = function()
|
||||
{
|
||||
if (Grocy.Components.BarcodeScanner.InitDone)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$(".barcodescanner-input:visible").each(function()
|
||||
{
|
||||
if ($(this).hasAttr("disabled"))
|
||||
@@ -291,5 +297,12 @@ setTimeout(function()
|
||||
{
|
||||
$(this).after('<a id="barcodescanner-start-button" class="btn btn-sm btn-primary text-white" data-target="' + $(this).attr("data-target") + '"><i class="fas fa-camera"></i></a>');
|
||||
}
|
||||
|
||||
Grocy.Components.BarcodeScanner.InitDone = true;
|
||||
});
|
||||
}
|
||||
|
||||
setTimeout(function()
|
||||
{
|
||||
Grocy.Components.BarcodeScanner.Init();
|
||||
}, 50);
|
||||
|
@@ -239,7 +239,7 @@ $('#product_id_text_input').on('blur', function(e)
|
||||
}
|
||||
};
|
||||
|
||||
if (!Grocy.FeatureFlags.DISABLE_BROWSER_BARCODE_CAMERA_SCANNING)
|
||||
if (!Grocy.FeatureFlags.GROCY_FEATURE_FLAG_DISABLE_BROWSER_BARCODE_CAMERA_SCANNING)
|
||||
{
|
||||
buttons.retrycamerascanning = {
|
||||
label: '<strong>C</strong> <i class="fas fa-camera"></i>',
|
||||
|
@@ -101,3 +101,25 @@ $('#recipe_id_text_input').on('blur', function(e)
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on("Grocy.BarcodeScanned", function(e, barcode, target)
|
||||
{
|
||||
if (!(target == "@recipepicker" || target == "undefined" || target == undefined)) // Default target
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Don't know why the blur event does not fire immediately ... this works...
|
||||
Grocy.Components.RecipePicker.GetInputElement().focusout();
|
||||
Grocy.Components.RecipePicker.GetInputElement().focus();
|
||||
Grocy.Components.RecipePicker.GetInputElement().blur();
|
||||
|
||||
Grocy.Components.RecipePicker.GetInputElement().val(barcode);
|
||||
|
||||
setTimeout(function()
|
||||
{
|
||||
Grocy.Components.RecipePicker.GetInputElement().focusout();
|
||||
Grocy.Components.RecipePicker.GetInputElement().focus();
|
||||
Grocy.Components.RecipePicker.GetInputElement().blur();
|
||||
}, 200);
|
||||
});
|
||||
|
@@ -449,6 +449,11 @@ $(document).on("click", ".copy-day-button", function(e)
|
||||
|
||||
$("#add-recipe-modal").on("shown.bs.modal", function(e)
|
||||
{
|
||||
if (!Grocy.FeatureFlags.GROCY_FEATURE_FLAG_DISABLE_BROWSER_BARCODE_CAMERA_SCANNING)
|
||||
{
|
||||
Grocy.Components.BarcodeScanner.Init();
|
||||
}
|
||||
|
||||
Grocy.Components.RecipePicker.GetInputElement().focus();
|
||||
})
|
||||
|
||||
@@ -459,6 +464,11 @@ $("#add-note-modal").on("shown.bs.modal", function(e)
|
||||
|
||||
$("#add-product-modal").on("shown.bs.modal", function(e)
|
||||
{
|
||||
if (!Grocy.FeatureFlags.GROCY_FEATURE_FLAG_DISABLE_BROWSER_BARCODE_CAMERA_SCANNING)
|
||||
{
|
||||
Grocy.Components.BarcodeScanner.Init();
|
||||
}
|
||||
|
||||
Grocy.Components.ProductPicker.GetInputElement().focus();
|
||||
})
|
||||
|
||||
|
Reference in New Issue
Block a user