2020-10-27 01:01:34 +01:00
|
|
|
import {UIElement} from "../UIElement";
|
|
|
|
import {UIEventSource} from "../../Logic/UIEventSource";
|
|
|
|
import TagRenderingConfig from "../../Customizations/JSON/TagRenderingConfig";
|
|
|
|
import TagRenderingQuestion from "./TagRenderingQuestion";
|
|
|
|
import Translations from "../i18n/Translations";
|
|
|
|
import Combine from "../Base/Combine";
|
|
|
|
import TagRenderingAnswer from "./TagRenderingAnswer";
|
|
|
|
import State from "../../State";
|
2020-11-06 01:58:26 +01:00
|
|
|
import Svg from "../../Svg";
|
2021-03-22 03:05:08 +01:00
|
|
|
import {TagUtils} from "../../Logic/TagUtils";
|
2020-10-27 01:01:34 +01:00
|
|
|
|
|
|
|
export default class EditableTagRendering extends UIElement {
|
2021-01-04 04:06:21 +01:00
|
|
|
private readonly _tags: UIEventSource<any>;
|
|
|
|
private readonly _configuration: TagRenderingConfig;
|
2020-10-27 01:01:34 +01:00
|
|
|
|
|
|
|
private _editMode: UIEventSource<boolean> = new UIEventSource<boolean>(false);
|
|
|
|
private _editButton: UIElement;
|
|
|
|
|
|
|
|
private _question: UIElement;
|
|
|
|
private _answer: UIElement;
|
|
|
|
|
|
|
|
constructor(tags: UIEventSource<any>,
|
|
|
|
configuration: TagRenderingConfig) {
|
|
|
|
super(tags);
|
|
|
|
this._tags = tags;
|
|
|
|
this._configuration = configuration;
|
|
|
|
|
|
|
|
this.ListenTo(this._editMode);
|
|
|
|
this.ListenTo(State.state?.osmConnection?.userDetails)
|
|
|
|
|
|
|
|
this._answer = new TagRenderingAnswer(tags, configuration);
|
2021-02-21 01:36:31 +01:00
|
|
|
this._answer.SetClass("w-full")
|
2020-11-17 16:29:51 +01:00
|
|
|
this._question = this.GenerateQuestion();
|
|
|
|
this.dumbMode = false;
|
2020-10-27 01:01:34 +01:00
|
|
|
|
|
|
|
if (this._configuration.question !== undefined) {
|
2020-11-20 14:00:37 +01:00
|
|
|
if (State.state?.featureSwitchUserbadge?.data) {
|
2020-11-16 01:59:30 +01:00
|
|
|
// 2.3em total width
|
|
|
|
const self = this;
|
|
|
|
this._editButton =
|
|
|
|
Svg.pencil_svg().SetClass("edit-button")
|
|
|
|
.onClick(() => {
|
|
|
|
self._editMode.setData(true);
|
|
|
|
});
|
2020-11-12 12:21:34 +01:00
|
|
|
}
|
2020-11-16 01:59:30 +01:00
|
|
|
}
|
|
|
|
}
|
2020-10-27 01:01:34 +01:00
|
|
|
|
2021-01-06 01:11:07 +01:00
|
|
|
InnerRender(): string {
|
|
|
|
if (!this._configuration?.condition?.matchesProperties(this._tags.data)) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
if (this._editMode.data) {
|
|
|
|
return this._question.Render();
|
|
|
|
}
|
2021-03-13 17:25:44 +01:00
|
|
|
if(!this._configuration.IsKnown(this._tags.data)){
|
|
|
|
return ""
|
2021-01-06 01:11:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return new Combine([this._answer,
|
|
|
|
(State.state?.osmConnection?.userDetails?.data?.loggedIn ?? true) ? this._editButton : undefined
|
2021-01-21 05:55:52 +01:00
|
|
|
]).SetClass("flex w-full break-word justify-between text-default landscape:w-1/2 landscape:p-2 pb-2 border-b border-gray-300 mb-2")
|
2021-01-06 01:11:07 +01:00
|
|
|
.Render();
|
|
|
|
}
|
|
|
|
|
2020-11-16 01:59:30 +01:00
|
|
|
private GenerateQuestion() {
|
|
|
|
const self = this;
|
|
|
|
if (this._configuration.question !== undefined) {
|
2020-10-27 01:01:34 +01:00
|
|
|
// And at last, set up the skip button
|
|
|
|
const cancelbutton =
|
|
|
|
Translations.t.general.cancel.Clone()
|
2021-01-24 22:20:40 +01:00
|
|
|
.SetClass("btn btn-secondary mr-3")
|
2020-10-27 01:01:34 +01:00
|
|
|
.onClick(() => {
|
|
|
|
self._editMode.setData(false)
|
|
|
|
});
|
|
|
|
|
2020-11-16 01:59:30 +01:00
|
|
|
return new TagRenderingQuestion(this._tags, this._configuration,
|
2020-10-27 01:01:34 +01:00
|
|
|
() => {
|
|
|
|
self._editMode.setData(false)
|
|
|
|
},
|
|
|
|
cancelbutton)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|