From 8c205941c727855eaeb12512ee8d67ef66d034c3 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Sat, 6 Jul 2019 18:15:53 +0200 Subject: [PATCH] Added that products can now also be consumed as spoiled from the stock overview page (option in the more/context menu per line) (closes #251) --- changelog/50_2.4.3_2019-xx-xx.md | 1 + localization/strings.pot | 3 +++ public/viewjs/stockoverview.js | 11 +++++++++-- views/stockoverview.blade.php | 8 ++++++++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/changelog/50_2.4.3_2019-xx-xx.md b/changelog/50_2.4.3_2019-xx-xx.md index 6c50b76e..cdbb5024 100644 --- a/changelog/50_2.4.3_2019-xx-xx.md +++ b/changelog/50_2.4.3_2019-xx-xx.md @@ -8,3 +8,4 @@ - Improved shopping list handling - Items can now be switched between lists (there is a shopping list dropdown on the item edit page) - Items can now be marked as "done" (new check mark button per item, when clicked, the item will be displayed greyed out, when clicked again the item will be displayed normally again) +- Improved that products can now also be consumed as spoiled from the stock overview page (option in the more/context menu per line) diff --git a/localization/strings.pot b/localization/strings.pot index 35ace53f..bdcfe217 100644 --- a/localization/strings.pot +++ b/localization/strings.pot @@ -1277,3 +1277,6 @@ msgstr "" msgid "Today" msgstr "" + +msgid "Consume %1$s of %2$s as spoiled" +msgstr "" diff --git a/public/viewjs/stockoverview.js b/public/viewjs/stockoverview.js index 018469d2..4e0d16df 100644 --- a/public/viewjs/stockoverview.js +++ b/public/viewjs/stockoverview.js @@ -90,8 +90,9 @@ $(document).on('click', '.product-consume-button', function(e) var productId = $(e.currentTarget).attr('data-product-id'); var consumeAmount = $(e.currentTarget).attr('data-consume-amount'); + var wasSpoiled = $(e.currentTarget).hasClass("product-consume-button-spoiled"); - Grocy.Api.Post('stock/products/' + productId + '/consume', { 'amount': consumeAmount }, + Grocy.Api.Post('stock/products/' + productId + '/consume', { 'amount': consumeAmount, 'spoiled': wasSpoiled }, function() { Grocy.Api.Get('stock/products/' + productId, @@ -155,8 +156,14 @@ $(document).on('click', '.product-consume-button', function(e) }); } + var toastMessage = __t('Removed %1$s of %2$s from stock', consumeAmount.toString() + " " + __n(consumeAmount, result.quantity_unit_stock.name, result.quantity_unit_stock.name_plural), result.product.name); + if (wasSpoiled) + { + toastMessage += " (" + __t("Spoiled") + ")"; + } + Grocy.FrontendHelpers.EndUiBusy(); - toastr.success(__t('Removed %1$s of %2$s from stock', consumeAmount.toString() + " " + __n(consumeAmount, result.quantity_unit_stock.name, result.quantity_unit_stock.name_plural), result.product.name)); + toastr.success(toastMessage); RefreshContextualTimeago(); RefreshStatistics(); }, diff --git a/views/stockoverview.blade.php b/views/stockoverview.blade.php index 44e7002b..4b07bc0a 100644 --- a/views/stockoverview.blade.php +++ b/views/stockoverview.blade.php @@ -122,6 +122,14 @@ {{ $__t('Edit product') }} + + + {{ $__t('Consume %1$s of %2$s as spoiled', '1 ' . FindObjectInArrayByPropertyValue($quantityunits, 'id', FindObjectInArrayByPropertyValue($products, 'id', $currentStockEntry->product_id)->qu_id_stock)->name, FindObjectInArrayByPropertyValue($products, 'id', $currentStockEntry->product_id)->name) }} +