From 6263715c538e31d035d24edddef5ed2bc74ae32e Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Mon, 28 Dec 2020 19:59:18 +0100 Subject: [PATCH] Fixed shopping list item form load handling (fixes #1222) --- changelog/61_UNRELEASED_xxxx-xx-xx.md | 1 + public/viewjs/shoppinglistitemform.js | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/changelog/61_UNRELEASED_xxxx-xx-xx.md b/changelog/61_UNRELEASED_xxxx-xx-xx.md index 035d787a..cfdd3d12 100644 --- a/changelog/61_UNRELEASED_xxxx-xx-xx.md +++ b/changelog/61_UNRELEASED_xxxx-xx-xx.md @@ -13,3 +13,4 @@ - Fixed that indirect unit conversions (those between units, not product overrides) could not be used/selected - Fixed that the new product option "Never show on stock overview" was unintentionally set by default for new products - Fixed that the success message on purchase displayed no amount when `FEATURE_FLAG_STOCK_PRICE_TRACKING` was disabled +- Fixed that adding items to the shopping list from the context/more menu on the stock overview page did not work diff --git a/public/viewjs/shoppinglistitemform.js b/public/viewjs/shoppinglistitemform.js index d21b6817..e6a6ea39 100644 --- a/public/viewjs/shoppinglistitemform.js +++ b/public/viewjs/shoppinglistitemform.js @@ -29,7 +29,7 @@ $('#save-shoppinglist-button').on('click', function(e) Grocy.Api.Get('stock/products/' + jsonData.product_id, function(productDetails) { - window.parent.postMessage(WindowMessageBag("ShowSuccessMessage", __t("Added %1$s of %2$s to the shopping list \"%3$s\"", jsonData.product_amount + " " + __n(jsonData.product_amount, productDetails.default_quantity_unit_purchase.name, productDetails.default_.name_plural), productDetails.product.name, $("#shopping_list_id option:selected").text())), Grocy.BaseUrl); + window.parent.postMessage(WindowMessageBag("ShowSuccessMessage", __t("Added %1$s of %2$s to the shopping list \"%3$s\"", parseFloat(jsonData.product_amount).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_amounts }) + " " + __n(jsonData.product_amount, productDetails.default_quantity_unit_purchase.name, productDetails.default_quantity_unit_purchase.name_plural), productDetails.product.name, $("#shopping_list_id option:selected").text())), Grocy.BaseUrl); window.parent.postMessage(WindowMessageBag("ShoppingListChanged", $("#shopping_list_id").val().toString()), Grocy.BaseUrl); window.parent.postMessage(WindowMessageBag("CloseAllModals"), Grocy.BaseUrl); }, @@ -51,8 +51,7 @@ $('#save-shoppinglist-button').on('click', function(e) } ); } - - if (Grocy.EditMode === 'create') + else if (Grocy.EditMode === 'create') { Grocy.Api.Post('objects/shopping_list', jsonData, function(result) @@ -67,7 +66,7 @@ $('#save-shoppinglist-button').on('click', function(e) Grocy.Api.Get('stock/products/' + jsonData.product_id, function(productDetails) { - window.parent.postMessage(WindowMessageBag("ShowSuccessMessage", __t("Added %1$s of %2$s to the shopping list \"%3$s\"", jsonData.amount + " " + __n(jsonData.amount, productDetails.default_quantity_unit_purchase.name, productDetails.default_quantity_unit_purchase.name_plural), productDetails.product.name, $("#shopping_list_id option:selected").text())), Grocy.BaseUrl); + window.parent.postMessage(WindowMessageBag("ShowSuccessMessage", __t("Added %1$s of %2$s to the shopping list \"%3$s\"", parseFloat(jsonData.amount).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_amounts }) + " " + __n(jsonData.amount, productDetails.default_quantity_unit_purchase.name, productDetails.default_quantity_unit_purchase.name_plural), productDetails.product.name, $("#shopping_list_id option:selected").text())), Grocy.BaseUrl); window.parent.postMessage(WindowMessageBag("ShoppingListChanged", $("#shopping_list_id").val().toString()), Grocy.BaseUrl); window.parent.postMessage(WindowMessageBag("CloseAllModals"), Grocy.BaseUrl); }, @@ -109,7 +108,7 @@ $('#save-shoppinglist-button').on('click', function(e) Grocy.Api.Get('stock/products/' + jsonData.product_id, function(productDetails) { - window.parent.postMessage(WindowMessageBag("ShowSuccessMessage", __t("Added %1$s of %2$s to the shopping list \"%3$s\"", jsonData.amount + " " + __n(jsonData.amount, productDetails.default_quantity_unit_purchase.name, productDetails.default_quantity_unit_purchase.name_plural), productDetails.product.name, $("#shopping_list_id option:selected").text())), Grocy.BaseUrl); + window.parent.postMessage(WindowMessageBag("ShowSuccessMessage", __t("Added %1$s of %2$s to the shopping list \"%3$s\"", parseFloat(jsonData.amount).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_amounts }) + " " + __n(jsonData.amount, productDetails.default_quantity_unit_purchase.name, productDetails.default_quantity_unit_purchase.name_plural), productDetails.product.name, $("#shopping_list_id option:selected").text())), Grocy.BaseUrl); window.parent.postMessage(WindowMessageBag("ShoppingListChanged", $("#shopping_list_id").val().toString()), Grocy.BaseUrl); window.parent.postMessage(WindowMessageBag("CloseAllModals"), Grocy.BaseUrl); }, @@ -223,4 +222,17 @@ if (GetUriParam("amount") !== undefined) Grocy.FrontendHelpers.ValidateForm('shoppinglist-form'); } +if (GetUriParam("embedded") !== undefined) +{ + if (GetUriParam("product") !== undefined) + { + Grocy.Components.ProductPicker.GetPicker().trigger('change'); + $("#display_amount").focus(); + } + else + { + Grocy.Components.ProductPicker.GetInputElement().focus(); + } +} + Grocy.Components.UserfieldsForm.Load();