mirror of
https://github.com/grocy/grocy.git
synced 2026-04-05 20:36:15 +02:00
51 lines
1.0 KiB
JavaScript
51 lines
1.0 KiB
JavaScript
import { BoolVal } from './extensions'
|
|
|
|
class HeaderClock
|
|
{
|
|
constructor(Grocy)
|
|
{
|
|
this.Grocy = Grocy;
|
|
this.HeaderClockInterval = null;
|
|
this.CheckHeaderClockEnabled();
|
|
|
|
if (this.Grocy.UserId !== -1 && BoolVal(this.Grocy.UserSettings.show_clock_in_header))
|
|
{
|
|
$("#show-clock-in-header").prop("checked", true);
|
|
}
|
|
}
|
|
|
|
RefreshHeaderClock()
|
|
{
|
|
$("#clock-small").text(moment().format("l LT"));
|
|
$("#clock-big").text(moment().format("LLLL"));
|
|
}
|
|
|
|
CheckHeaderClockEnabled()
|
|
{
|
|
if (this.Grocy.UserId === -1)
|
|
{
|
|
return;
|
|
}
|
|
|
|
// Refresh the clock in the header every second when enabled
|
|
if (BoolVal(this.Grocy.UserSettings.show_clock_in_header))
|
|
{
|
|
this.RefreshHeaderClock();
|
|
$("#clock-container").removeClass("d-none");
|
|
|
|
this.HeaderClockInterval = setInterval(this.RefreshHeaderClock, 1000);
|
|
}
|
|
else
|
|
{
|
|
if (this.HeaderClockInterval !== null)
|
|
{
|
|
clearInterval(this.HeaderClockInterval);
|
|
this.HeaderClockInterval = null;
|
|
}
|
|
|
|
$("#clock-container").addClass("d-none");
|
|
}
|
|
}
|
|
}
|
|
|
|
export { HeaderClock } |