| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | import ExtraLinkConfigJson from "./Json/ExtraLinkConfigJson" | 
					
						
							|  |  |  | import { Translation } from "../../UI/i18n/Translation" | 
					
						
							|  |  |  | import Translations from "../../UI/i18n/Translations" | 
					
						
							| 
									
										
										
										
											2022-02-14 04:48:33 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | export default class ExtraLinkConfig { | 
					
						
							|  |  |  |     public readonly icon?: string | 
					
						
							|  |  |  |     public readonly text?: Translation | 
					
						
							|  |  |  |     public readonly href: string | 
					
						
							|  |  |  |     public readonly newTab?: false | boolean | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |     public readonly requirements?: Set< | 
					
						
							|  |  |  |         "iframe" | "no-iframe" | "welcome-message" | "no-welcome-message" | 
					
						
							|  |  |  |     > | 
					
						
							| 
									
										
										
										
											2022-02-14 04:48:33 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     constructor(configJson: ExtraLinkConfigJson, context) { | 
					
						
							|  |  |  |         this.icon = configJson.icon | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         this.text = Translations.T(configJson.text, "themes:" + context + ".text") | 
					
						
							| 
									
										
										
										
											2022-02-14 04:48:33 +01:00
										 |  |  |         this.href = configJson.href | 
					
						
							|  |  |  |         this.newTab = configJson.newTab | 
					
						
							|  |  |  |         this.requirements = new Set(configJson.requirements) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for (let requirement of configJson.requirements) { | 
					
						
							|  |  |  |             if (this.requirements.has(<any>("no-" + requirement))) { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                 throw ( | 
					
						
							|  |  |  |                     "Conflicting requirements found for " + | 
					
						
							|  |  |  |                     context + | 
					
						
							|  |  |  |                     ".extraLink: both '" + | 
					
						
							|  |  |  |                     requirement + | 
					
						
							|  |  |  |                     "' and 'no-" + | 
					
						
							|  |  |  |                     requirement + | 
					
						
							|  |  |  |                     "' found" | 
					
						
							|  |  |  |                 ) | 
					
						
							| 
									
										
										
										
											2022-02-14 04:48:33 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (this.icon === undefined && this.text === undefined) { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             throw ( | 
					
						
							|  |  |  |                 "At " + | 
					
						
							|  |  |  |                 context + | 
					
						
							|  |  |  |                 ".extraLink: define at least an icon or a text to show. Both are undefined, this is not allowed" | 
					
						
							|  |  |  |             ) | 
					
						
							| 
									
										
										
										
											2022-02-14 04:48:33 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | } |