mapcomplete/UI/Popup/SaveButton.ts

35 lines
1.3 KiB
TypeScript
Raw Permalink Normal View History

2020-10-14 12:15:09 +02:00
import {UIEventSource} from "../../Logic/UIEventSource";
import {UIElement} from "../UIElement";
import Translations from "../i18n/Translations";
import UserDetails, {OsmConnection} from "../../Logic/Osm/OsmConnection";
2020-07-05 18:59:47 +02:00
export class SaveButton extends UIElement {
2020-10-27 01:01:34 +01:00
2020-12-08 23:44:34 +01:00
private readonly _value: UIEventSource<any>;
private readonly _friendlyLogin: UIElement;
private readonly _userDetails: UIEventSource<UserDetails>;
2020-07-05 18:59:47 +02:00
2020-12-08 23:44:34 +01:00
constructor(value: UIEventSource<any>, osmConnection: OsmConnection) {
2020-07-05 18:59:47 +02:00
super(value);
2020-12-08 23:44:34 +01:00
this._userDetails = osmConnection?.userDetails;
2020-07-05 18:59:47 +02:00
if(value === undefined){
throw "No event source for savebutton, something is wrong"
}
this._value = value;
2020-10-27 01:01:34 +01:00
this._friendlyLogin = Translations.t.general.loginToStart.Clone()
.SetClass("login-button-friendly")
2020-12-08 23:44:34 +01:00
.onClick(() => osmConnection?.AttemptLogin())
2020-07-05 18:59:47 +02:00
}
2020-07-20 18:24:00 +02:00
InnerRender(): string {
2020-12-08 23:44:34 +01:00
if(this._userDetails != undefined && !this._userDetails.data.loggedIn){
2020-10-27 01:01:34 +01:00
return this._friendlyLogin.Render();
}
let inactive_class = ''
2020-12-08 23:44:34 +01:00
if (this._value.data === false || (this._value.data ?? "") === "") {
inactive_class = "btn-disabled";
2020-07-05 18:59:47 +02:00
}
return Translations.t.general.save.Clone().SetClass(`btn ${inactive_class}`).Render();
2020-07-05 18:59:47 +02:00
}
}