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 theHTMLElementsFactory from '../../core/uiLib/HTMLElementsFactory.js'; |
26 | import theTranslator from '../../core/uiLib/Translator.js'; |
27 | import BaseDialogOptions from './BaseDialogOptions.js'; |
28 | import CancelButtonClickEL from './CancelButtonClickEL.js'; |
29 | import TopBarDragStartEL from './TopBarDragStartEL.js'; |
30 | import TopBarDragEndEL from './TopBarDragEndEL.js'; |
31 | import TopBarTouchEL from './TopBarTouchEL.js'; |
32 | import BaseDialogMover from './BaseDialogMover.js'; |
33 | |
34 | |
35 | |
36 | |
37 | |
38 | |
39 | |
40 | |
41 | |
42 | class BaseDialog { |
43 | |
44 | |
45 | |
46 | |
47 | |
48 | |
49 | |
50 | |
51 | |
52 | |
53 | |
54 | |
55 | #dialogHTMLElement; |
56 | |
57 | |
58 | |
59 | |
60 | |
61 | |
62 | #topBarHTMLElement; |
63 | |
64 | |
65 | |
66 | |
67 | |
68 | |
69 | #cancelButton; |
70 | |
71 | |
72 | |
73 | |
74 | |
75 | |
76 | #contentHTMLElement; |
77 | |
78 | |
79 | |
80 | |
81 | |
82 | |
83 | #baseDialogMover; |
84 | |
85 | |
86 | |
87 | |
88 | |
89 | |
90 | #topBarDragStartEL; |
91 | |
92 | |
93 | |
94 | |
95 | |
96 | |
97 | #topBarDragEndEL; |
98 | |
99 | |
100 | |
101 | |
102 | |
103 | |
104 | #topBarTouchEL; |
105 | |
106 | |
107 | |
108 | |
109 | |
110 | |
111 | #cancelButtonClickEL; |
112 | |
113 | |
114 | |
115 | |
116 | |
117 | |
118 | #options = null; |
119 | |
120 | |
121 | |
122 | |
123 | |
124 | #createDialogHTMLElement ( ) { |
125 | |
126 | |
127 | this.#dialogHTMLElement = theHTMLElementsFactory.create ( |
128 | 'div', |
129 | { |
130 | className : 'TravelNotes-BaseDialog-DialogHTMLElement' |
131 | } |
132 | ); |
133 | this.mover.dialogHTMLElement = this.#dialogHTMLElement; |
134 | } |
135 | |
136 | |
137 | |
138 | |
139 | |
140 | #createTopBarHTMLElement ( ) { |
141 | |
142 | this.#topBarHTMLElement = theHTMLElementsFactory.create ( |
143 | 'div', |
144 | { |
145 | className : 'TravelNotes-BaseDialog-TopBarHTMLElement', |
146 | draggable : true |
147 | }, |
148 | this.#dialogHTMLElement |
149 | ); |
150 | |
151 | this.#topBarTouchEL = new TopBarTouchEL ( this.mover ); |
152 | this.#topBarHTMLElement.addEventListener ( 'touchstart', this.#topBarTouchEL, false ); |
153 | this.#topBarHTMLElement.addEventListener ( 'touchmove', this.#topBarTouchEL, false ); |
154 | this.#topBarHTMLElement.addEventListener ( 'touchend', this.#topBarTouchEL, false ); |
155 | this.#topBarHTMLElement.addEventListener ( 'touchcancel', this.#topBarTouchEL, false ); |
156 | this.#topBarDragStartEL = new TopBarDragStartEL ( this.mover ); |
157 | this.#topBarHTMLElement.addEventListener ( 'dragstart', this.#topBarDragStartEL, false ); |
158 | this.#topBarDragEndEL = new TopBarDragEndEL ( this.mover ); |
159 | this.#topBarHTMLElement.addEventListener ( 'dragend', this.#topBarDragEndEL, false ); |
160 | |
161 | this.#cancelButton = theHTMLElementsFactory.create ( |
162 | 'div', |
163 | { |
164 | textContent : '❌', |
165 | className : 'TravelNotes-BaseDialog-CancelButton', |
166 | title : theTranslator.getText ( 'BaseDialog - Cancel' ) |
167 | }, |
168 | this.#topBarHTMLElement |
169 | ); |
170 | theHTMLElementsFactory.create ( |
171 | 'div', |
172 | { |
173 | textContent : this.title, |
174 | className : 'TravelNotes-BaseDialog-Title' |
175 | }, |
176 | this.#topBarHTMLElement |
177 | ); |
178 | this.#cancelButtonClickEL = new CancelButtonClickEL ( this ); |
179 | this.#cancelButton.addEventListener ( 'click', this.#cancelButtonClickEL, false ); |
180 | this.mover.topBarHTMLElement = this.#topBarHTMLElement; |
181 | } |
182 | |
183 | |
184 | |
185 | |
186 | |
187 | #createToolbarHTMLElement ( ) { |
188 | if ( this.toolbarHTMLElement ) { |
189 | theHTMLElementsFactory.create ( |
190 | 'div', |
191 | { |
192 | className : 'TravelNotes-BaseDialog-ToolbarHTMLElement' |
193 | }, |
194 | this.#dialogHTMLElement |
195 | ).appendChild ( this.toolbarHTMLElement ); |
196 | } |
197 | } |
198 | |
199 | |
200 | |
201 | |
202 | |
203 | #createContentHTMLElement ( ) { |
204 | this.#contentHTMLElement = theHTMLElementsFactory.create ( |
205 | 'div', |
206 | { |
207 | className : 'TravelNotes-BaseDialog-ContentHTMLElement' |
208 | }, |
209 | this.#dialogHTMLElement |
210 | ); |
211 | |
212 | this.contentHTMLElements.forEach ( |
213 | contentHTMLElement => this.#contentHTMLElement.appendChild ( contentHTMLElement ) |
214 | ); |
215 | } |
216 | |
217 | |
218 | |
219 | |
220 | |
221 | #createHTML ( ) { |
222 | this.#createDialogHTMLElement ( ); |
223 | this.#createTopBarHTMLElement ( ); |
224 | this.#createToolbarHTMLElement ( ); |
225 | this.#createContentHTMLElement ( ); |
226 | } |
227 | |
228 | |
229 | |
230 | |
231 | |
232 | |
233 | constructor ( options ) { |
234 | Object.freeze ( this ); |
235 | this.#options = new BaseDialogOptions ( options ); |
236 | } |
237 | |
238 | |
239 | |
240 | |
241 | |
242 | |
243 | #destructor ( ) { |
244 | this.#topBarHTMLElement.removeEventListener ( 'dragstart', this.#topBarDragStartEL, false ); |
245 | this.#topBarDragStartEL = null; |
246 | this.#topBarHTMLElement.removeEventListener ( 'dragend', this.#topBarDragEndEL, false ); |
247 | this.#topBarDragEndEL = null; |
248 | |
249 | this.#topBarHTMLElement.removeEventListener ( 'touchstart', this.#topBarTouchEL, false ); |
250 | this.#topBarHTMLElement.removeEventListener ( 'touchmove', this.#topBarTouchEL, false ); |
251 | this.#topBarHTMLElement.removeEventListener ( 'touchend', this.#topBarTouchEL, false ); |
252 | this.#topBarHTMLElement.removeEventListener ( 'touchcancel', this.#topBarTouchEL, false ); |
253 | this.#topBarTouchEL = null; |
254 | |
255 | this.#cancelButton.removeEventListener ( 'click', this.#cancelButtonClickEL, false ); |
256 | this.#cancelButtonClickEL = null; |
257 | |
258 | if ( this.#baseDialogMover ) { |
259 | this.#baseDialogMover = null; |
260 | } |
261 | } |
262 | |
263 | |
264 | |
265 | |
266 | |
267 | |
268 | |
269 | get mover ( ) { return this.#baseDialogMover ? this.#baseDialogMover : this.#baseDialogMover = new BaseDialogMover ( ); } |
270 | |
271 | |
272 | |
273 | |
274 | |
275 | onCancel ( ) { |
276 | this.#destructor ( ); |
277 | } |
278 | |
279 | |
280 | |
281 | |
282 | |
283 | onOk ( ) { |
284 | this.#destructor ( ); |
285 | } |
286 | |
287 | |
288 | |
289 | |
290 | |
291 | |
292 | get title ( ) { return ''; } |
293 | |
294 | |
295 | |
296 | |
297 | |
298 | |
299 | |
300 | get toolbarHTMLElement ( ) { return null; } |
301 | |
302 | |
303 | |
304 | |
305 | |
306 | |
307 | |
308 | get contentHTMLElements ( ) { return []; } |
309 | |
310 | |
311 | |
312 | |
313 | |
314 | show ( ) { |
315 | this.createContentHTML ( ); |
316 | this.#createHTML ( ); |
317 | } |
318 | |
319 | |
320 | |
321 | |
322 | |
323 | |
324 | |
325 | removeFromBackground ( backgroundElement ) { |
326 | backgroundElement.removeChild ( this.#dialogHTMLElement ); |
327 | } |
328 | |
329 | |
330 | |
331 | |
332 | |
333 | |
334 | |
335 | addToBackground ( backgroundElement ) { |
336 | backgroundElement.appendChild ( this.#dialogHTMLElement ); |
337 | } |
338 | |
339 | |
340 | |
341 | |
342 | |
343 | |
344 | addToDialog ( htmlElement ) { |
345 | this.#dialogHTMLElement.appendChild ( htmlElement ); |
346 | } |
347 | |
348 | |
349 | |
350 | |
351 | |
352 | |
353 | get options ( ) { return this.#options; } |
354 | |
355 | |
356 | |
357 | |
358 | |
359 | |
360 | addCssClass ( cssClass ) { |
361 | this.#dialogHTMLElement.classList.add ( cssClass ); |
362 | } |
363 | |
364 | } |
365 | |
366 | export default BaseDialog; |
367 | |
368 | |
369 | |