| 
									
										
										
										
											2020-10-14 12:15:09 +02:00
										 |  |  | import {UIEventSource} from "../../Logic/UIEventSource"; | 
					
						
							|  |  |  | import {UIElement} from "../UIElement"; | 
					
						
							|  |  |  | import Translations from "../i18n/Translations"; | 
					
						
							| 
									
										
										
										
											2021-06-12 02:58:32 +02:00
										 |  |  | import {OsmConnection} from "../../Logic/Osm/OsmConnection"; | 
					
						
							|  |  |  | import BaseUIElement from "../BaseUIElement"; | 
					
						
							|  |  |  | import Toggle from "../Input/Toggle"; | 
					
						
							| 
									
										
										
										
											2020-07-05 18:59:47 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | export class SaveButton extends UIElement { | 
					
						
							| 
									
										
										
										
											2020-10-27 01:01:34 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-12 02:58:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     private readonly _element: BaseUIElement; | 
					
						
							| 
									
										
										
										
											2020-07-05 18:59:47 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-08 23:44:34 +01:00
										 |  |  |     constructor(value: UIEventSource<any>, osmConnection: OsmConnection) { | 
					
						
							| 
									
										
										
										
											2020-07-05 18:59:47 +02:00
										 |  |  |         super(value); | 
					
						
							| 
									
										
										
										
											2021-06-12 02:58:32 +02:00
										 |  |  |         if (value === undefined) { | 
					
						
							| 
									
										
										
										
											2020-07-05 18:59:47 +02:00
										 |  |  |             throw "No event source for savebutton, something is wrong" | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-06-12 02:58:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         const pleaseLogin = Translations.t.general.loginToStart.Clone() | 
					
						
							| 
									
										
										
										
											2020-10-27 01:01:34 +01:00
										 |  |  |             .SetClass("login-button-friendly") | 
					
						
							| 
									
										
										
										
											2020-12-08 23:44:34 +01:00
										 |  |  |             .onClick(() => osmConnection?.AttemptLogin()) | 
					
						
							| 
									
										
										
										
											2021-06-12 02:58:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const isSaveable = value.map(v => v !== false && (v ?? "") !== "") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const saveEnabled = Translations.t.general.save.Clone().SetClass(`btn`); | 
					
						
							|  |  |  |         const saveDisabled = Translations.t.general.save.Clone().SetClass(`btn btn-disabled`); | 
					
						
							|  |  |  |         const save = new Toggle( | 
					
						
							|  |  |  |             saveEnabled, | 
					
						
							|  |  |  |             saveDisabled, | 
					
						
							|  |  |  |             isSaveable | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         this._element = new Toggle( | 
					
						
							|  |  |  |             save | 
					
						
							|  |  |  |             , pleaseLogin, | 
					
						
							|  |  |  |             osmConnection?.userDetails?.map(userDetails => userDetails.loggedIn) ?? new UIEventSource<any>(false) | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 18:59:47 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-12 02:58:32 +02:00
										 |  |  |     InnerRender(): BaseUIElement { | 
					
						
							|  |  |  |         return this._element | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 18:59:47 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |