From d11dcb38fe1d2e70a31449fa3a590eca458facf1 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Sun, 30 Sep 2018 09:57:42 +0200 Subject: [PATCH] Only reload the page on external changes when there is no unsaved form data (fixes #73) --- public/js/grocy.js | 9 +++++++++ public/js/grocy_dbchangedhandling.js | 6 +++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/public/js/grocy.js b/public/js/grocy.js index 24b8fd29..45edcc8b 100644 --- a/public/js/grocy.js +++ b/public/js/grocy.js @@ -191,3 +191,12 @@ Grocy.FrontendHelpers.ShowGenericError = function(message, 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"); +}); diff --git a/public/js/grocy_dbchangedhandling.js b/public/js/grocy_dbchangedhandling.js index e35fa2cd..d32b6231 100644 --- a/public/js/grocy_dbchangedhandling.js +++ b/public/js/grocy_dbchangedhandling.js @@ -11,6 +11,7 @@ // 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 +// and when there is no unsaved form data setInterval(function() { Grocy.Api.Get('system/get-db-changed-time', @@ -21,7 +22,10 @@ setInterval(function() { if (Grocy.IdleTime >= 50) { - window.location.reload(); + if ($("form.is-dirty").length === 0) + { + window.location.reload(); + } } Grocy.DatabaseChangedTime = newDbChangedTime;