diff --git a/public/js/grocy_clock.js b/public/js/grocy_clock.js index b5ff2bda..d617c0f6 100644 --- a/public/js/grocy_clock.js +++ b/public/js/grocy_clock.js @@ -12,6 +12,11 @@ function RefreshHeaderClock() Grocy.HeaderClockInterval = null; function CheckHeaderClockEnabled() { + if (Grocy.UserId === -1) + { + return; + } + // Refresh the clock in the header every second when enabled if (BoolVal(Grocy.UserSettings.show_clock_in_header)) { @@ -36,7 +41,7 @@ function CheckHeaderClockEnabled() } CheckHeaderClockEnabled(); -if (BoolVal(Grocy.UserSettings.show_clock_in_header)) +if (Grocy.UserId !== -1 && BoolVal(Grocy.UserSettings.show_clock_in_header)) { $("#show-clock-in-header").prop("checked", true); } diff --git a/public/js/grocy_dbchangedhandling.js b/public/js/grocy_dbchangedhandling.js index 96eacc80..77ee6c0c 100644 --- a/public/js/grocy_dbchangedhandling.js +++ b/public/js/grocy_dbchangedhandling.js @@ -1,13 +1,16 @@ -Grocy.Api.Get('system/db-changed-time', - function(result) - { - Grocy.DatabaseChangedTime = moment(result.changed_time); - }, - function(xhr) - { - console.error(xhr); - } -); +if (Grocy.UserId !== -1) +{ + Grocy.Api.Get('system/db-changed-time', + function(result) + { + Grocy.DatabaseChangedTime = moment(result.changed_time); + }, + function(xhr) + { + console.error(xhr); + } + ); +} // 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, @@ -56,7 +59,7 @@ setInterval(function() Grocy.IdleTime += 1; }, 1000); -if (BoolVal(Grocy.UserSettings.auto_reload_on_db_change)) +if (Grocy.UserId !== -1 && BoolVal(Grocy.UserSettings.auto_reload_on_db_change)) { $("#auto-reload-enabled").prop("checked", true); } diff --git a/public/js/grocy_nightmode.js b/public/js/grocy_nightmode.js index 801499de..7615b073 100644 --- a/public/js/grocy_nightmode.js +++ b/public/js/grocy_nightmode.js @@ -56,18 +56,21 @@ $("#auto-night-mode-time-range-goes-over-midgnight").on("change", function() CheckNightMode(); }); -$("#night-mode-enabled").prop("checked", BoolVal(Grocy.UserSettings.night_mode_enabled)); -$("#auto-night-mode-enabled").prop("checked", BoolVal(Grocy.UserSettings.auto_night_mode_enabled)); -$("#auto-night-mode-time-range-goes-over-midgnight").prop("checked", BoolVal(Grocy.UserSettings.auto_night_mode_time_range_goes_over_midnight)); -$("#auto-night-mode-enabled").trigger("change"); -$("#auto-night-mode-time-range-from").val(Grocy.UserSettings.auto_night_mode_time_range_from); -$("#auto-night-mode-time-range-from").trigger("keyup"); -$("#auto-night-mode-time-range-to").val(Grocy.UserSettings.auto_night_mode_time_range_to); -$("#auto-night-mode-time-range-to").trigger("keyup"); +if (Grocy.UserId !== -1) +{ + $("#night-mode-enabled").prop("checked", BoolVal(Grocy.UserSettings.night_mode_enabled)); + $("#auto-night-mode-enabled").prop("checked", BoolVal(Grocy.UserSettings.auto_night_mode_enabled)); + $("#auto-night-mode-time-range-goes-over-midgnight").prop("checked", BoolVal(Grocy.UserSettings.auto_night_mode_time_range_goes_over_midnight)); + $("#auto-night-mode-enabled").trigger("change"); + $("#auto-night-mode-time-range-from").val(Grocy.UserSettings.auto_night_mode_time_range_from); + $("#auto-night-mode-time-range-from").trigger("keyup"); + $("#auto-night-mode-time-range-to").val(Grocy.UserSettings.auto_night_mode_time_range_to); + $("#auto-night-mode-time-range-to").trigger("keyup"); +} function CheckNightMode() { - if (!BoolVal(Grocy.UserSettings.auto_night_mode_enabled)) + if (Grocy.UserId === -1 || !BoolVal(Grocy.UserSettings.auto_night_mode_enabled)) { return; } @@ -105,7 +108,10 @@ function CheckNightMode() } } } -CheckNightMode(); +if (Grocy.UserId !== -1) +{ + CheckNightMode(); +} if (Grocy.Mode === "production") { diff --git a/views/layout/default.blade.php b/views/layout/default.blade.php index 5d8d7b72..81fe5b82 100644 --- a/views/layout/default.blade.php +++ b/views/layout/default.blade.php @@ -57,9 +57,15 @@ Grocy.CalendarFirstDayOfWeek = '{{ GROCY_CALENDAR_FIRST_DAY_OF_WEEK }}'; Grocy.CalendarShowWeekNumbers = {{ BoolToString(GROCY_CALENDAR_SHOW_WEEK_OF_YEAR) }}; Grocy.GettextPo = {!! $GettextPo !!}; - Grocy.UserSettings = {!! json_encode($userSettings) !!}; Grocy.FeatureFlags = {!! json_encode($featureFlags) !!}; + + @if (GROCY_AUTHENTICATED) + Grocy.UserSettings = {!! json_encode($userSettings) !!}; Grocy.UserId = {{ GROCY_USER_ID }}; + @else + Grocy.UserSettings = { }; + Grocy.UserId = -1; + @endif