mapcomplete/UI/OpeningHours/OpeningHoursPicker.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

48 lines
1.6 KiB
TypeScript
Raw Normal View History

import { UIEventSource } from "../../Logic/UIEventSource"
import OpeningHoursPickerTable from "./OpeningHoursPickerTable"
import { OH, OpeningHour } from "./OpeningHours"
import { InputElement } from "../Input/InputElement"
2021-06-10 01:36:20 +02:00
import BaseUIElement from "../BaseUIElement"
2020-10-04 01:04:46 +02:00
export default class OpeningHoursPicker extends InputElement<OpeningHour[]> {
public readonly IsSelected: UIEventSource<boolean> = new UIEventSource<boolean>(false)
2021-06-16 14:23:53 +02:00
private readonly _ohs: UIEventSource<OpeningHour[]>
2020-10-04 01:04:46 +02:00
private readonly _backgroundTable: OpeningHoursPickerTable
2020-09-30 22:22:58 +02:00
2020-10-04 12:55:44 +02:00
constructor(ohs: UIEventSource<OpeningHour[]> = new UIEventSource<OpeningHour[]>([])) {
2020-09-30 22:22:58 +02:00
super()
2020-10-04 01:04:46 +02:00
this._ohs = ohs
2020-09-30 22:22:58 +02:00
2021-06-16 14:23:53 +02:00
ohs.addCallback((oh) => {
ohs.setData(OH.MergeTimes(oh))
})
2020-09-30 22:22:58 +02:00
2021-06-16 14:23:53 +02:00
this._backgroundTable = new OpeningHoursPickerTable(this._ohs)
this._backgroundTable.ConstructElement()
2020-09-30 22:22:58 +02:00
}
2021-06-10 01:36:20 +02:00
InnerRender(): BaseUIElement {
return this._backgroundTable
}
2020-10-04 01:04:46 +02:00
GetValue(): UIEventSource<OpeningHour[]> {
return this._ohs
2020-09-30 22:22:58 +02:00
}
2020-10-04 01:04:46 +02:00
IsValid(t: OpeningHour[]): boolean {
return true
2020-09-30 22:22:58 +02:00
}
/**
*
* const rules = OH.ParseRule("Jul-Aug Sa closed; Mo,Tu,Th,Fr,PH 12:00-22:30, We 17:00-22:30, Sa 14:00-19:00, Su 10:00-21:00; Dec 24,25,31 off; Jan 1 off")
* const v = new UIEventSource(rules)
* const ohpicker = new OpeningHoursPicker(v)
* const html = ohpicker.InnerConstructElement()
* html !== undefined // => true
*/
2021-06-16 14:23:53 +02:00
protected InnerConstructElement(): HTMLElement {
return this._backgroundTable.ConstructElement()
}
2020-09-30 22:22:58 +02:00
}