Prepared auto night mode configuration option (references #71)

This commit is contained in:
Bernd Bestel 2018-09-30 13:33:21 +02:00
parent f451e65278
commit 5c79a80f7a
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
2 changed files with 95 additions and 6 deletions

View File

@ -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);

View File

@ -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
</script>
</head>
@ -206,6 +212,16 @@
<div class="dropdown-menu dropdown-menu-right">
<a class="dropdown-item logout-button discrete-link" href="{{ $U('/logout') }}"><i class="fas fa-sign-out-alt"></i>&nbsp;{{ $L('Logout') }}</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item logout-button discrete-link" href="{{ $U('/user/' . GROCY_USER_ID . '?changepw=true') }}"><i class="fas fa-key"></i>&nbsp;{{ $L('Change password') }}</a>
</div>
</li>
@endif
@if(GROCY_AUTHENTICATED === true)
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle discrete-link" href="#" data-toggle="dropdown"><i class="fas fa-sliders-h"></i> <span class="d-inline d-lg-none">{{ $L('View settings') }}</span></a>
<div class="dropdown-menu dropdown-menu-right">
<div class="dropdown-item">
<div class="form-check">
<input class="form-check-input" type="checkbox" id="auto-reload-enabled">
@ -214,6 +230,7 @@
</label>
</div>
</div>
<div class="dropdown-divider"></div>
<div class="dropdown-item">
<div class="form-check">
<input class="form-check-input" type="checkbox" id="night-mode-enabled">
@ -222,8 +239,18 @@
</label>
</div>
</div>
<div class="dropdown-divider"></div>
<a class="dropdown-item logout-button discrete-link" href="{{ $U('/user/' . GROCY_USER_ID . '?changepw=true') }}"><i class="fas fa-key"></i>&nbsp;{{ $L('Change password') }}</a>
<div class="dropdown-item">
<div class="form-check">
<input class="form-check-input" type="checkbox" id="auto-night-mode-enabled">
<label class="form-check-label" for="auto-night-mode-enabled">
{{ $L('Auto enable in time range') }}
</label>
</div>
<div class="form-inline">
<input type="text" class="form-control my-1" readonly id="auto-night-mode-time-range-from" placeholder="{{ $L('From') }} ({{ $L('in format') }} HH:mm)">
<input type="text" class="form-control" readonly id="auto-night-mode-time-range-to" placeholder="{{ $L('To') }} ({{ $L('in format') }} HH:mm)">
</div>
</div>
</div>
</li>
@endif