import { Controller } from "./main"; export class NightLampView { private readonly night_lamp_only_when_dark: HTMLInputElement; private readonly night_lamp_time_start: HTMLSelectElement; private readonly night_lamp_time_end: HTMLSelectElement; constructor(controller:Controller){ (document.getElementById("lightview") as HTMLElement).innerHTML = require('./nightlightview.html') as string; this.night_lamp_only_when_dark = document.getElementById("night_lamp_only_when_dark") as HTMLInputElement; this.night_lamp_only_when_dark.onchange = controller.configChanged this.night_lamp_time_start = document.getElementById("night_lamp_time_start") as HTMLSelectElement; this.night_lamp_time_start.onchange = controller.configChanged for (let i = 0; i < 24; i++) { let option = document.createElement("option"); if (i == 20){ option.selected = true } option.innerText = i.toString(); this.night_lamp_time_start.appendChild(option); } this.night_lamp_time_end = document.getElementById("night_lamp_time_end") as HTMLSelectElement; this.night_lamp_time_end.onchange = controller.configChanged for (let i = 0; i < 24; i++) { let option = document.createElement("option"); if (i == 1){ option.selected = true } option.innerText = i.toString(); this.night_lamp_time_end.appendChild(option); } } setConfig(nightLamp: NightLampConfig) { this.night_lamp_only_when_dark.checked = nightLamp.night_lamp_only_when_dark this.night_lamp_time_start.value = nightLamp.night_lamp_hour_start.toString(); this.night_lamp_time_end.value = nightLamp.night_lamp_hour_end.toString(); } getConfig(): NightLampConfig { return { night_lamp_hour_start: +this.night_lamp_time_start.value, night_lamp_hour_end: +this.night_lamp_time_end.value, night_lamp_only_when_dark: this.night_lamp_only_when_dark.checked, } } }