From 3762c1f79970e681b0cbeb2219200e4e569662e0 Mon Sep 17 00:00:00 2001
From: kriddles <54413450+kriddles@users.noreply.github.com>
Date: Sat, 25 Jan 2020 11:02:50 -0600
Subject: [PATCH] 450 consume meal plan product (#514)
* typo
* mealplan product consume
---
public/viewjs/mealplan.js | 59 +++++++++++++++++++++++++++++++++++++--
1 file changed, 56 insertions(+), 3 deletions(-)
diff --git a/public/viewjs/mealplan.js b/public/viewjs/mealplan.js
index fa826db5..84451aa2 100644
--- a/public/viewjs/mealplan.js
+++ b/public/viewjs/mealplan.js
@@ -206,13 +206,13 @@ var calendar = $("#calendar").fullCalendar({
element.html('\
\
' + productDetails.product.name + ' \
- " + __n(mealPlanEntry.product_amount, productDetails.quantity_unit_purchase.name, productDetails.quantity_unit_purchase.name_plural) + '
\
+ ' + mealPlanEntry.product_amount + " " + __n(mealPlanEntry.product_amount, productDetails.quantity_unit_purchase.name, productDetails.quantity_unit_purchase.name_plural) + '
\
' + fulfillmentIconHtml + " " + fulfillmentInfoHtml + '
\
' + costsAndCaloriesPerServing + ' \
\
\
+ \
\
');
@@ -419,7 +419,7 @@ Grocy.Components.RecipePicker.GetInputElement().keydown(function(event)
}
});
-$(document).on("keyodwn", "#servings", function(e)
+$(document).on("keydown", "#servings", function(e)
{
if (event.keyCode === 13) //Enter
{
@@ -489,6 +489,45 @@ $(document).on('click', '.recipe-order-missing-button', function(e)
});
});
+$(document).on('click', '.product-consume-button', function(e)
+{
+ e.preventDefault();
+
+ // Remove the focus from the current button
+ // to prevent that the tooltip stays until clicked anywhere else
+ document.activeElement.blur();
+
+ Grocy.FrontendHelpers.BeginUiBusy();
+
+ var productId = $(e.currentTarget).attr('data-product-id');
+ var consumeAmount = $(e.currentTarget).attr('data-product-amount');
+
+ Grocy.Api.Post('stock/products/' + productId + '/consume', { 'amount': consumeAmount, 'spoiled': false },
+ function(bookingResponse)
+ {
+ Grocy.Api.Get('stock/products/' + productId,
+ function(result)
+ {
+ 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) + '
' + __t("Undo") + '';
+
+ Grocy.FrontendHelpers.EndUiBusy();
+ toastr.success(toastMessage);
+ },
+ function(xhr)
+ {
+ Grocy.FrontendHelpers.EndUiBusy();
+ console.error(xhr);
+ }
+ );
+ },
+ function(xhr)
+ {
+ Grocy.FrontendHelpers.EndUiBusy();
+ console.error(xhr);
+ }
+ );
+});
+
$(document).on('click', '.recipe-consume-button', function(e)
{
// Remove the focus from the current button
@@ -598,3 +637,17 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
);
}
});
+
+function UndoStockTransaction(transactionId)
+{
+ Grocy.Api.Post('stock/transactions/' + transactionId.toString() + '/undo', { },
+ function (result)
+ {
+ toastr.success(__t("Transaction successfully undone"));
+ },
+ function (xhr)
+ {
+ console.error(xhr);
+ }
+ );
+};