2020-10-14 12:15:09 +02:00
|
|
|
import {UIEventSource} from "../../Logic/UIEventSource";
|
|
|
|
import {UIElement} from "../UIElement";
|
|
|
|
import Translations from "../i18n/Translations";
|
2021-01-04 04:06:21 +01:00
|
|
|
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-10-27 01:01:34 +01:00
|
|
|
let clss = "save";
|
|
|
|
|
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();
|
|
|
|
}
|
2020-12-08 23:44:34 +01:00
|
|
|
if (this._value.data === false || (this._value.data ?? "") === "") {
|
2020-10-27 01:01:34 +01:00
|
|
|
clss = "save-non-active";
|
2020-07-05 18:59:47 +02:00
|
|
|
}
|
2020-10-27 01:01:34 +01:00
|
|
|
return Translations.t.general.save.Clone().SetClass(clss).Render();
|
2020-07-05 18:59:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|