diff --git a/public/viewjs/shoppinglist.js b/public/viewjs/shoppinglist.js index 6d8fe43f..fe020075 100644 --- a/public/viewjs/shoppinglist.js +++ b/public/viewjs/shoppinglist.js @@ -447,3 +447,13 @@ if ($(window).width() < 768 & window.location.hash !== "#compact" && !BoolVal(Gr { $("#shopping-list-compact-view-button").click(); } + +$(window).on("message", function(e) +{ + var data = e.originalEvent.data; + + if (data.Message === "ShoppingListChanged") + { + window.location.href = U('/shoppinglist?list=' + data.Payload); + } +}); diff --git a/public/viewjs/shoppinglistform.js b/public/viewjs/shoppinglistform.js index 820ae3e4..fbfe4836 100644 --- a/public/viewjs/shoppinglistform.js +++ b/public/viewjs/shoppinglistform.js @@ -10,12 +10,14 @@ Grocy.Api.Post('objects/shopping_lists', jsonData, function(result) { - window.location.href = U('/shoppinglist?list=' + result.created_object_id); + window.parent.postMessage(WindowMessageBag("ShoppingListChanged", result.created_object_id), Grocy.BaseUrl); + window.parent.postMessage(WindowMessageBag("Ready"), Grocy.BaseUrl); + window.parent.postMessage(WindowMessageBag("CloseAllModals"), Grocy.BaseUrl); }, function(xhr) { Grocy.FrontendHelpers.EndUiBusy("shopping-list-form"); - Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response) + Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response); } ); } @@ -24,12 +26,14 @@ Grocy.Api.Put('objects/shopping_lists/' + Grocy.EditObjectId, jsonData, function(result) { - window.location.href = U('/shoppinglist'); + window.parent.postMessage(WindowMessageBag("ShoppingListChanged", Grocy.EditObjectId), Grocy.BaseUrl); + window.parent.postMessage(WindowMessageBag("Ready"), Grocy.BaseUrl); + window.parent.postMessage(WindowMessageBag("CloseAllModals"), Grocy.BaseUrl); }, function(xhr) { Grocy.FrontendHelpers.EndUiBusy("shopping-list-form"); - Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response) + Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response); } ); } diff --git a/public/viewjs/shoppinglistitemform.js b/public/viewjs/shoppinglistitemform.js index f035108d..d7a953d4 100644 --- a/public/viewjs/shoppinglistitemform.js +++ b/public/viewjs/shoppinglistitemform.js @@ -19,6 +19,7 @@ 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.quantity_unit_purchase.name, productDetails.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); }, function(xhr) @@ -51,6 +52,7 @@ 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.quantity_unit_purchase.name, productDetails.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); }, function(xhr) @@ -82,6 +84,7 @@ 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.quantity_unit_purchase.name, productDetails.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); }, function(xhr) diff --git a/views/shoppinglist.blade.php b/views/shoppinglist.blade.php index c9ff2427..523ef3a2 100644 --- a/views/shoppinglist.blade.php +++ b/views/shoppinglist.blade.php @@ -40,10 +40,14 @@
- + {{ $__t('New shopping list') }} + + {{ $__t('Edit shopping list') }} + @@ -77,8 +81,8 @@