mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 01:32:38 +00:00
Save night mode enabled state and apply night mode class to <body> on server side (references #71)
This commit is contained in:
parent
d4227d2e41
commit
176333df5b
@ -1,7 +1,20 @@
|
||||
$("#night-mode-enabled").on("change", function()
|
||||
{
|
||||
var value = $(this).is(":checked");
|
||||
window.localStorage.setItem("night_mode", value);
|
||||
|
||||
jsonData = { };
|
||||
jsonData.value = value;
|
||||
console.log(jsonData);
|
||||
Grocy.Api.Post('user/settings/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)
|
||||
{
|
||||
@ -13,8 +26,7 @@
|
||||
}
|
||||
});
|
||||
|
||||
if (window.localStorage.getItem("night_mode") === "true")
|
||||
if (Grocy.NightModeEnabled)
|
||||
{
|
||||
$("body").addClass("night-mode");
|
||||
$("#night-mode-enabled").prop("checked", true);
|
||||
}
|
||||
|
@ -47,10 +47,18 @@
|
||||
@else
|
||||
Grocy.AutoReloadOnDatabaseChangeEnabled = true;
|
||||
@endif
|
||||
|
||||
@if(array_key_exists('night_mode_enabled', $userSettings))
|
||||
@php $nightModeEnabled = boolval($userSettings['night_mode_enabled']); @endphp
|
||||
Grocy.NightModeEnabled = {{ BoolToString($userSettings['night_mode_enabled']) }};
|
||||
@else
|
||||
@php $nightModeEnabled = false; @endphp
|
||||
Grocy.NightModeEnabled = false;
|
||||
@endif
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body class="fixed-nav">
|
||||
<body class="fixed-nav @if($nightModeEnabled == true) night-mode @endif">
|
||||
<nav id="mainNav" class="navbar navbar-expand-lg navbar-light fixed-top">
|
||||
<a class="navbar-brand py-0" href="{{ $U('/') }}"><img src="{{ $U('/img/grocy_logo.svg?v=', true) }}{{ $version }}" height="30"></a>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user