mapcomplete/UI/Popup/SaveButton.ts

35 lines
1.1 KiB
TypeScript
Raw Normal View History

2020-10-14 10:15:09 +00:00
import {UIEventSource} from "../../Logic/UIEventSource";
import {UIElement} from "../UIElement";
import Translations from "../i18n/Translations";
2020-10-27 00:01:34 +00:00
import State from "../../State";
2020-07-05 16:59:47 +00:00
export class SaveButton extends UIElement {
2020-10-27 00:01:34 +00:00
2020-07-05 16:59:47 +00:00
private _value: UIEventSource<any>;
2020-10-27 00:01:34 +00:00
private _friendlyLogin: UIElement;
2020-07-05 16:59:47 +00:00
constructor(value: UIEventSource<any>) {
super(value);
if(value === undefined){
throw "No event source for savebutton, something is wrong"
}
this._value = value;
2020-10-27 00:01:34 +00:00
this._friendlyLogin = Translations.t.general.loginToStart.Clone()
.SetClass("login-button-friendly")
.onClick(() => State.state.osmConnection.AttemptLogin())
2020-07-05 16:59:47 +00:00
}
2020-07-20 16:24:00 +00:00
InnerRender(): string {
2020-10-27 00:01:34 +00:00
let clss = "save";
if(State.state !== undefined && !State.state.osmConnection.userDetails.data.loggedIn){
return this._friendlyLogin.Render();
}
if ((this._value.data ?? "") === "") {
clss = "save-non-active";
2020-07-05 16:59:47 +00:00
}
2020-10-27 00:01:34 +00:00
return Translations.t.general.save.Clone().SetClass(clss).Render();
2020-07-05 16:59:47 +00:00
}
}