Implemented frontend external barcode lookup workflow + a plugin for Open Food Facts (closes #158)

This commit is contained in:
Bernd Bestel
2025-01-11 20:04:32 +01:00
parent a2c2049037
commit c9ffe4885d
9 changed files with 101 additions and 16 deletions

View File

@@ -257,6 +257,7 @@ $('#product_id_text_input').on('blur', function(e)
callback: function()
{
Grocy.Components.ProductPicker.PopupOpen = false;
Grocy.FrontendHelpers.BeginUiBusy($("form").first().attr("id"));
Grocy.Api.Get("stock/barcodes/external-lookup/" + encodeURIComponent(input) + "?add=true",
function(pluginResponse)
@@ -264,15 +265,17 @@ $('#product_id_text_input').on('blur', function(e)
if (pluginResponse == null)
{
toastr.warning(__t("Nothing was found for the given barcode"));
Grocy.FrontendHelpers.EndUiBusy($("form").first().attr("id"));
}
else
{
window.location.href = U("/product/" + pluginResponse.id + "?flow=InplaceNewProductByPlugin&returnto=" + encodeURIComponent(Grocy.CurrentUrlRelative + "?flow=InplaceNewProductWithName&" + embedded) + "&" + embedded);
window.location.href = U("/product/" + pluginResponse.id + "?flow=InplaceNewProductByExternalBarcodeLookupPlugin&returnto=" + encodeURIComponent(Grocy.CurrentUrlRelative + "?flow=InplaceNewProductWithName&" + embedded) + "&" + embedded);
}
},
function(xhr)
{
Grocy.FrontendHelpers.ShowGenericError("Error while executing the barcode lookup plugin", xhr.response);
Grocy.FrontendHelpers.EndUiBusy($("form").first().attr("id"));
}
);
}