Only reload the page on external changes when there is no unsaved form data (fixes #73)

This commit is contained in:
Bernd Bestel 2018-09-30 09:57:42 +02:00
parent 77d82f22dc
commit d11dcb38fe
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
2 changed files with 14 additions and 1 deletions

View File

@ -191,3 +191,12 @@ Grocy.FrontendHelpers.ShowGenericError = function(message, exception)
console.error(exception); console.error(exception);
} }
$("form").on("keyup paste", "input, textarea", function()
{
$(this).closest("form").addClass("is-dirty");
});
$("form").on("click", "select", function()
{
$(this).closest("form").addClass("is-dirty");
});

View File

@ -11,6 +11,7 @@
// Check if the database has changed once a minute // Check if the database has changed once a minute
// If a change is detected, reload the current page, but only if already idling for at least 50 seconds // If a change is detected, reload the current page, but only if already idling for at least 50 seconds
// and when there is no unsaved form data
setInterval(function() setInterval(function()
{ {
Grocy.Api.Get('system/get-db-changed-time', Grocy.Api.Get('system/get-db-changed-time',
@ -21,7 +22,10 @@ setInterval(function()
{ {
if (Grocy.IdleTime >= 50) if (Grocy.IdleTime >= 50)
{ {
window.location.reload(); if ($("form.is-dirty").length === 0)
{
window.location.reload();
}
} }
Grocy.DatabaseChangedTime = newDbChangedTime; Grocy.DatabaseChangedTime = newDbChangedTime;