Improved the meal plan add-dialogs (closes #540)

This commit is contained in:
Bernd Bestel 2020-02-03 20:04:22 +01:00
parent b4a759c0fc
commit 58cff18b03
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
2 changed files with 39 additions and 2 deletions

View File

@ -12,6 +12,9 @@
- Fixed that when editing a recipe ingredient which had "Only check if a single unit is in stock" set, not any quantity unit could be picked and the amount stayed empty
- Fixed that when reloading the "new recipe"-page (or when it gets auto-reloaded due to "Auto reload on external changes" is enabled), for each reload a new recipe was created
### Meal plan improvements
- Improved that all add-dialogs can be submitted by using `ENTER` and that the next input is automatically selected after selecting a recipe/product
### General & other improvements/fixes
- Optimized the top navbar height to waste less space
- Fixed that the "contextual time ago" of date/time pickers was not displayed

View File

@ -277,6 +277,7 @@ $(document).on("click", ".add-recipe-button", function(e)
$("#add-recipe-modal-title").text(__t("Add recipe to %s", day.toString()));
$("#day").val(day.toString());
$("#recipe_servings").val(1);
Grocy.Components.RecipePicker.Clear();
$("#add-recipe-modal").modal("show");
Grocy.FrontendHelpers.ValidateForm("add-recipe-form");
@ -407,7 +408,7 @@ $('#save-add-product-button').on('click', function(e)
);
});
Grocy.Components.RecipePicker.GetInputElement().keydown(function(event)
$('#add-recipe-form input').keydown(function (event)
{
if (event.keyCode === 13) //Enter
{
@ -424,6 +425,23 @@ Grocy.Components.RecipePicker.GetInputElement().keydown(function(event)
}
});
$('#add-product-form input').keydown(function (event)
{
if (event.keyCode === 13) //Enter
{
event.preventDefault();
if (document.getElementById("add-product-form").checkValidity() === false) //There is at least one validation error
{
return false;
}
else
{
$("#save-add-product-button").click();
}
}
});
$(document).on("keydown", "#servings", function(e)
{
if (event.keyCode === 13) //Enter
@ -629,10 +647,11 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
Grocy.Api.Get('stock/products/' + productId,
function(productDetails)
{
Grocy.Components.ProductAmountPicker.Reload(productDetails.product.id, productDetails.quantity_unit_stock.id, true);
Grocy.Components.ProductAmountPicker.Reload(productDetails.product.id, productDetails.quantity_unit_stock.id);
$('#display_amount').val(1);
$('#display_amount').focus();
$('#display_amount').select();
$(".input-group-productamountpicker").trigger("change");
Grocy.FrontendHelpers.ValidateForm('add-product-form');
},
@ -657,3 +676,18 @@ function UndoStockTransaction(transactionId)
}
);
};
Grocy.Components.RecipePicker.GetPicker().on('change', function(e)
{
var recipeId = $(e.target).val();
if (recipeId)
{
// Does not work (clears the RecipePicker) when done immediately, don't know why...
setTimeout(function()
{
$("#recipe_servings").focus();
$("#recipe_servings").select();
}, 200);
}
});