import {UIElement} from "./UIElement"; import {TagMapping, TagMappingOptions} from "./TagMapping"; import {Question, QuestionDefinition} from "../Logic/Question"; import {UIEventSource} from "./UIEventSource"; import {QuestionPicker} from "./QuestionPicker"; import {OsmImageUploadHandler} from "../Logic/OsmImageUploadHandler"; import {ImageCarousel} from "./Image/ImageCarousel"; import {Changes} from "../Logic/Changes"; import {UserDetails} from "../Logic/OsmConnection"; import {CommonTagMappings} from "../Layers/CommonTagMappings"; import {VerticalCombine} from "./Base/VerticalCombine"; export class FeatureInfoBox extends UIElement { private _tagsES: UIEventSource; private _title: UIElement; private _osmLink: UIElement; private _infoElements: UIElement[] private _questions: QuestionPicker; private _changes: Changes; private _userDetails: UIEventSource; private _imageElement: ImageCarousel; private _pictureUploader: UIElement; private _wikipedialink: UIElement; constructor( tagsES: UIEventSource, elementsToShow: (TagMappingOptions | QuestionDefinition | UIElement)[], questions: QuestionDefinition[], changes: Changes, userDetails: UIEventSource, preferedPictureLicense : UIEventSource ) { super(tagsES); this._tagsES = tagsES; this._changes = changes; this._userDetails = userDetails; this.ListenTo(userDetails); this._imageElement = new ImageCarousel(this._tagsES); this._questions = new QuestionPicker( this._changes.asQuestions(questions), this._tagsES); var infoboxes: UIElement[] = []; for (const uiElement of elementsToShow) { if (uiElement instanceof QuestionDefinition) { const questionDef = uiElement as QuestionDefinition; const question = new Question(this._changes, questionDef); infoboxes.push(question.CreateHtml(this._tagsES)); } else if (uiElement instanceof TagMappingOptions) { const tagMappingOpt = uiElement as TagMappingOptions; infoboxes.push(new TagMapping(tagMappingOpt, this._tagsES)) } else { const ui = uiElement as UIElement; infoboxes.push(ui); } } this._title = infoboxes.shift(); this._infoElements = infoboxes; this._osmLink = new TagMapping(CommonTagMappings.osmLink, this._tagsES); this._wikipedialink = new TagMapping(CommonTagMappings.wikipediaLink, this._tagsES); this._pictureUploader = new OsmImageUploadHandler(tagsES, userDetails, preferedPictureLicense, changes, this._imageElement.slideshow).getUI(); } InnerRender(): string { let questions = ""; if (this._userDetails.data.loggedIn) { // Questions is embedded in a span, because it'll hide the parent when the questions dissappear questions = ""+this._questions.HideOnEmpty(true).Render()+""; } return "
" + "
" + "" + this._title.Render() + "" + this._wikipedialink.Render() + this._osmLink.Render() + "
" + "
" + this._imageElement.Render() + this._pictureUploader.Render() + new VerticalCombine(this._infoElements, 'infobox-information').HideOnEmpty(true).Render() + questions + "
" + "" + "
"; } Activate() { super.Activate(); this._imageElement.Activate(); this._pictureUploader.Activate(); } Update() { super.Update(); this._imageElement.Update(); this._pictureUploader.Update(); } }