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 theOsmSearchDictionary from '../../../core/osmSearch/OsmSearchDictionary.js'; |
27 | import TreeArrowClickEL from './TreeArrowClickEL.js'; |
28 | import TreeWheelEL from './TreeWheelEL.js'; |
29 | import TreeCheckboxChangeEL from './TreeCheckboxChangeEL.js'; |
30 | import { ZERO } from '../../../main/Constants.js'; |
31 | |
32 | |
33 | |
34 | |
35 | |
36 | |
37 | |
38 | class OsmSearchTree { |
39 | |
40 | |
41 | |
42 | |
43 | |
44 | |
45 | #treeHTMLElement; |
46 | |
47 | |
48 | |
49 | |
50 | |
51 | |
52 | #treeArrowClickEL; |
53 | |
54 | |
55 | |
56 | |
57 | |
58 | |
59 | #treeCheckboxChangeEL; |
60 | |
61 | |
62 | |
63 | |
64 | |
65 | |
66 | #deepTree; |
67 | |
68 | |
69 | |
70 | |
71 | |
72 | |
73 | #addItem ( item ) { |
74 | |
75 | this.#deepTree ++; |
76 | |
77 | |
78 | const itemHTMLElement = theHTMLElementsFactory.create ( |
79 | 'div', |
80 | { |
81 | className : 'TravelNotes-OsmSearchDialog-SearchItemMargin' + this.#deepTree, |
82 | dataset : { ObjId : item.objId } |
83 | }, |
84 | this.#treeHTMLElement |
85 | ); |
86 | |
87 | |
88 | if ( ! item.isRoot ) { |
89 | const itemCheckbox = theHTMLElementsFactory.create ( |
90 | 'input', |
91 | { |
92 | type : 'checkbox', |
93 | checked : item.isSelected |
94 | }, |
95 | itemHTMLElement |
96 | ); |
97 | itemCheckbox.addEventListener ( 'change', this.#treeCheckboxChangeEL, false ); |
98 | } |
99 | |
100 | |
101 | if ( ZERO === item.filterTagsArray.length ) { |
102 | const itemArrow = theHTMLElementsFactory.create ( |
103 | 'div', |
104 | { |
105 | className : 'TravelNotes-BaseDialog-Button TravelNotes-OsmSearchDialog-TreeArrow', |
106 | textContent : item.isExpanded ? '▼' : '▶' |
107 | }, |
108 | itemHTMLElement |
109 | ); |
110 | itemArrow.addEventListener ( 'click', this.#treeArrowClickEL, false ); |
111 | } |
112 | |
113 | |
114 | theHTMLElementsFactory.create ( |
115 | 'text', |
116 | { |
117 | value : item.name |
118 | }, |
119 | itemHTMLElement |
120 | ); |
121 | |
122 | |
123 | if ( item.isExpanded ) { |
124 | item.items.forEach ( tmpItem => this.#addItem ( tmpItem ) ); |
125 | } |
126 | |
127 | |
128 | this.#deepTree --; |
129 | } |
130 | |
131 | |
132 | |
133 | |
134 | |
135 | constructor ( ) { |
136 | |
137 | Object.freeze ( this ); |
138 | |
139 | this.#deepTree = ZERO; |
140 | |
141 | |
142 | this.#treeHTMLElement = theHTMLElementsFactory.create ( |
143 | 'div', |
144 | { |
145 | id : 'TravelNotes-OsmSearchDialog-SearchTree' |
146 | } |
147 | ); |
148 | |
149 | |
150 | this.#treeHTMLElement.addEventListener ( 'wheel', new TreeWheelEL ( ), { passive : true } ); |
151 | this.#treeCheckboxChangeEL = new TreeCheckboxChangeEL ( this ); |
152 | this.#treeArrowClickEL = new TreeArrowClickEL ( this ); |
153 | |
154 | |
155 | this.#addItem ( theOsmSearchDictionary.dictionary ); |
156 | } |
157 | |
158 | |
159 | |
160 | |
161 | |
162 | redraw ( ) { |
163 | this.#treeHTMLElement.textContent = ''; |
164 | this.#addItem ( theOsmSearchDictionary.dictionary ); |
165 | } |
166 | |
167 | |
168 | |
169 | |
170 | |
171 | |
172 | get treeHTMLElement ( ) { return this.#treeHTMLElement; } |
173 | } |
174 | |
175 | export default OsmSearchTree; |
176 | |
177 | |
178 | |