1 | /* |
2 | Copyright - 2017 2023 - wwwouaiebe - Contact: https://www.ouaie.be/ |
3 | |
4 | This program is free software; |
5 | you can redistribute it and/or modify it under the terms of the |
6 | GNU General Public License as published by the Free Software Foundation; |
7 | either version 3 of the License, or any later version. |
8 | |
9 | This program is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | GNU General Public License for more details. |
13 | |
14 | You should have received a copy of the GNU General Public License |
15 | along with this program; if not, write to the Free Software |
16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
17 | */ |
18 | /* |
19 | Changes: |
20 | - v4.0.0: |
21 | - created from v3.6.0 |
22 | Doc reviewed 202208 |
23 | */ |
24 | |
25 | import ModalBaseDialog from '../baseDialog/ModalBaseDialog.js'; |
26 | import theTranslator from '../../core/uiLib/Translator.js'; |
27 | import AddressControl from '../../controls/addressControl/AddressControl.js'; |
28 | import TextInputControl from '../../controls/textInputControl/TextInputControl.js'; |
29 | import WayPointPropertiesDialogEventListeners from './WayPointPropertiesDialogEventListeners.js'; |
30 | |
31 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
32 | /** |
33 | This is the WayPointProerties dialog |
34 | */ |
35 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
36 | |
37 | class WayPointPropertiesDialog extends ModalBaseDialog { |
38 | |
39 | /** |
40 | A reference to the edited wayPoint |
41 | @type {WayPoint} |
42 | */ |
43 | |
44 | #wayPoint; |
45 | |
46 | /** |
47 | The waypoint name control |
48 | @type {TextInputControl} |
49 | */ |
50 | |
51 | #wayPointNameControl; |
52 | |
53 | /** |
54 | The waypoint address control |
55 | @type {AddressControl} |
56 | */ |
57 | |
58 | #addressControl; |
59 | |
60 | /** |
61 | The event listeners collection |
62 | @type {WayPointPropertiesDialogEventListeners} |
63 | */ |
64 | |
65 | #eventListeners; |
66 | |
67 | /** |
68 | The constructor |
69 | @param {WayPoint} wayPoint The wayPoint to modify |
70 | */ |
71 | |
72 | constructor ( wayPoint ) { |
73 | super ( ); |
74 | this.#wayPoint = wayPoint; |
75 | this.#eventListeners = new WayPointPropertiesDialogEventListeners ( this, this.#wayPoint.latLng ); |
76 | } |
77 | |
78 | /** |
79 | Create all the controls needed for the dialog. |
80 | Overload of the base class createContentHTML |
81 | */ |
82 | |
83 | createContentHTML ( ) { |
84 | this.#wayPointNameControl = new TextInputControl ( |
85 | { |
86 | headerText : theTranslator.getText ( 'WayPointPropertiesDialog - Name' ) |
87 | }, |
88 | this.#eventListeners |
89 | ); |
90 | this.#wayPointNameControl.value = this.#wayPoint.name; |
91 | this.#addressControl = new AddressControl ( this.#eventListeners ); |
92 | this.#addressControl.address = this.#wayPoint.address; |
93 | |
94 | } |
95 | |
96 | /** |
97 | Overload of the BaseDialog.onCancel ( ) method. |
98 | */ |
99 | |
100 | onCancel ( ) { |
101 | |
102 | this.#eventListeners.destructor ( ); |
103 | super.onCancel ( ); |
104 | } |
105 | |
106 | /** |
107 | Overload of the BaseDialog.onOk ( ) method. Called when the Ok button is clicked |
108 | */ |
109 | |
110 | onOk ( ) { |
111 | this.#wayPoint.address = this.#addressControl.address; |
112 | this.#wayPoint.name = this.#wayPointNameControl.value; |
113 | this.#eventListeners.destructor ( ); |
114 | super.onOk ( ); |
115 | } |
116 | |
117 | /** |
118 | An array with the HTMLElements that have to be added in the content of the dialog. |
119 | Overload of the BaseDialog contentHTMLElements property. |
120 | @type {Array.<HTMLElement>} |
121 | */ |
122 | |
123 | get contentHTMLElements ( ) { |
124 | return [ |
125 | this.#wayPointNameControl.controlHTMLElement, |
126 | this.#addressControl.controlHTMLElement |
127 | ]; |
128 | } |
129 | |
130 | /** |
131 | The name in the control |
132 | */ |
133 | |
134 | set name ( wayPointName ) { |
135 | this.#wayPointNameControl.name = wayPointName; |
136 | } |
137 | |
138 | /** |
139 | The address in the control |
140 | */ |
141 | |
142 | set address ( address ) { |
143 | this.#addressControl.address = address; |
144 | } |
145 | |
146 | /** |
147 | The title of the dialog. Overload of the BaseDialog title property. |
148 | @type {String} |
149 | */ |
150 | |
151 | get title ( ) { return theTranslator.getText ( 'WayPointPropertiesDialog - Waypoint properties' ); } |
152 | |
153 | /** |
154 | The waypoint used by the dialog |
155 | @type {WayPoint} |
156 | */ |
157 | |
158 | get wayPoint ( ) { return this.#wayPoint; } |
159 | |
160 | /** |
161 | Set the control values after an update by the geoCoder |
162 | @param {Object} values The values to push in the controls |
163 | */ |
164 | |
165 | setControlsValues ( values ) { |
166 | this.#addressControl.address = values.address; |
167 | this.#wayPointNameControl.value = values.name; |
168 | } |
169 | } |
170 | |
171 | export default WayPointPropertiesDialog; |
172 | |
173 | /* --- End of file --------------------------------------------------------------------------------------------------------- */ |
174 |