File : contextMenus/RouteContextMenu.js

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 theConfig from '../data/Config.js';
28
import theNoteEditor from '../core/NoteEditor.js';
29
import theRouteEditor from '../core/RouteEditor.js';
30
import theWayPointEditor from '../core/WayPointEditor.js';
31
import theTravelNotesData from '../data/TravelNotesData.js';
32
import theTranslator from '../core/uiLib/Translator.js';
33
import Zoomer from '../core/Zoomer.js';
34
import theProfileDialogsManager from '../core/ProfileDialogsManager.js';
35
import theDataSearchEngine from '../data/DataSearchEngine.js';
36
import AllManeuverNotesBuilder from '../core/AllManeuverNotesBuilder.js';
37
38
import { ROUTE_EDITION_STATUS, ZERO } from '../main/Constants.js';
39
40
/* ------------------------------------------------------------------------------------------------------------------------- */
41
/**
42
this class implements the BaseContextMenu class for the routes
43
*/
44
/* ------------------------------------------------------------------------------------------------------------------------- */
45
46
class RouteContextMenu extends BaseContextMenu {
47
48
    /**
49
    The route for witch the context menu is displayed
50
    @type {Route}
51
    */
52
53
    #route = null;
54
55
    /**
56
    The constructor
57
    @param {Event} contextMenuEvent The event that have triggered the menu
58
    @param {HTMLElement} parentNode The parent node of the menu. Can be null for leaflet objects
59
    */
60
61
    constructor ( contextMenuEvent, parentNode ) {
62
        super ( contextMenuEvent, parentNode );
63
        this.#route = theDataSearchEngine.getRoute ( this.targetObjId );
64
    }
65
66
    /**
67
    The list of menu items to use. Implementation of the BaseContextMenu.menuItems property
68
    @type {Array.<MenuItem>}
69
    */
70
71
    get menuItems ( ) {
72
        return [
73
            new MenuItem (
74
                theTranslator.getText ( 'RouteContextMenu - Edit this route' ),
75
                (
76
                    ( this.targetObjId !== theTravelNotesData.travel.editedRoute.objId )
77
                    &&
78
                    ( ROUTE_EDITION_STATUS.editedChanged !== theTravelNotesData.travel.editedRoute.editionStatus )
79
                ),
80
                ( ) => theRouteEditor.editRoute ( this.targetObjId )
81
82
            ),
83
            new MenuItem (
84
                theTranslator.getText ( 'RouteContextMenu - Delete this route' ),
85
                (
86
                    ( this.targetObjId !== theTravelNotesData.travel.editedRoute.objId )
87
                    ||
88
                    ( ROUTE_EDITION_STATUS.editedChanged !== theTravelNotesData.travel.editedRoute.editionStatus )
89
                ),
90
                ( ) => theRouteEditor.removeRoute ( this.targetObjId )
91
92
            ),
93
            new MenuItem (
94
                theTranslator.getText (
95
                    this.#route.hidden
96
                        ?
97
                        'RouteContextMenu - Show this route'
98
                        :
99
                        'RouteContextMenu - Hide this route'
100
                ),
101
                this.#route.hidden
102
                ||
103
                theTravelNotesData.travel.editedRoute.objId !== this.targetObjId,
104
                ( ) => {
105
                    if ( this.#route.hidden ) {
106
                        theRouteEditor.showRoute ( this.targetObjId );
107
                    }
108
                    else {
109
                        theRouteEditor.hideRoute ( this.targetObjId );
110
                    }
111
                }
112
            ),
113
            new MenuItem (
114
                theTranslator.getText ( 'RouteContextMenu - Properties' ),
115
                ! this.#route.hidden,
116
                ( ) => theRouteEditor.routeProperties ( this.targetObjId )
117
            ),
118
            new MenuItem (
119
                theTranslator.getText ( 'RouteContextMenu - Zoom to route' ),
120
                ! this.#route.hidden,
121
                ( ) => new Zoomer ( ).zoomToRoute ( this.targetObjId )
122
            ),
123
            new MenuItem (
124
                theTranslator.getText ( 'RouteContextMenu - View the elevation' ),
125
                this.#route.itinerary.hasProfile,
126
                ( ) => theProfileDialogsManager.showProfile ( this.targetObjId )
127
            ),
128
            new MenuItem (
129
                theTranslator.getText ( 'RouteContextMenu - Print route map' ),
130
                theConfig.printRouteMap.isEnabled,
131
                ( ) => theRouteEditor.printRouteMap ( this.targetObjId )
132
            ),
133
            new MenuItem (
134
                theTranslator.getText ( 'RouteContextMenu - Save this route in a GPX file' ),
135
                ( ZERO < this.#route.itinerary.itineraryPoints.length ),
136
                ( ) => theRouteEditor.saveGpx ( this.targetObjId )
137
            ),
138
            new MenuItem (
139
                theTranslator.getText ( 'RouteContextMenu - Invert waypoints' ),
140
                theTravelNotesData.travel.editedRoute.objId === this.targetObjId,
141
                ( ) => theWayPointEditor.reverseWayPoints ( )
142
            ),
143
            new MenuItem (
144
                theTranslator.getText ( 'RouteContextMenu - Add a note on the route' ),
145
                ! this.haveParentNode,
146
                ( ) => theNoteEditor.newRouteNote ( this.targetObjId, this.latLng )
147
            ),
148
            new MenuItem (
149
                theTranslator.getText ( 'RouteContextMenu - Create a note for each route maneuver' ),
150
                ! this.#route.hidden,
151
                ( ) => new AllManeuverNotesBuilder ( ).addAllManeuverNotes ( this.targetObjId )
152
            ),
153
            new MenuItem (
154
                theTranslator.getText ( 'RouteContextMenu - Save modifications on this route' ),
155
                theTravelNotesData.travel.editedRoute.objId === this.targetObjId,
156
                ( ) => theRouteEditor.saveEdition ( )
157
            ),
158
            new MenuItem (
159
                theTranslator.getText ( 'RouteContextMenu - Cancel modifications on this route' ),
160
                theTravelNotesData.travel.editedRoute.objId === this.targetObjId,
161
                ( ) => theRouteEditor.cancelEdition ( )
162
            )
163
        ];
164
    }
165
}
166
167
export default RouteContextMenu;
168
169
/* --- End of file --------------------------------------------------------------------------------------------------------- */
170