diff --git a/localization/strings.pot b/localization/strings.pot
index 88ee0ff2..fa65c6b4 100644
--- a/localization/strings.pot
+++ b/localization/strings.pot
@@ -1720,3 +1720,12 @@ msgstr ""
msgid "Don't automatically switch to the compact view on mobile devices"
msgstr ""
+
+msgid "Edit note on %s"
+msgstr ""
+
+msgid "Edit product on %s"
+msgstr ""
+
+msgid "Edit recipe on %s"
+msgstr ""
diff --git a/public/viewjs/mealplan.js b/public/viewjs/mealplan.js
index 53a48fee..20929f1a 100644
--- a/public/viewjs/mealplan.js
+++ b/public/viewjs/mealplan.js
@@ -1,4 +1,6 @@
var firstRender = true;
+Grocy.IsMealPlanEntryEditAction = false;
+Grocy.MealPlanEntryEditObjectId = -1;
var firstDay = null;
if (!Grocy.CalendarFirstDayOfWeek.isEmpty())
@@ -132,6 +134,7 @@ var calendar = $("#calendar").fullCalendar({
' + costsAndCaloriesPerServing + ' \
\
\
+ \
\
\
\
@@ -217,6 +220,7 @@ var calendar = $("#calendar").fullCalendar({
' + costsAndCaloriesPerServing + ' \
\
\
+ \
\
\
\
@@ -255,6 +259,7 @@ var calendar = $("#calendar").fullCalendar({
' + mealPlanEntry.note + ' \
\
\
+ \
\
');
}
@@ -282,6 +287,7 @@ $(document).on("click", ".add-recipe-button", function(e)
Grocy.Components.RecipePicker.Clear();
$("#add-recipe-modal").modal("show");
Grocy.FrontendHelpers.ValidateForm("add-recipe-form");
+ Grocy.IsMealPlanEntryEditAction = false;
});
$(document).on("click", ".add-note-button", function(e)
@@ -293,6 +299,7 @@ $(document).on("click", ".add-note-button", function(e)
$("#note").val("");
$("#add-note-modal").modal("show");
Grocy.FrontendHelpers.ValidateForm("add-note-form");
+ Grocy.IsMealPlanEntryEditAction = false;
});
$(document).on("click", ".add-product-button", function(e)
@@ -304,6 +311,41 @@ $(document).on("click", ".add-product-button", function(e)
Grocy.Components.ProductPicker.Clear();
$("#add-product-modal").modal("show");
Grocy.FrontendHelpers.ValidateForm("add-product-form");
+ Grocy.IsMealPlanEntryEditAction = false;
+});
+
+$(document).on("click", ".edit-meal-plan-entry-button", function (e)
+{
+ var mealPlanEntry = JSON.parse($(this).parents(".fc-h-event:first").attr("data-meal-plan-entry"));
+
+ if (mealPlanEntry.type == "recipe")
+ {
+ $("#add-recipe-modal-title").text(__t("Edit recipe on %s", mealPlanEntry.day.toString()));
+ $("#day").val(mealPlanEntry.day.toString());
+ $("#recipe_servings").val(mealPlanEntry.recipe_servings);
+ Grocy.Components.RecipePicker.SetId(mealPlanEntry.recipe_id);
+ $("#add-recipe-modal").modal("show");
+ Grocy.FrontendHelpers.ValidateForm("add-recipe-form");
+ }
+ else if (mealPlanEntry.type == "product")
+ {
+ $("#add-product-modal-title").text(__t("Edit product on %s", mealPlanEntry.day.toString()));
+ $("#day").val(mealPlanEntry.day.toString());
+ Grocy.Components.ProductPicker.SetId(mealPlanEntry.product_id);
+ $("#add-product-modal").modal("show");
+ Grocy.FrontendHelpers.ValidateForm("add-product-form");
+ Grocy.Components.ProductPicker.GetPicker().trigger("change");
+ }
+ else if (mealPlanEntry.type == "note")
+ {
+ $("#add-note-modal-title").text(__t("Edit note on %s", mealPlanEntry.day.toString()));
+ $("#day").val(mealPlanEntry.day.toString());
+ $("#note").val(mealPlanEntry.note);
+ $("#add-note-modal").modal("show");
+ Grocy.FrontendHelpers.ValidateForm("add-note-form");
+ }
+ Grocy.IsMealPlanEntryEditAction = true;
+ Grocy.MealPlanEntryEditObjectId = mealPlanEntry.id;
});
$("#add-recipe-modal").on("shown.bs.modal", function(e)
@@ -346,16 +388,32 @@ $('#save-add-recipe-button').on('click', function(e)
return false;
}
- Grocy.Api.Post('objects/meal_plan', $('#add-recipe-form').serializeJSON(),
- function(result)
- {
- window.location.reload();
- },
- function(xhr)
- {
- Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
- }
- );
+ if (Grocy.IsMealPlanEntryEditAction)
+ {
+ Grocy.Api.Put('objects/meal_plan/' + Grocy.MealPlanEntryEditObjectId.toString(), $('#add-recipe-form').serializeJSON(),
+ function(result)
+ {
+ window.location.reload();
+ },
+ function(xhr)
+ {
+ Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
+ }
+ );
+ }
+ else
+ {
+ Grocy.Api.Post('objects/meal_plan', $('#add-recipe-form').serializeJSON(),
+ function(result)
+ {
+ window.location.reload();
+ },
+ function(xhr)
+ {
+ Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
+ }
+ );
+ }
});
$('#save-add-note-button').on('click', function(e)
@@ -369,16 +427,34 @@ $('#save-add-note-button').on('click', function(e)
var jsonData = $('#add-note-form').serializeJSON();
jsonData.day = $("#day").val();
- Grocy.Api.Post('objects/meal_plan', jsonData,
- function(result)
- {
- window.location.reload();
- },
- function(xhr)
- {
- Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
- }
- );
+
+ if (Grocy.IsMealPlanEntryEditAction)
+ {
+ Grocy.Api.Put('objects/meal_plan/' + Grocy.MealPlanEntryEditObjectId.toString(), jsonData,
+ function(result)
+ {
+ window.location.reload();
+ },
+ function(xhr)
+ {
+ Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
+ }
+ );
+ }
+ else
+ {
+ Grocy.Api.Post('objects/meal_plan', jsonData,
+ function(result)
+ {
+ window.location.reload();
+ },
+ function(xhr)
+ {
+ Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
+ }
+ );
+ }
+
});
$('#save-add-product-button').on('click', function(e)
@@ -397,16 +473,33 @@ $('#save-add-product-button').on('click', function(e)
delete jsonData.amount;
jsonData.product_qu_id = jsonData.qu_id;
delete jsonData.qu_id;
- Grocy.Api.Post('objects/meal_plan', jsonData,
- function(result)
- {
- window.location.reload();
- },
- function(xhr)
- {
- Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
- }
- );
+
+ if (Grocy.IsMealPlanEntryEditAction)
+ {
+ Grocy.Api.Put('objects/meal_plan/' + Grocy.MealPlanEntryEditObjectId.toString(), jsonData,
+ function (result)
+ {
+ window.location.reload();
+ },
+ function (xhr)
+ {
+ Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
+ }
+ );
+ }
+ else
+ {
+ Grocy.Api.Post('objects/meal_plan', jsonData,
+ function(result)
+ {
+ window.location.reload();
+ },
+ function(xhr)
+ {
+ Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
+ }
+ );
+ }
});
$('#add-recipe-form input').keydown(function (event)