Optimized product picker focus handling

This commit is contained in:
Bernd Bestel 2025-01-24 16:46:42 +01:00
parent f4226876c9
commit aad589eaca
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
2 changed files with 22 additions and 17 deletions

View File

@ -757,7 +757,7 @@ $(window).on("message", function(e)
} }
else if (data.Message == "CloseLastModal") else if (data.Message == "CloseLastModal")
{ {
$(".modal:visible").last().modal("hide"); $(".modal:visible").not(".custom-escape-key-handling").last().modal("hide");
} }
else if (data.Message == "ResizeResponsiveEmbeds") else if (data.Message == "ResizeResponsiveEmbeds")
{ {

View File

@ -210,13 +210,15 @@ $('#product_id_text_input').on('blur', function(e)
var buttons = { var buttons = {
cancel: { cancel: {
label: __t('Cancel'), label: __t('Cancel'),
className: 'btn-secondary responsive-button', className: 'btn-secondary responsive-button productpicker-workflow-cancel-button',
callback: function() callback: function()
{ {
Grocy.Components.ProductPicker.PopupOpen = false; Grocy.Components.ProductPicker.PopupOpen = false;
Grocy.Components.ProductPicker.SetValue(''); setTimeout(function()
Grocy.Components.ProductPicker.GetInputElement().focus(); {
Grocy.Components.ProductPicker.GetInputElement().select(); Grocy.Components.ProductPicker.GetInputElement().focus();
Grocy.Components.ProductPicker.GetInputElement().select();
}, 500);
} }
}, },
addnewproduct: { addnewproduct: {
@ -272,8 +274,11 @@ $('#product_id_text_input').on('blur', function(e)
{ {
toastr.warning(__t("Nothing was found for the given barcode")); toastr.warning(__t("Nothing was found for the given barcode"));
Grocy.FrontendHelpers.EndUiBusy($("form").first().attr("id")); Grocy.FrontendHelpers.EndUiBusy($("form").first().attr("id"));
Grocy.Components.ProductPicker.GetInputElement().focus(); setTimeout(function()
Grocy.Components.ProductPicker.GetInputElement().select(); {
Grocy.Components.ProductPicker.GetInputElement().focus();
Grocy.Components.ProductPicker.GetInputElement().select();
}, 500);
} }
else else
{ {
@ -334,35 +339,32 @@ $('#product_id_text_input').on('blur', function(e)
title: __t('Create or assign product'), title: __t('Create or assign product'),
onEscape: function() onEscape: function()
{ {
Grocy.Components.ProductPicker.PopupOpen = false; $(".productpicker-workflow-cancel-button").click();
Grocy.Components.ProductPicker.SetValue('');
Grocy.Components.ProductPicker.GetInputElement().focus();
Grocy.Components.ProductPicker.GetInputElement().select();
}, },
size: 'large', size: 'large',
backdrop: true, backdrop: true,
closeButton: false, closeButton: false,
buttons: buttons, buttons: buttons,
className: "wider" className: "wider custom-escape-key-handling",
}).on('keypress', function(e) }).on('keypress', function(e)
{ {
if (e.key === 'B' || e.key === 'b') if (e.key === 'B' || e.key === 'b')
{ {
$('.add-new-barcode-dialog-button').not(".d-none").click(); $('.add-new-barcode-dialog-button').not(".d-none").click();
} }
if (e.key === 'p' || e.key === 'P') else if (e.key === 'p' || e.key === 'P')
{ {
$('.add-new-product-dialog-button').not(".d-none").click(); $('.add-new-product-dialog-button').not(".d-none").click();
} }
if (e.key === 'a' || e.key === 'A') else if (e.key === 'a' || e.key === 'A')
{ {
$('.add-new-product-with-barcode-dialog-button').not(".d-none").click(); $('.add-new-product-with-barcode-dialog-button').not(".d-none").click();
} }
if (e.key === 'c' || e.key === 'C') else if (e.key === 'c' || e.key === 'C')
{ {
$('.retry-camera-scanning-button').not(".d-none").click(); $('.retry-camera-scanning-button').not(".d-none").click();
} }
if (e.key === 'e' || e.key === 'E') else if (e.key === 'e' || e.key === 'E')
{ {
$('.add-new-product-plugin-dialog-button').not(".d-none").click(); $('.add-new-product-plugin-dialog-button').not(".d-none").click();
} }
@ -374,7 +376,10 @@ $('#product_id_text_input').on('blur', function(e)
Grocy.Components.ProductPicker.Clear(); Grocy.Components.ProductPicker.Clear();
Grocy.FrontendHelpers.ValidateForm('consume-form'); Grocy.FrontendHelpers.ValidateForm('consume-form');
Grocy.Components.ProductPicker.ShowCustomError(__t('This product is not in stock')); Grocy.Components.ProductPicker.ShowCustomError(__t('This product is not in stock'));
Grocy.Components.ProductPicker.GetInputElement().focus(); setTimeout(function()
{
Grocy.Components.ProductPicker.GetInputElement().focus();
}, 500);
} }
}, },
function(xhr) function(xhr)