From 5c79a80f7a4ddc97e38c2f58120a12fec2bdca37 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Sun, 30 Sep 2018 13:33:21 +0200 Subject: [PATCH] Prepared auto night mode configuration option (references #71) --- public/js/grocy_nightmode.js | 70 ++++++++++++++++++++++++++++++++-- views/layout/default.blade.php | 31 ++++++++++++++- 2 files changed, 95 insertions(+), 6 deletions(-) diff --git a/public/js/grocy_nightmode.js b/public/js/grocy_nightmode.js index 093af246..5ff42087 100644 --- a/public/js/grocy_nightmode.js +++ b/public/js/grocy_nightmode.js @@ -4,7 +4,6 @@ jsonData = { }; jsonData.value = value; - console.log(jsonData); Grocy.Api.Post('user/settings/night_mode_enabled', jsonData, function(result) { @@ -26,7 +25,70 @@ } }); -if (Grocy.NightModeEnabled) +$("#auto-night-mode-enabled").on("change", function() { - $("#night-mode-enabled").prop("checked", true); -} + var value = $(this).is(":checked"); + + jsonData = { }; + jsonData.value = value; + Grocy.Api.Post('user/settings/auto_night_mode_enabled', jsonData, + function(result) + { + // Nothing to do... + }, + function(xhr) + { + Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response) + } + ); + + if (value) + { + $("#auto-night-mode-time-range-from").prop("readonly", false); + $("#auto-night-mode-time-range-to").prop("readonly", false); + } + else + { + $("#auto-night-mode-time-range-from").prop("readonly", true); + $("#auto-night-mode-time-range-to").prop("readonly", true); + } +}); + +$("#auto-night-mode-time-range-from").on("blur", function() +{ + var value = $(this).val(); + + jsonData = { }; + jsonData.value = value; + Grocy.Api.Post('user/settings/auto_night_mode_time_range_from', jsonData, + function(result) + { + // Nothing to do... + }, + function(xhr) + { + Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response) + } + ); +}); + +$("#auto-night-mode-time-range-to").on("blur", function() +{ + var value = $(this).val(); + + jsonData = { }; + jsonData.value = value; + Grocy.Api.Post('user/settings/auto_night_mode_time_range_to', jsonData, + function(result) + { + // Nothing to do... + }, + function(xhr) + { + Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response) + } + ); +}); + +$("#night-mode-enabled").prop("checked", Grocy.NightModeEnabled); +$("#auto-night-mode-enabled").prop("checked", Grocy.AutoNightModeEnabled); diff --git a/views/layout/default.blade.php b/views/layout/default.blade.php index 803d9be7..4831d4d2 100644 --- a/views/layout/default.blade.php +++ b/views/layout/default.blade.php @@ -56,6 +56,12 @@ @php $nightModeEnabled = false; @endphp Grocy.NightModeEnabled = false; @endif + + @if(array_key_exists('auto_night_mode_enabled', $userSettings)) + Grocy.AutoNightModeEnabled = {{ BoolToString($userSettings['auto_night_mode_enabled']) }}; + @else + Grocy.AutoNightModeEnabled = false; + @endif @@ -206,6 +212,16 @@ + + @endif + + @if(GROCY_AUTHENTICATED === true) + @endif