2022-06-06 19:37:22 +02:00
|
|
|
import { ImmutableStore, Store } from "../../Logic/UIEventSource"
|
2020-10-14 12:15:09 +02:00
|
|
|
import Translations from "../i18n/Translations"
|
2021-06-12 02:58:32 +02:00
|
|
|
import { OsmConnection } from "../../Logic/Osm/OsmConnection"
|
|
|
|
import Toggle from "../Input/Toggle"
|
2022-05-06 12:41:24 +02:00
|
|
|
import BaseUIElement from "../BaseUIElement"
|
2020-07-05 18:59:47 +02:00
|
|
|
|
2021-06-14 02:39:23 +02:00
|
|
|
export class SaveButton extends Toggle {
|
2022-06-05 02:24:14 +02:00
|
|
|
constructor(
|
|
|
|
value: Store<any>,
|
|
|
|
osmConnection: OsmConnection,
|
|
|
|
textEnabled?: BaseUIElement,
|
|
|
|
textDisabled?: BaseUIElement
|
|
|
|
) {
|
2021-06-12 02:58:32 +02:00
|
|
|
if (value === undefined) {
|
2020-07-05 18:59:47 +02:00
|
|
|
throw "No event source for savebutton, something is wrong"
|
|
|
|
}
|
2021-06-12 02:58:32 +02:00
|
|
|
|
|
|
|
const pleaseLogin = Translations.t.general.loginToStart
|
|
|
|
.Clone()
|
2020-10-27 01:01:34 +01:00
|
|
|
.SetClass("login-button-friendly")
|
2020-12-08 23:44:34 +01:00
|
|
|
.onClick(() => osmConnection?.AttemptLogin())
|
2021-06-12 02:58:32 +02:00
|
|
|
|
|
|
|
const isSaveable = value.map((v) => v !== false && (v ?? "") !== "")
|
|
|
|
|
2022-05-06 12:41:24 +02:00
|
|
|
const saveEnabled = (textEnabled ?? Translations.t.general.save.Clone()).SetClass(`btn`)
|
|
|
|
const saveDisabled = (textDisabled ?? Translations.t.general.save.Clone()).SetClass(
|
|
|
|
`btn btn-disabled`
|
2021-06-12 02:58:32 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
const save = new Toggle(saveEnabled, saveDisabled, isSaveable)
|
2022-06-06 19:37:22 +02:00
|
|
|
super(save, pleaseLogin, osmConnection?.isLoggedIn ?? new ImmutableStore(false))
|
2020-07-05 18:59:47 +02:00
|
|
|
}
|
|
|
|
}
|