| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | import { UIElement } from "../UIElement" | 
					
						
							|  |  |  | import BaseUIElement from "../BaseUIElement" | 
					
						
							|  |  |  | import { UIEventSource } from "../../Logic/UIEventSource" | 
					
						
							|  |  |  | import ExtraLinkConfig from "../../Models/ThemeConfig/ExtraLinkConfig" | 
					
						
							|  |  |  | import Img from "../Base/Img" | 
					
						
							|  |  |  | import { SubtleButton } from "../Base/SubtleButton" | 
					
						
							|  |  |  | import Toggle from "../Input/Toggle" | 
					
						
							|  |  |  | import Loc from "../../Models/Loc" | 
					
						
							|  |  |  | import Locale from "../i18n/Locale" | 
					
						
							|  |  |  | import { Utils } from "../../Utils" | 
					
						
							|  |  |  | import Svg from "../../Svg" | 
					
						
							|  |  |  | import Translations from "../i18n/Translations" | 
					
						
							|  |  |  | import { Translation } from "../i18n/Translation" | 
					
						
							| 
									
										
										
										
											2022-02-14 04:48:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-10 23:18:40 +01:00
										 |  |  | export default class ExtraLinkButton extends UIElement { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |     private readonly _config: ExtraLinkConfig | 
					
						
							| 
									
										
										
										
											2022-02-14 04:48:33 +01:00
										 |  |  |     private readonly state: { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         layoutToUse: { id: string; title: Translation } | 
					
						
							|  |  |  |         featureSwitchWelcomeMessage: UIEventSource<boolean> | 
					
						
							|  |  |  |         locationControl: UIEventSource<Loc> | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-02-14 04:48:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |     constructor( | 
					
						
							|  |  |  |         state: { | 
					
						
							|  |  |  |             featureSwitchWelcomeMessage: UIEventSource<boolean> | 
					
						
							|  |  |  |             locationControl: UIEventSource<Loc> | 
					
						
							|  |  |  |             layoutToUse: { id: string; title: Translation } | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         config: ExtraLinkConfig | 
					
						
							|  |  |  |     ) { | 
					
						
							|  |  |  |         super() | 
					
						
							|  |  |  |         this.state = state | 
					
						
							|  |  |  |         this._config = config | 
					
						
							| 
									
										
										
										
											2022-02-14 04:48:33 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-10 23:18:40 +01:00
										 |  |  |     protected InnerRender(): BaseUIElement { | 
					
						
							|  |  |  |         if (this._config === undefined) { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             return undefined | 
					
						
							| 
									
										
										
										
											2022-02-14 04:48:33 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-03-10 23:18:40 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         const c = this._config | 
					
						
							| 
									
										
										
										
											2022-02-14 04:48:33 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         const isIframe = window !== window.top | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-13 03:46:53 +01:00
										 |  |  |         if (c.requirements?.has("iframe") && !isIframe) { | 
					
						
							| 
									
										
										
										
											2022-02-14 04:48:33 +01:00
										 |  |  |             return undefined | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-13 03:46:53 +01:00
										 |  |  |         if (c.requirements?.has("no-iframe") && isIframe) { | 
					
						
							| 
									
										
										
										
											2022-02-14 04:48:33 +01:00
										 |  |  |             return undefined | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-10 23:18:40 +01:00
										 |  |  |         let link: BaseUIElement | 
					
						
							| 
									
										
										
										
											2022-02-14 04:48:33 +01:00
										 |  |  |         const theme = this.state.layoutToUse?.id ?? "" | 
					
						
							| 
									
										
										
										
											2022-07-01 00:16:05 +02:00
										 |  |  |         const basepath = window.location.host | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         const href = this.state.locationControl.map((loc) => { | 
					
						
							| 
									
										
										
										
											2022-02-14 04:48:33 +01:00
										 |  |  |             const subs = { | 
					
						
							|  |  |  |                 ...loc, | 
					
						
							|  |  |  |                 theme: theme, | 
					
						
							| 
									
										
										
										
											2022-07-01 00:16:05 +02:00
										 |  |  |                 basepath, | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                 language: Locale.language.data, | 
					
						
							| 
									
										
										
										
											2022-02-14 04:48:33 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |             return Utils.SubstituteKeys(c.href, subs) | 
					
						
							|  |  |  |         }) | 
					
						
							| 
									
										
										
										
											2022-03-10 23:18:40 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         let img: BaseUIElement = Svg.pop_out_ui() | 
					
						
							|  |  |  |         if (c.icon !== undefined) { | 
					
						
							|  |  |  |             img = new Img(c.icon).SetClass("h-6") | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         let text: Translation | 
					
						
							|  |  |  |         if (c.text === undefined) { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             text = Translations.t.general.screenToSmall.Subs({ | 
					
						
							|  |  |  |                 theme: this.state.layoutToUse.title, | 
					
						
							|  |  |  |             }) | 
					
						
							| 
									
										
										
										
											2022-03-10 23:18:40 +01:00
										 |  |  |         } else { | 
					
						
							|  |  |  |             text = c.text.Clone() | 
					
						
							| 
									
										
										
										
											2022-02-14 04:48:33 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-03-10 23:18:40 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         link = new SubtleButton(img, text, { | 
					
						
							| 
									
										
										
										
											2022-07-01 00:16:05 +02:00
										 |  |  |             url: href, | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             newTab: c.newTab, | 
					
						
							| 
									
										
										
										
											2022-03-10 23:18:40 +01:00
										 |  |  |         }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-13 03:46:53 +01:00
										 |  |  |         if (c.requirements?.has("no-welcome-message")) { | 
					
						
							| 
									
										
										
										
											2022-02-14 04:48:33 +01:00
										 |  |  |             link = new Toggle(undefined, link, this.state.featureSwitchWelcomeMessage) | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-13 03:46:53 +01:00
										 |  |  |         if (c.requirements?.has("welcome-message")) { | 
					
						
							| 
									
										
										
										
											2022-03-10 23:18:40 +01:00
										 |  |  |             link = new Toggle(link, undefined, this.state.featureSwitchWelcomeMessage) | 
					
						
							| 
									
										
										
										
											2022-02-14 04:48:33 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-03-10 23:18:40 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         return link | 
					
						
							| 
									
										
										
										
											2022-02-14 04:48:33 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | } |