Optimized initial focus / workflow handling for recipeposform and shoppinglistitemform

This commit is contained in:
Bernd Bestel 2023-11-04 13:19:46 +01:00
parent fdf5559c25
commit f01ca33c33
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
2 changed files with 67 additions and 5 deletions

View File

@ -20,6 +20,27 @@ $('#save-recipe-pos-button').on('click', function(e)
Grocy.FrontendHelpers.BeginUiBusy("recipe-pos-form");
if (GetUriParam("flow") === "InplaceAddBarcodeToExistingProduct")
{
var jsonDataBarcode = {};
jsonDataBarcode.barcode = GetUriParam("barcode");
jsonDataBarcode.product_id = jsonData.product_id;
Grocy.Api.Post('objects/product_barcodes', jsonDataBarcode,
function(result)
{
$("#flow-info-InplaceAddBarcodeToExistingProduct").addClass("d-none");
$('#barcode-lookup-disabled-hint').addClass('d-none');
$('#barcode-lookup-hint').removeClass('d-none');
},
function(xhr)
{
Grocy.FrontendHelpers.EndUiBusy("inventory-form");
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response);
}
);
}
if (Grocy.EditMode === 'create')
{
Grocy.Api.Post('objects/recipes_pos', jsonData,
@ -94,12 +115,38 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
Grocy.FrontendHelpers.ValidateForm('recipe-pos-form');
if (Grocy.Components.ProductPicker.InProductAddWorkflow() === false)
if (!Grocy.Components.ProductPicker.InAnyFlow())
{
if (GetUriParam("product") !== undefined || Grocy.EditMode == "edit")
{
Grocy.Components.ProductPicker.GetPicker().trigger('change');
setTimeout(function()
{
$("#display_amount").focus();
}, 250);
}
else
{
setTimeout(function()
{
Grocy.Components.ProductPicker.GetInputElement().focus();
}, 250);
}
}
else
{
Grocy.Components.ProductPicker.GetPicker().trigger('change');
if (Grocy.Components.ProductPicker.InProductModifyWorkflow())
{
setTimeout(function()
{
Grocy.Components.ProductPicker.GetInputElement().focus();
}, 250);
}
}
if (Grocy.EditMode == "create")
{
Grocy.RecipePosFormInitialLoadDone = true;

View File

@ -273,7 +273,7 @@ if (GetUriParam("amount") !== undefined)
Grocy.FrontendHelpers.ValidateForm('shoppinglist-form');
}
if (GetUriParam("embedded") !== undefined)
if (!Grocy.Components.ProductPicker.InAnyFlow())
{
if (GetUriParam("product") !== undefined || Grocy.EditMode == "edit")
{
@ -282,7 +282,10 @@ if (GetUriParam("embedded") !== undefined)
Grocy.Components.ProductPicker.GetPicker().trigger('change');
}
setTimeout(function()
{
$("#display_amount").focus();
}, 250);
}
else
{
@ -292,6 +295,18 @@ if (GetUriParam("embedded") !== undefined)
}, 250);
}
}
else
{
Grocy.Components.ProductPicker.GetPicker().trigger('change');
if (Grocy.Components.ProductPicker.InProductModifyWorkflow())
{
setTimeout(function()
{
Grocy.Components.ProductPicker.GetInputElement().focus();
}, 250);
}
}
var eitherRequiredFields = $("#product_id,#product_id_text_input,#note");
eitherRequiredFields.prop('required', "");