grocy/public/js/grocy_clock.js
Maximilian Bosch 2b0208e88c
Fix toggle for header-clock
I'm not 100% sure why, but with this change, the listener which calls
`CheckHeaderClockEnabled` will be invoked *before* the listener which
persists the setting.

If the setting is persisted before that, the clock doesn't show up when
enabling it in the settings-menu and appears/disappears in the exact
opposite way the setting is true/false.
2020-09-07 20:35:09 +02:00

48 lines
986 B
JavaScript

$(document).on("change", "#show-clock-in-header", function()
{
CheckHeaderClockEnabled();
});
function RefreshHeaderClock()
{
$("#clock-small").text(moment().format("l LT"));
$("#clock-big").text(moment().format("LLLL"));
}
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))
{
RefreshHeaderClock();
$("#clock-container").removeClass("d-none");
Grocy.HeaderClockInterval = setInterval(function()
{
RefreshHeaderClock();
}, 1000);
}
else
{
if (Grocy.HeaderClockInterval !== null)
{
clearInterval(Grocy.HeaderClockInterval);
Grocy.HeaderClockInterval = null;
}
$("#clock-container").addClass("d-none");
}
}
CheckHeaderClockEnabled();
if (Grocy.UserId !== -1 && BoolVal(Grocy.UserSettings.show_clock_in_header))
{
$("#show-clock-in-header").prop("checked", true);
}