| 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 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 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | class RouteContextMenu extends BaseContextMenu { |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | #route = null; |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | constructor ( contextMenuEvent, parentNode ) { |
| 62 | super ( contextMenuEvent, parentNode ); |
| 63 | this.#route = theDataSearchEngine.getRoute ( this.targetObjId ); |
| 64 | } |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 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 | |
| 170 | |