1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | |
25 | import ModalBaseDialog from '../baseDialog/ModalBaseDialog.js'; |
26 | import theTranslator from '../../core/uiLib/Translator.js'; |
27 | import CheckboxInputControl from '../../controls/checkboxInputControl/CheckboxInputControl.js'; |
28 | import ColorControl from '../../controls/colorControl/ColorControl.js'; |
29 | import NumberInputControl from '../../controls/numberInputControl/NumberInputControl.js'; |
30 | import TextInputControl from '../../controls/textInputControl/TextInputControl.js'; |
31 | import SelectControl from '../../controls/selectControl/SelectControl.js'; |
32 | import theConfig from '../../data/Config.js'; |
33 | import { ZERO } from '../../main/Constants.js'; |
34 | |
35 | |
36 | |
37 | |
38 | |
39 | |
40 | |
41 | class RoutePropertiesDialog extends ModalBaseDialog { |
42 | |
43 | |
44 | |
45 | |
46 | |
47 | |
48 | #route; |
49 | |
50 | |
51 | |
52 | |
53 | |
54 | |
55 | #colorControl; |
56 | |
57 | |
58 | |
59 | |
60 | |
61 | |
62 | #routeNameControl; |
63 | |
64 | |
65 | |
66 | |
67 | |
68 | |
69 | #routeWidthControl; |
70 | |
71 | |
72 | |
73 | |
74 | |
75 | |
76 | #dashSelectControl; |
77 | |
78 | |
79 | |
80 | |
81 | |
82 | |
83 | #chainedRouteControl; |
84 | |
85 | |
86 | |
87 | |
88 | |
89 | |
90 | |
91 | static get #ROUTE_MIN_WIDTH ( ) { return 1; } |
92 | |
93 | |
94 | |
95 | |
96 | |
97 | |
98 | |
99 | static get #ROUTE_MAX_WIDTH ( ) { return 40; } |
100 | |
101 | |
102 | |
103 | |
104 | |
105 | |
106 | |
107 | |
108 | |
109 | |
110 | constructor ( route ) { |
111 | super ( ); |
112 | this.#route = route; |
113 | } |
114 | |
115 | |
116 | |
117 | |
118 | |
119 | |
120 | createContentHTML ( ) { |
121 | this.#routeNameControl = new TextInputControl ( |
122 | { |
123 | headerText : theTranslator.getText ( 'RoutePropertiesDialog - Name' ), |
124 | value : this.#route.computedName |
125 | } |
126 | ); |
127 | this.#routeWidthControl = new NumberInputControl ( |
128 | { |
129 | beforeText : theTranslator.getText ( 'RoutePropertiesDialog - Width' ), |
130 | value : this.#route.width, |
131 | min : RoutePropertiesDialog.#ROUTE_MIN_WIDTH, |
132 | max : RoutePropertiesDialog.#ROUTE_MAX_WIDTH |
133 | } |
134 | ); |
135 | this.#dashSelectControl = new SelectControl ( |
136 | { |
137 | beforeText : theTranslator.getText ( 'RoutePropertiesDialog - Linetype' ), |
138 | elements : Array.from ( theConfig.route.dashChoices, dashChoice => dashChoice.text ) |
139 | } |
140 | ); |
141 | this.#dashSelectControl.selectedIndex = |
142 | this.#route.dashIndex < theConfig.route.dashChoices.length |
143 | ? |
144 | this.#route.dashIndex |
145 | : |
146 | ZERO; |
147 | this.#chainedRouteControl = new CheckboxInputControl ( |
148 | { |
149 | beforeText : theTranslator.getText ( 'RoutePropertiesDialog - Chained route' ), |
150 | checked : this.#route.chain |
151 | } |
152 | ); |
153 | this.#colorControl = new ColorControl ( |
154 | { |
155 | cssColor : this.#route.color, |
156 | headerText : theTranslator.getText ( 'RoutePropertiesDialog - Color' ) |
157 | } |
158 | ); |
159 | } |
160 | |
161 | |
162 | |
163 | |
164 | |
165 | show ( ) { |
166 | let showPromise = super.show ( ); |
167 | this.addCssClass ( 'TravelNotes-RoutePropertiesDialog' ); |
168 | return showPromise; |
169 | } |
170 | |
171 | |
172 | |
173 | |
174 | |
175 | onCancel ( ) { |
176 | this.#colorControl.destructor ( ); |
177 | super.onCancel ( ); |
178 | } |
179 | |
180 | |
181 | |
182 | |
183 | |
184 | |
185 | onOk ( ) { |
186 | |
187 | this.#route.color = this.#colorControl.cssColor; |
188 | if ( this.#route.computedName !== this.#routeNameControl.value ) { |
189 | this.#route.name = this.#routeNameControl.value; |
190 | } |
191 | this.#route.width = this.#routeWidthControl.value; |
192 | this.#route.chain = this.#chainedRouteControl.checked; |
193 | this.#route.dashIndex = this.#dashSelectControl.selectedIndex; |
194 | this.#colorControl.destructor ( ); |
195 | |
196 | super.onOk ( ); |
197 | } |
198 | |
199 | |
200 | |
201 | |
202 | |
203 | |
204 | get title ( ) { return theTranslator.getText ( 'RoutePropertiesDialog - Route properties' ); } |
205 | |
206 | |
207 | |
208 | |
209 | |
210 | |
211 | |
212 | get contentHTMLElements ( ) { |
213 | return [ |
214 | this.#routeNameControl.controlHTMLElement, |
215 | this.#routeWidthControl.controlHTMLElement, |
216 | this.#dashSelectControl.controlHTMLElement, |
217 | this.#chainedRouteControl.controlHTMLElement, |
218 | this.#colorControl.controlHTMLElement |
219 | ]; |
220 | } |
221 | } |
222 | |
223 | export default RoutePropertiesDialog; |
224 | |
225 | |
226 | |