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 | This program is distributed in the hope that it will be useful, |
9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | GNU General Public License for more details. |
12 | You should have received a copy of the GNU General Public License |
13 | along with this program; if not, write to the Free Software |
14 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
15 | */ |
16 | /* |
17 | Changes: |
18 | - v4.0.0: |
19 | - created from v3.6.0 |
20 | Doc reviewed 202208 |
21 | */ |
22 | |
23 | import ObjId from '../data/ObjId.js'; |
24 | import ObjType from '../data/ObjType.js'; |
25 | import Collection from '../data/Collection.js'; |
26 | import Route from '../data/Route.js'; |
27 | import Note from '../data/Note.js'; |
28 | import theHTMLSanitizer from '../core/htmlSanitizer/HTMLSanitizer.js'; |
29 | import TravelObject from '../data/TravelObject.js'; |
30 | import { INVALID_OBJ_ID } from '../main/Constants.js'; |
31 | |
32 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
33 | /** |
34 | This class represent a travel |
35 | */ |
36 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
37 | |
38 | class Travel extends TravelObject { |
39 | |
40 | /** |
41 | The object type for travels |
42 | @type {ObjType} |
43 | */ |
44 | |
45 | static #objType = new ObjType ( 'Travel', [ 'editedRoute', 'routes', 'notes', 'layerName', 'name', 'readOnly', 'objId' ] ); |
46 | |
47 | /** |
48 | the route currently edited |
49 | @type {Route} |
50 | */ |
51 | |
52 | #editedRoute = new Route ( ); |
53 | |
54 | /** |
55 | a Collection of Routes |
56 | @type {Collection.<Route>} |
57 | */ |
58 | |
59 | #routes = new Collection ( Route ); |
60 | |
61 | /** |
62 | a Collection of Notes |
63 | @type {Collection.<Note>} |
64 | */ |
65 | |
66 | #notes = new Collection ( Note ); |
67 | |
68 | /** |
69 | the background map name |
70 | @type {String} |
71 | */ |
72 | |
73 | #layerName = 'OSM - Color'; |
74 | |
75 | /** |
76 | the Travel name |
77 | @type {String} |
78 | */ |
79 | |
80 | #name = ''; |
81 | |
82 | /** |
83 | a boolean indicates when the Travel is read only |
84 | @type {Boolean} |
85 | */ |
86 | |
87 | #readOnly = false; |
88 | |
89 | /** |
90 | the objId of the travel |
91 | @type {Number} |
92 | */ |
93 | |
94 | #objId = INVALID_OBJ_ID; |
95 | |
96 | /** |
97 | The constructor |
98 | */ |
99 | |
100 | constructor ( ) { |
101 | super ( ); |
102 | this.#routes.add ( new Route ( ) ); |
103 | this.#objId = ObjId.nextObjId; |
104 | |
105 | } |
106 | |
107 | /** |
108 | the route currently edited |
109 | @type {Route} |
110 | */ |
111 | |
112 | get editedRoute ( ) { return this.#editedRoute; } |
113 | |
114 | set editedRoute ( editedRoute ) { |
115 | this.#editedRoute = |
116 | 'Route' === editedRoute?.objType?.name |
117 | ? |
118 | editedRoute |
119 | : |
120 | new Route ( ); |
121 | } |
122 | |
123 | /** |
124 | a Collection of Routes |
125 | @type {Collection.<Route>} |
126 | */ |
127 | |
128 | get routes ( ) { return this.#routes; } |
129 | |
130 | /** |
131 | a Collection of Notes |
132 | @type {Collection.<Note>} |
133 | */ |
134 | |
135 | get notes ( ) { return this.#notes; } |
136 | |
137 | /** |
138 | the background map name |
139 | @type {String} |
140 | */ |
141 | |
142 | get layerName ( ) { return this.#layerName; } |
143 | |
144 | set layerName ( layerName ) { |
145 | this.#layerName = |
146 | 'string' === typeof ( layerName ) |
147 | ? |
148 | theHTMLSanitizer.sanitizeToJsString ( layerName ) |
149 | : |
150 | 'OSM - Color'; |
151 | } |
152 | |
153 | /** |
154 | the Travel name |
155 | @type {String} |
156 | */ |
157 | |
158 | get name ( ) { return this.#name; } |
159 | |
160 | set name ( Name ) { |
161 | this.#name = |
162 | 'string' === typeof ( Name ) |
163 | ? |
164 | theHTMLSanitizer.sanitizeToJsString ( Name ) |
165 | : |
166 | ''; |
167 | } |
168 | |
169 | /** |
170 | a boolean indicates when the Travel is read only |
171 | @type {Boolean} |
172 | */ |
173 | |
174 | get readOnly ( ) { return this.#readOnly; } |
175 | |
176 | set readOnly ( readOnly ) { |
177 | this.#readOnly = |
178 | 'boolean' === typeof ( readOnly ) |
179 | ? |
180 | readOnly |
181 | : |
182 | true; |
183 | } |
184 | |
185 | /** |
186 | the objId of the Travel. objId are unique identifier given by the code |
187 | @type {Number} |
188 | */ |
189 | |
190 | get objId ( ) { return this.#objId; } |
191 | |
192 | /** |
193 | the ObjType of the Travel. |
194 | @type {ObjType} |
195 | */ |
196 | |
197 | get objType ( ) { return Travel.#objType; } |
198 | |
199 | /** |
200 | An object literal with the Travel properties and without any methods. |
201 | This object can be used with the JSON object |
202 | @type {JsonObject} |
203 | */ |
204 | |
205 | get jsonObject ( ) { |
206 | return { |
207 | editedRoute : this.editedRoute.jsonObject, |
208 | layerName : this.layerName, |
209 | name : this.name, |
210 | routes : this.routes.jsonObject, |
211 | notes : this.notes.jsonObject, |
212 | readOnly : this.readOnly, |
213 | objId : this.#objId, |
214 | objType : this.objType.jsonObject |
215 | }; |
216 | } |
217 | |
218 | set jsonObject ( something ) { |
219 | const otherthing = this.validateObject ( something ); |
220 | this.editedRoute.jsonObject = otherthing.editedRoute; |
221 | this.layerName = something.layerName; |
222 | this.name = otherthing.name; |
223 | this.readOnly = otherthing.readOnly; |
224 | this.routes.jsonObject = otherthing.routes; |
225 | this.notes.jsonObject = otherthing.notes; |
226 | this.#objId = ObjId.nextObjId; |
227 | } |
228 | } |
229 | |
230 | export default Travel; |
231 | |
232 | /* --- End of file --------------------------------------------------------------------------------------------------------- */ |
233 |