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 NoteDialogToolbar from './toolbar/NoteDialogToolbar.js'; |
27 | |
28 | import MapIconData from './toolbar/MapIconData.js'; |
29 | |
30 | import TextAreaControl from '../../controls/textAreaControl/TextAreaControl.js'; |
31 | import TextInputControl from '../../controls/textInputControl/TextInputControl.js'; |
32 | import AddressControl from '../../controls/addressControl/AddressControl.js'; |
33 | import GeoCoderHelper from '../../controls/addressControl/GeoCoderHelper.js'; |
34 | |
35 | import NoteDialogIconDimsControl from './controls/NoteDialogIconDimsControl.js'; |
36 | import NoteDialogLinkControl from './controls/NoteDialogLinkControl.js'; |
37 | import NoteDialogPreviewControl from './controls/NoteDialogPreviewControl.js'; |
38 | |
39 | import NoteDialogEventListeners from './eventListeners/NoteDialogEventListeners.js'; |
40 | |
41 | import theHTMLSanitizer from '../../core/htmlSanitizer/HTMLSanitizer.js'; |
42 | import theTranslator from '../../core/uiLib/Translator.js'; |
43 | import theConfig from '../../data/Config.js'; |
44 | import Note from '../../data/Note.js'; |
45 | |
46 | |
47 | |
48 | |
49 | |
50 | |
51 | |
52 | class NoteDialog extends ModalBaseDialog { |
53 | |
54 | |
55 | |
56 | |
57 | |
58 | |
59 | #note; |
60 | |
61 | |
62 | |
63 | |
64 | |
65 | |
66 | #route; |
67 | |
68 | |
69 | |
70 | |
71 | |
72 | |
73 | #previewNote; |
74 | |
75 | |
76 | |
77 | |
78 | |
79 | |
80 | #iconDimsControl; |
81 | |
82 | |
83 | |
84 | |
85 | |
86 | |
87 | #iconControl; |
88 | |
89 | |
90 | |
91 | |
92 | |
93 | |
94 | #tooltipControl; |
95 | |
96 | |
97 | |
98 | |
99 | |
100 | |
101 | #popupControl; |
102 | |
103 | |
104 | |
105 | |
106 | |
107 | |
108 | #addressControl; |
109 | |
110 | |
111 | |
112 | |
113 | |
114 | |
115 | #linkControl; |
116 | |
117 | |
118 | |
119 | |
120 | |
121 | |
122 | #phoneControl; |
123 | |
124 | |
125 | |
126 | |
127 | |
128 | |
129 | #previewControl; |
130 | |
131 | |
132 | |
133 | |
134 | |
135 | |
136 | #toolbar; |
137 | |
138 | |
139 | |
140 | |
141 | |
142 | |
143 | #focusControl; |
144 | |
145 | |
146 | |
147 | |
148 | |
149 | |
150 | #eventListeners; |
151 | |
152 | |
153 | |
154 | |
155 | |
156 | |
157 | #destructor ( ) { |
158 | this.#toolbar.destructor ( this.#eventListeners ); |
159 | this.#iconDimsControl.destructor ( this.#eventListeners ); |
160 | this.#iconControl.destructor ( this.#eventListeners ); |
161 | this.#tooltipControl.destructor ( this.#eventListeners ); |
162 | this.#popupControl.destructor ( this.#eventListeners ); |
163 | this.#addressControl.destructor ( this.#eventListeners ); |
164 | this.#linkControl.destructor ( this.#eventListeners ); |
165 | this.#phoneControl.destructor ( this.#eventListeners ); |
166 | this.#eventListeners.destructor ( ); |
167 | } |
168 | |
169 | |
170 | |
171 | |
172 | |
173 | |
174 | |
175 | constructor ( note, route ) { |
176 | super ( ); |
177 | |
178 | this.#focusControl = null; |
179 | |
180 | |
181 | this.#note = note; |
182 | this.#route = route; |
183 | |
184 | |
185 | this.#previewNote = new Note ( ); |
186 | this.#previewNote.jsonObject = note.jsonObject; |
187 | |
188 | } |
189 | |
190 | |
191 | |
192 | |
193 | |
194 | |
195 | createContentHTML ( ) { |
196 | this.#eventListeners = new NoteDialogEventListeners ( this, this.#previewNote.latLng ); |
197 | |
198 | |
199 | this.#toolbar = new NoteDialogToolbar ( this.#eventListeners ); |
200 | this.#iconDimsControl = new NoteDialogIconDimsControl ( this.#eventListeners ); |
201 | this.#iconControl = new TextAreaControl ( |
202 | { |
203 | placeholder : '?????', |
204 | datasetName : 'iconContent', |
205 | headerText : theTranslator.getText ( 'NoteDialogIconControl - Icon content' ) |
206 | }, |
207 | this.#eventListeners |
208 | ); |
209 | this.#tooltipControl = new TextInputControl ( |
210 | { |
211 | headerText : theTranslator.getText ( 'NoteDialogTooltipControl - Tooltip content' ), |
212 | datasetName : 'tooltipContent' |
213 | }, |
214 | this.#eventListeners |
215 | ); |
216 | this.#popupControl = new TextAreaControl ( |
217 | { |
218 | rows : theConfig.noteDialog.areaHeight.popupContent, |
219 | datasetName : 'popupContent', |
220 | headerText : theTranslator.getText ( 'NoteDialogPopupControl - Text' ) |
221 | }, |
222 | this.#eventListeners |
223 | ); |
224 | this.#addressControl = new AddressControl ( this.#eventListeners ); |
225 | this.#linkControl = new NoteDialogLinkControl ( this.#eventListeners, this.#previewNote.latLng ); |
226 | this.#phoneControl = new TextInputControl ( |
227 | { |
228 | headerText : theTranslator.getText ( 'NoteDialogPhoneControl - Phone' ), |
229 | datasetName : 'phone' |
230 | }, |
231 | this.#eventListeners |
232 | ); |
233 | this.#previewControl = new NoteDialogPreviewControl ( this.#previewNote ); |
234 | |
235 | |
236 | this.setControlsValues ( this.#previewNote ); |
237 | } |
238 | |
239 | |
240 | |
241 | |
242 | |
243 | |
244 | get focusControl ( ) { return this.#focusControl; } |
245 | |
246 | set focusControl ( focusControl ) { this.#focusControl = focusControl; } |
247 | |
248 | |
249 | |
250 | |
251 | |
252 | |
253 | get mapIconData ( ) { return new MapIconData ( this.#previewNote.latLng, this.#route ); } |
254 | |
255 | |
256 | |
257 | |
258 | |
259 | |
260 | updatePreview ( noteData ) { |
261 | for ( const property in noteData ) { |
262 | this.#previewNote [ property ] = noteData [ property ]; |
263 | } |
264 | this.#previewControl.update ( ); |
265 | } |
266 | |
267 | |
268 | |
269 | |
270 | |
271 | setAddress ( ) { |
272 | if ( '' === this.#note.address ) { |
273 | new GeoCoderHelper ( this ).setAddressWithGeoCoder ( this.#previewNote.latLng ); |
274 | } |
275 | } |
276 | |
277 | |
278 | |
279 | |
280 | |
281 | |
282 | canClose ( ) { |
283 | if ( '' === this.#iconControl.value ) { |
284 | this.showError ( theTranslator.getText ( 'Notedialog - The icon content cannot be empty' ) ); |
285 | return false; |
286 | } |
287 | if ( '' !== this.#linkControl.url ) { |
288 | if ( '' === theHTMLSanitizer.sanitizeToUrl ( this.#linkControl.url ).url ) { |
289 | this.showError ( theTranslator.getText ( 'NoteDialog - invalidUrl' ) ); |
290 | return false; |
291 | } |
292 | } |
293 | |
294 | return true; |
295 | } |
296 | |
297 | |
298 | |
299 | |
300 | |
301 | onCancel ( ) { |
302 | this.#destructor ( ); |
303 | super.onCancel ( ); |
304 | } |
305 | |
306 | |
307 | |
308 | |
309 | |
310 | onOk ( ) { |
311 | if ( super.onOk ( ) ) { |
312 | |
313 | |
314 | this.#note.iconWidth = this.#iconDimsControl.iconWidth; |
315 | this.#note.iconHeight = this.#iconDimsControl.iconHeight; |
316 | this.#note.iconContent = this.#iconControl.value; |
317 | this.#note.tooltipContent = this.#tooltipControl.value; |
318 | this.#note.popupContent = this.#popupControl.value; |
319 | this.#note.address = this.#addressControl.address; |
320 | this.#note.url = this.#linkControl.url; |
321 | this.#note.phone = this.#phoneControl.value; |
322 | |
323 | |
324 | this.#note.latLng = this.#previewNote.latLng; |
325 | |
326 | this.#destructor ( ); |
327 | } |
328 | } |
329 | |
330 | |
331 | |
332 | |
333 | |
334 | |
335 | get title ( ) { return theTranslator.getText ( 'NoteDialog - Note' ); } |
336 | |
337 | |
338 | |
339 | |
340 | |
341 | |
342 | |
343 | get toolbarHTMLElement ( ) { |
344 | return this.#toolbar.rootHTMLElement; |
345 | } |
346 | |
347 | |
348 | |
349 | |
350 | |
351 | |
352 | |
353 | get contentHTMLElements ( ) { |
354 | return [ |
355 | this.#iconDimsControl.controlHTMLElement, |
356 | this.#iconControl.controlHTMLElement, |
357 | this.#tooltipControl.controlHTMLElement, |
358 | this.#popupControl.controlHTMLElement, |
359 | this.#addressControl.controlHTMLElement, |
360 | this.#linkControl.controlHTMLElement, |
361 | this.#phoneControl.controlHTMLElement |
362 | ]; |
363 | } |
364 | |
365 | |
366 | |
367 | |
368 | |
369 | |
370 | |
371 | get footerHTMLElements ( ) { |
372 | return this.#previewControl.HTMLElements; |
373 | } |
374 | |
375 | |
376 | |
377 | |
378 | |
379 | |
380 | setControlsValues ( source ) { |
381 | this.#iconDimsControl.iconHeight = source.iconHeight || this.#iconDimsControl.iconHeight; |
382 | this.#iconDimsControl.iconWidth = source.iconWidth || this.#iconDimsControl.iconWidth; |
383 | this.#iconControl.value = source.iconContent || this.#iconControl.value; |
384 | this.#tooltipControl.value = source.tooltipContent || this.#tooltipControl.value; |
385 | this.#popupControl.value = source.popupContent || this.#popupControl.value; |
386 | this.#addressControl.address = source.address || this.#addressControl.address; |
387 | this.#linkControl.url = source.url || this.#linkControl.url; |
388 | this.#phoneControl.value = source.phone || this.#phoneControl.value; |
389 | } |
390 | |
391 | |
392 | |
393 | |
394 | |
395 | updateToolbar ( ) { |
396 | this.#toolbar.update ( this.#eventListeners ); |
397 | } |
398 | |
399 | } |
400 | |
401 | export default NoteDialog; |
402 | |
403 | |
404 | |