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 theConfig from '../../data/Config.js'; |
26 | import theTranslator from '../../core/uiLib/Translator.js'; |
27 | import DockableBaseDialog from '../baseDialog/DockableBaseDialog.js'; |
28 | import theHTMLElementsFactory from '../../core/uiLib/HTMLElementsFactory.js'; |
29 | import OsmSearchToolbarButtons from './osmSearchToolbarButtons/OsmSearchToolbarButtons.js'; |
30 | import OsmSearchTree from './osmSearchToolbarTree/OsmSearchTree.js'; |
31 | import OsmSearchWait from './osmSearchToolbarWait/OsmSearchWait.js'; |
32 | import OsmSearchContextMenu from '../../contextMenus/OsmSearchContextMenu.js'; |
33 | import SortableListControl from '../../controls/sortableListControl/SortableListControl.js'; |
34 | import OsmSearchResultsHTMLBuilder from './osmSearchResults/OsmSearchResultsHTMLBuilder.js'; |
35 | import OsmSearchLimits from './OsmSearchLimits.js'; |
36 | import SearchResultMouseEnterEL from './osmSearchResults/SearchResultMouseEnterEL.js'; |
37 | import SearchResultMouseLeaveEL from './osmSearchResults/SearchResultMouseLeaveEL.js'; |
38 | import theTravelNotesData from '../../data/TravelNotesData.js'; |
39 | |
40 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
41 | /** |
42 | This class is the TravelPropertiesDialog |
43 | */ |
44 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
45 | |
46 | class OsmSearchDialog extends DockableBaseDialog { |
47 | |
48 | /** |
49 | The limits of the search |
50 | @type {OsmSearchLimits} |
51 | */ |
52 | |
53 | #osmSearchLimits; |
54 | |
55 | /** |
56 | The toolbar HTMLElement |
57 | @type {HTMLElement} |
58 | */ |
59 | |
60 | #toolbarHTMLElement; |
61 | |
62 | /** |
63 | The notes control |
64 | @type {SortableListControl} |
65 | */ |
66 | |
67 | #osmSearchResultsControl; |
68 | |
69 | /** |
70 | The search tree |
71 | @type {OsmSearchTree} |
72 | */ |
73 | |
74 | #osmSearchTree; |
75 | |
76 | /** |
77 | The wait bar |
78 | @type {OsmSearchWait} |
79 | */ |
80 | |
81 | #osmSearchWait; |
82 | |
83 | /** |
84 | The html builder for the results |
85 | @type {OsmSearchResultsHTMLBuilder} |
86 | */ |
87 | |
88 | #osmSearchResultsHTMLBuilder; |
89 | |
90 | /** |
91 | Search result mouseenter event listener |
92 | @type {SearchResultMouseEnterEL} |
93 | */ |
94 | |
95 | #searchResultMouseEnterEL; |
96 | |
97 | /** |
98 | Search result contextmenu event listener |
99 | @type {SearchResultMouseLeaveEL} |
100 | */ |
101 | |
102 | #searchResultMouseLeaveEL; |
103 | |
104 | /** |
105 | Toolbar creation |
106 | */ |
107 | |
108 | #createToolbar ( ) { |
109 | this.#toolbarHTMLElement = theHTMLElementsFactory.create ( 'div' ); |
110 | this.#osmSearchTree = new OsmSearchTree ( ); |
111 | this.#osmSearchWait = new OsmSearchWait ( ); |
112 | const osmSearchToolbarButtons = new OsmSearchToolbarButtons ( this.#osmSearchTree, this.#osmSearchWait ); |
113 | this.#toolbarHTMLElement.appendChild ( osmSearchToolbarButtons.toolbarButtonsHTMLElement ); |
114 | this.#toolbarHTMLElement.appendChild ( this.#osmSearchTree.treeHTMLElement ); |
115 | this.#toolbarHTMLElement.appendChild ( this.#osmSearchWait.waitHTMLElement ); |
116 | } |
117 | |
118 | /** |
119 | The constructor |
120 | */ |
121 | |
122 | constructor ( ) { |
123 | super ( theConfig.osmSearchDialog.dialogX, theConfig.osmSearchDialog.dialogY ); |
124 | } |
125 | |
126 | /** |
127 | Create all the controls needed for the dialog. |
128 | Overload of the base class createContentHTML |
129 | */ |
130 | |
131 | createContentHTML ( ) { |
132 | this.#createToolbar ( ); |
133 | this.#osmSearchResultsControl = new SortableListControl ( |
134 | null, |
135 | OsmSearchContextMenu |
136 | ); |
137 | this.#osmSearchResultsHTMLBuilder = new OsmSearchResultsHTMLBuilder ( ); |
138 | this.#osmSearchLimits = new OsmSearchLimits ( ); |
139 | this.#searchResultMouseEnterEL = new SearchResultMouseEnterEL ( ); |
140 | this.#searchResultMouseLeaveEL = new SearchResultMouseLeaveEL ( ); |
141 | } |
142 | |
143 | /** |
144 | An array with the HTMLElements that have to be added in the content of the dialog. |
145 | Overload of the BaseDialog contentHTMLElements property. |
146 | @type {Array.<HTMLElement>} |
147 | */ |
148 | |
149 | get contentHTMLElements ( ) { |
150 | return [ ].concat ( |
151 | this.#osmSearchResultsControl.controlHTMLElement |
152 | ); |
153 | } |
154 | |
155 | /** |
156 | The dialog title. Overload of the BaseDialog.title property |
157 | @type {String} |
158 | */ |
159 | |
160 | get title ( ) { return theTranslator.getText ( 'OsmSearchDialog - Searching OpenStreetMap' ); } |
161 | |
162 | /** |
163 | The toolbar HTMLElement |
164 | @type {HTMLElement} |
165 | */ |
166 | |
167 | get toolbarHTMLElement ( ) { |
168 | return this.#toolbarHTMLElement; |
169 | } |
170 | |
171 | /** |
172 | Hide the dialog and the search limits |
173 | */ |
174 | |
175 | onCancel ( ) { |
176 | this.#osmSearchLimits.hide ( ); |
177 | super.onCancel ( ); |
178 | } |
179 | |
180 | /** |
181 | Show the dialog and the search limits |
182 | */ |
183 | |
184 | show ( ) { |
185 | super.show ( ); |
186 | this.#osmSearchLimits.show ( ); |
187 | } |
188 | |
189 | /** |
190 | Update the content of the dialog |
191 | */ |
192 | |
193 | updateContent ( ) { |
194 | this.#osmSearchWait.hideWait ( ); |
195 | this.#osmSearchLimits.hide ( ); |
196 | this.#osmSearchLimits.show ( ); |
197 | const searchResultsHTMLElements = []; |
198 | theTravelNotesData.searchData.forEach ( |
199 | ( osmElement, index ) => { |
200 | const searchResultsHTMLElement = this.#osmSearchResultsHTMLBuilder.buildHTMLElement ( osmElement, index ); |
201 | searchResultsHTMLElement.addEventListener ( 'mouseenter', this.#searchResultMouseEnterEL, false ); |
202 | searchResultsHTMLElement.addEventListener ( 'mouseleave', this.#searchResultMouseLeaveEL, false ); |
203 | searchResultsHTMLElements.push ( searchResultsHTMLElement ); |
204 | } |
205 | ); |
206 | this.#osmSearchResultsControl.updateContent ( searchResultsHTMLElements ); |
207 | } |
208 | } |
209 | |
210 | export default OsmSearchDialog; |
211 | |
212 | /* --- End of file --------------------------------------------------------------------------------------------------------- */ |
213 |