2020-06-29 03:12:44 +02:00
|
|
|
import {UIElement} from "./UIElement";
|
|
|
|
import {UIEventSource} from "./UIEventSource";
|
|
|
|
import {Tag} from "../Logic/TagsFilter";
|
|
|
|
import {FilteredLayer} from "../Logic/FilteredLayer";
|
|
|
|
import {FixedUiElement} from "./Base/FixedUiElement";
|
|
|
|
import {Button} from "./Base/Button";
|
2020-07-24 15:52:21 +02:00
|
|
|
import Translations from "./i18n/Translations";
|
|
|
|
import Combine from "./Base/Combine";
|
2020-07-29 18:35:46 +02:00
|
|
|
import {SubtleButton} from "./Base/SubtleButton";
|
|
|
|
import {VerticalCombine} from "./Base/VerticalCombine";
|
2020-07-29 21:50:19 +02:00
|
|
|
import Locale from "./i18n/Locale";
|
2020-07-30 00:59:08 +02:00
|
|
|
import {Changes} from "../Logic/Osm/Changes";
|
|
|
|
import {UserDetails} from "../Logic/Osm/OsmConnection";
|
2020-07-31 01:45:54 +02:00
|
|
|
import {State} from "../State";
|
2020-07-29 18:35:46 +02:00
|
|
|
|
2020-06-29 03:12:44 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Asks to add a feature at the last clicked location, at least if zoom is sufficient
|
|
|
|
*/
|
|
|
|
export class SimpleAddUI extends UIElement {
|
|
|
|
private _addButtons: UIElement[];
|
2020-07-31 01:45:54 +02:00
|
|
|
|
2020-07-31 16:17:16 +02:00
|
|
|
private _confirmPreset: UIEventSource<{
|
|
|
|
description: string | UIElement,
|
|
|
|
name: string | UIElement,
|
|
|
|
icon: string,
|
|
|
|
tags: Tag[],
|
|
|
|
layerToAddTo: FilteredLayer
|
|
|
|
}>
|
|
|
|
= new UIEventSource(undefined);
|
2020-07-29 18:35:46 +02:00
|
|
|
private confirmButton: UIElement = undefined;
|
|
|
|
private cancelButton: UIElement;
|
2020-07-29 21:48:41 +02:00
|
|
|
private goToInboxButton: UIElement = new SubtleButton("./assets/envelope.svg",
|
2020-07-29 21:32:51 +02:00
|
|
|
Translations.t.general.goToInbox, {url:"https://www.openstreetmap.org/messages/inbox", newTab: false});
|
2020-07-29 18:35:46 +02:00
|
|
|
|
2020-07-31 16:17:16 +02:00
|
|
|
constructor() {
|
2020-07-31 01:45:54 +02:00
|
|
|
super(State.state.locationControl);
|
2020-07-29 21:50:19 +02:00
|
|
|
this.ListenTo(Locale.language);
|
2020-07-31 01:45:54 +02:00
|
|
|
this.ListenTo(State.state.osmConnection.userDetails);
|
2020-07-31 16:17:16 +02:00
|
|
|
|
|
|
|
this.ListenTo(State.state.layerUpdater.runningQuery);
|
|
|
|
|
2020-06-29 03:12:44 +02:00
|
|
|
this._addButtons = [];
|
2020-07-29 18:35:46 +02:00
|
|
|
this.ListenTo(this._confirmPreset);
|
|
|
|
this.clss = "add-ui"
|
2020-06-29 03:12:44 +02:00
|
|
|
|
2020-07-29 18:35:46 +02:00
|
|
|
const self = this;
|
2020-07-31 16:17:16 +02:00
|
|
|
for (const layer of State.state.filteredLayers.data) {
|
|
|
|
for (const preset of layer.layerDef.presets) {
|
|
|
|
|
|
|
|
|
|
|
|
// <button type='button'> looks SO retarded
|
|
|
|
// the default type of button is 'submit', which performs a POST and page reload
|
|
|
|
const button =
|
|
|
|
new SubtleButton(
|
|
|
|
preset.icon,
|
|
|
|
new Combine([
|
|
|
|
"<b>",
|
|
|
|
preset.title,
|
|
|
|
"</b><br/>",
|
|
|
|
preset.description !== undefined ? preset.description : ""])
|
|
|
|
).onClick(
|
|
|
|
() => {
|
|
|
|
self.confirmButton = new SubtleButton(preset.icon,
|
|
|
|
new Combine([
|
|
|
|
"Add a ",
|
|
|
|
"<b>",
|
|
|
|
preset.title,
|
|
|
|
"</b> here<br/>",
|
|
|
|
preset.description !== undefined ? preset.description : ""]));
|
|
|
|
self.confirmButton.onClick(self.CreatePoint(preset.tags, layer));
|
|
|
|
self._confirmPreset.setData({
|
|
|
|
tags: preset.tags,
|
|
|
|
layerToAddTo: layer,
|
|
|
|
name: preset.title,
|
|
|
|
description: preset.description,
|
|
|
|
icon: preset.icon
|
|
|
|
});
|
|
|
|
}
|
2020-07-29 18:35:46 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-06-29 03:12:44 +02:00
|
|
|
this._addButtons.push(button);
|
2020-07-31 16:17:16 +02:00
|
|
|
}
|
2020-06-29 03:12:44 +02:00
|
|
|
}
|
2020-07-29 18:35:46 +02:00
|
|
|
|
|
|
|
this.cancelButton = new SubtleButton(
|
2020-07-29 21:48:41 +02:00
|
|
|
"./assets/close.svg",
|
2020-07-29 18:35:46 +02:00
|
|
|
Translations.t.general.cancel
|
|
|
|
).onClick(() => {
|
|
|
|
self._confirmPreset.setData(undefined);
|
|
|
|
})
|
2020-06-29 03:12:44 +02:00
|
|
|
}
|
|
|
|
|
2020-07-31 16:17:16 +02:00
|
|
|
private CreatePoint(tags: Tag[], layerToAddTo: FilteredLayer) {
|
2020-06-29 03:12:44 +02:00
|
|
|
const self = this;
|
|
|
|
return () => {
|
|
|
|
|
2020-07-31 04:58:58 +02:00
|
|
|
const loc = State.state.bm.LastClickLocation.data;
|
2020-07-31 16:17:16 +02:00
|
|
|
let feature = State.state.changes.createElement(tags, loc.lat, loc.lon);
|
|
|
|
layerToAddTo.AddNewElement(feature);
|
2020-07-31 01:45:54 +02:00
|
|
|
State.state.selectedElement.setData({feature: feature});
|
2020-06-29 03:12:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-20 18:24:00 +02:00
|
|
|
InnerRender(): string {
|
2020-07-29 18:35:46 +02:00
|
|
|
|
2020-07-31 01:45:54 +02:00
|
|
|
const userDetails = State.state.osmConnection.userDetails;
|
2020-07-29 18:35:46 +02:00
|
|
|
|
|
|
|
if (this._confirmPreset.data !== undefined) {
|
|
|
|
|
2020-07-31 01:45:54 +02:00
|
|
|
if(userDetails.data.dryRun){
|
2020-07-31 16:17:16 +02:00
|
|
|
this.CreatePoint(this._confirmPreset.data.tags, this._confirmPreset.data.layerToAddTo)();
|
2020-07-31 04:58:58 +02:00
|
|
|
return "";
|
2020-07-29 21:48:41 +02:00
|
|
|
}
|
2020-07-29 18:35:46 +02:00
|
|
|
|
|
|
|
return new Combine([
|
|
|
|
Translations.t.general.add.confirmIntro.Subs({title: this._confirmPreset.data.name}),
|
2020-07-31 01:45:54 +02:00
|
|
|
userDetails.data.dryRun ? "<span class='alert'>TESTING - changes won't be saved</span>":"",
|
2020-07-29 18:35:46 +02:00
|
|
|
this.confirmButton,
|
|
|
|
this.cancelButton
|
|
|
|
|
|
|
|
]).Render();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let header: UIElement = Translations.t.general.add.header;
|
|
|
|
|
2020-07-30 00:59:08 +02:00
|
|
|
|
2020-07-31 01:45:54 +02:00
|
|
|
if(userDetails === undefined){
|
2020-07-30 00:59:08 +02:00
|
|
|
return header.Render();
|
|
|
|
}
|
|
|
|
|
2020-07-31 01:45:54 +02:00
|
|
|
if (!userDetails.data.loggedIn) {
|
2020-07-24 15:52:21 +02:00
|
|
|
return new Combine([header, Translations.t.general.add.pleaseLogin]).Render()
|
2020-07-15 13:15:36 +02:00
|
|
|
}
|
|
|
|
|
2020-07-31 01:45:54 +02:00
|
|
|
if (userDetails.data.unreadMessages > 0) {
|
2020-07-29 18:35:46 +02:00
|
|
|
return new Combine([header, "<span class='alert'>",
|
|
|
|
Translations.t.general.readYourMessages,
|
2020-07-29 19:02:36 +02:00
|
|
|
"</span>",
|
|
|
|
this.goToInboxButton
|
|
|
|
]).Render();
|
2020-07-29 18:35:46 +02:00
|
|
|
}
|
|
|
|
|
2020-07-31 01:45:54 +02:00
|
|
|
if (userDetails.data.dryRun) {
|
2020-07-29 18:35:46 +02:00
|
|
|
header = new Combine([header,
|
|
|
|
"<span class='alert'>",
|
|
|
|
"Test mode - changes won't be saved",
|
|
|
|
"</span>"
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2020-07-31 01:45:54 +02:00
|
|
|
if (userDetails.data.csCount < 5) {
|
2020-07-29 18:35:46 +02:00
|
|
|
return new Combine([header, "<span class='alert'>",
|
|
|
|
Translations.t.general.fewChangesBefore,
|
|
|
|
"</span>"]).Render();
|
|
|
|
}
|
|
|
|
|
2020-07-31 01:45:54 +02:00
|
|
|
if (State.state.locationControl.data.zoom < 19) {
|
2020-07-24 15:52:21 +02:00
|
|
|
return new Combine([header, Translations.t.general.add.zoomInFurther]).Render()
|
2020-06-29 03:40:19 +02:00
|
|
|
}
|
2020-06-29 16:21:36 +02:00
|
|
|
|
2020-07-31 16:17:16 +02:00
|
|
|
if (State.state.layerUpdater.runningQuery.data) {
|
2020-07-24 15:52:21 +02:00
|
|
|
return new Combine([header, Translations.t.general.add.stillLoading]).Render()
|
2020-06-29 03:12:44 +02:00
|
|
|
}
|
|
|
|
|
2020-07-29 18:35:46 +02:00
|
|
|
|
2020-06-29 03:12:44 +02:00
|
|
|
var html = "";
|
|
|
|
for (const button of this._addButtons) {
|
|
|
|
html += button.Render();
|
|
|
|
}
|
2020-07-29 18:35:46 +02:00
|
|
|
|
|
|
|
|
2020-07-24 15:52:21 +02:00
|
|
|
return header.Render() + html;
|
2020-06-29 03:12:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
InnerUpdate(htmlElement: HTMLElement) {
|
2020-07-31 01:45:54 +02:00
|
|
|
State.state.osmConnection.registerActivateOsmAUthenticationClass();
|
2020-06-29 03:12:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|