| 
									
										
										
										
											2020-08-31 02:59:47 +02:00
										 |  |  | import SingleSetting from "./SingleSetting"; | 
					
						
							|  |  |  | import {UIElement} from "../UIElement"; | 
					
						
							|  |  |  | import {FixedUiElement} from "../Base/FixedUiElement"; | 
					
						
							|  |  |  | import {UIEventSource} from "../../Logic/UIEventSource"; | 
					
						
							| 
									
										
										
										
											2020-09-02 11:37:34 +02:00
										 |  |  | import PageSplit from "../Base/PageSplit"; | 
					
						
							| 
									
										
										
										
											2020-08-31 02:59:47 +02:00
										 |  |  | import Combine from "../Base/Combine"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default class SettingsTable extends UIElement { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private _col1: UIElement[] = []; | 
					
						
							| 
									
										
										
										
											2020-09-02 11:37:34 +02:00
										 |  |  |     private _col2: UIElement[] = []; | 
					
						
							| 
									
										
										
										
											2020-08-31 02:59:47 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     public selectedSetting: UIEventSource<SingleSetting<any>>; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-02 11:37:34 +02:00
										 |  |  |     constructor(elements: (SingleSetting<any> | string)[], | 
					
						
							| 
									
										
										
										
											2020-08-31 02:59:47 +02:00
										 |  |  |                 currentSelectedSetting: UIEventSource<SingleSetting<any>>) { | 
					
						
							|  |  |  |         super(undefined); | 
					
						
							|  |  |  |         const self = this; | 
					
						
							|  |  |  |         this.selectedSetting = currentSelectedSetting ?? new UIEventSource<SingleSetting<any>>(undefined); | 
					
						
							|  |  |  |         for (const element of elements) { | 
					
						
							| 
									
										
										
										
											2020-09-02 11:37:34 +02:00
										 |  |  |             if(typeof element === "string"){ | 
					
						
							|  |  |  |                 this._col1.push(new FixedUiElement(element)); | 
					
						
							|  |  |  |                 this._col2.push(null); | 
					
						
							|  |  |  |                 continue; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |              | 
					
						
							|  |  |  |             let title: UIElement = element._name === undefined ? null : new FixedUiElement(element._name); | 
					
						
							| 
									
										
										
										
											2020-08-31 02:59:47 +02:00
										 |  |  |             this._col1.push(title); | 
					
						
							|  |  |  |             this._col2.push(element._value); | 
					
						
							| 
									
										
										
										
											2020-09-02 11:37:34 +02:00
										 |  |  |             element._value.SetStyle("display:block"); | 
					
						
							| 
									
										
										
										
											2020-08-31 02:59:47 +02:00
										 |  |  |             element._value.IsSelected.addCallback(isSelected => { | 
					
						
							|  |  |  |                 if (isSelected) { | 
					
						
							|  |  |  |                     self.selectedSetting.setData(element); | 
					
						
							|  |  |  |                 } else if (self.selectedSetting.data === element) { | 
					
						
							|  |  |  |                     self.selectedSetting.setData(undefined); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     InnerRender(): string { | 
					
						
							| 
									
										
										
										
											2020-09-02 11:37:34 +02:00
										 |  |  |         let elements = []; | 
					
						
							| 
									
										
										
										
											2020-08-31 02:59:47 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         for (let i = 0; i < this._col1.length; i++) { | 
					
						
							| 
									
										
										
										
											2020-09-02 11:37:34 +02:00
										 |  |  |             if(this._col1[i] !== null && this._col2[i] !== null){ | 
					
						
							|  |  |  |                 elements.push(new PageSplit(this._col1[i], this._col2[i], 25)); | 
					
						
							|  |  |  |             }else if(this._col1[i] !== null){ | 
					
						
							|  |  |  |                 elements.push(this._col1[i]) | 
					
						
							|  |  |  |             }else{ | 
					
						
							|  |  |  |                 elements.push(this._col2[i]) | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2020-08-31 02:59:47 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-02 11:37:34 +02:00
										 |  |  |         return new Combine(elements).Render(); | 
					
						
							| 
									
										
										
										
											2020-08-31 02:59:47 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-09-02 11:37:34 +02:00
										 |  |  |      | 
					
						
							| 
									
										
										
										
											2020-08-31 02:59:47 +02:00
										 |  |  | } |