Implemented a way to use the external barcode lookup plugin also from within the frontend as a product picker workflow

This commit is contained in:
Bernd Bestel
2023-11-03 20:47:43 +01:00
parent c9215a9a4e
commit 27f9d70b56
11 changed files with 62 additions and 14 deletions

View File

@@ -249,6 +249,32 @@ $('#product_id_text_input').on('blur', function(e)
Grocy.Components.ProductPicker.PopupOpen = false;
window.location.href = U('/product/new?flow=InplaceNewProductWithBarcode&barcode=' + encodeURIComponent(input) + '&returnto=' + encodeURIComponent(Grocy.CurrentUrlRelative + "?flow=InplaceAddBarcodeToExistingProduct&barcode=" + input + "&" + embedded) + "&" + embedded);
}
},
barcodepluginlookup: {
label: '<strong>E</strong> ' + __t('External barcode lookup (via plugin)'),
className: 'btn-dark add-new-product-plugin-dialog-button responsive-button ' + addProductWorkflowsAdditionalCssClasses,
callback: function()
{
Grocy.Components.ProductPicker.PopupOpen = false;
Grocy.Api.Get("stock/barcodes/external-lookup/" + encodeURIComponent(input) + "?add=true",
function(pluginResponse)
{
if (pluginResponse == null)
{
toastr.warning(__t("Nothing was found for the given barcode"));
}
else
{
window.location.href = U("/product/" + pluginResponse.id + "?flow=InplaceNewProductByPlugin&returnto=" + encodeURIComponent(Grocy.CurrentUrlRelative + "?flow=InplaceNewProductWithName&" + embedded) + "&" + embedded);
}
},
function(xhr)
{
Grocy.FrontendHelpers.ShowGenericError("Error while executing the barcode lookup plugin", xhr.response);
}
);
}
}
};
@@ -321,6 +347,10 @@ $('#product_id_text_input').on('blur', function(e)
{
$('.retry-camera-scanning-button').not(".d-none").click();
}
if (e.key === 'e' || e.key === 'E')
{
$('.add-new-product-plugin-dialog-button').not(".d-none").click();
}
});
}
else