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 BaseContextMenu from './baseContextMenu/BaseContextMenu.js'; |
26 | import MenuItem from './baseContextMenu/MenuItem.js'; |
27 | import theDataSearchEngine from '../data/DataSearchEngine.js'; |
28 | import theNoteEditor from '../core/NoteEditor.js'; |
29 | import Zoomer from '../core/Zoomer.js'; |
30 | import theTravelNotesData from '../data/TravelNotesData.js'; |
31 | import theTranslator from '../core/uiLib/Translator.js'; |
32 | |
33 | import { INVALID_OBJ_ID } from '../main/Constants.js'; |
34 | |
35 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
36 | /** |
37 | this class implements the BaseContextMenu class for the notes |
38 | */ |
39 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
40 | |
41 | class NoteContextMenu extends BaseContextMenu { |
42 | |
43 | /** |
44 | The route to witch the note is linked |
45 | @type {Route} |
46 | */ |
47 | |
48 | #route; |
49 | |
50 | /** |
51 | The constructor |
52 | @param {Event} contextMenuEvent The event that have triggered the menu |
53 | @param {HTMLElement} parentNode The parent node of the menu. Can be null for leaflet objects |
54 | */ |
55 | |
56 | constructor ( contextMenuEvent, parentNode ) { |
57 | super ( contextMenuEvent, parentNode ); |
58 | this.#route = theDataSearchEngine.getNoteAndRoute ( this.targetObjId ).route; |
59 | } |
60 | |
61 | /** |
62 | The list of menu items to use. Implementation of the BaseContextMenu.menuItems property |
63 | @type {Array.<MenuItem>} |
64 | */ |
65 | |
66 | get menuItems ( ) { |
67 | return [ |
68 | new MenuItem ( |
69 | theTranslator.getText ( 'NoteContextMenu - Edit this note' ), |
70 | true, |
71 | ( ) => theNoteEditor.editNote ( this.targetObjId ) |
72 | ), |
73 | new MenuItem ( |
74 | theTranslator.getText ( 'NoteContextMenu - Delete this note' ), |
75 | true, |
76 | ( ) => theNoteEditor.removeNote ( this.targetObjId ) |
77 | ), |
78 | new MenuItem ( |
79 | theTranslator.getText ( 'NoteContextMenu - Zoom to note' ), |
80 | true, |
81 | ( ) => new Zoomer ( ).zoomToNote ( this.targetObjId ) |
82 | ), |
83 | new MenuItem ( |
84 | theTranslator.getText ( |
85 | this.#route |
86 | ? |
87 | 'NoteContextMenu - Detach note from route' |
88 | : |
89 | 'NoteContextMenu - Attach note to route' ), |
90 | INVALID_OBJ_ID === theTravelNotesData.editedRouteObjId, |
91 | ( ) => { |
92 | if ( this.#route ) { |
93 | theNoteEditor.detachNoteFromRoute ( this.targetObjId ); |
94 | } |
95 | else { |
96 | theNoteEditor.attachNoteToRoute ( this.targetObjId ); |
97 | } |
98 | } |
99 | ) |
100 | ]; |
101 | } |
102 | } |
103 | |
104 | export default NoteContextMenu; |
105 | |
106 | /* --- End of file --------------------------------------------------------------------------------------------------------- */ |
107 |