| 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 theTranslator from '../../core/uiLib/Translator.js'; |
| 26 | import ObjId from '../../data/ObjId.js'; |
| 27 | import NonModalBaseDialog from '../baseDialog/NonModalBaseDialog.js'; |
| 28 | import theHTMLElementsFactory from '../../core/uiLib/HTMLElementsFactory.js'; |
| 29 | import theEventDispatcher from '../../core/lib/EventDispatcher.js'; |
| 30 | import theUtilities from '../../core/uiLib/Utilities.js'; |
| 31 | import SvgProfileBuilder from '../../core/lib/SvgProfileBuilder.js'; |
| 32 | import SvgContextMenuEL from './SvgContextMenuEL.js'; |
| 33 | import SvgMouseLeaveEL from './SvgMouseLeaveEL.js'; |
| 34 | import SvgMouseMoveEL from './SvgMouseMoveEL.js'; |
| 35 | import { ZERO } from '../../main/Constants.js'; |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | class ProfileDialog extends NonModalBaseDialog { |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | #svg = null; |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | #svgDiv; |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | #ascentDiv; |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | #nameDiv; |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | #svgContextMenuEL = null; |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | #svgMouseMoveEL = null; |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | #svgMouseLeaveEL = null; |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | #markerObjId = ObjId.nextObjId; |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | #routeObjId; |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | #clean ( ) { |
| 113 | if ( this.#svg ) { |
| 114 | this.#svg.removeEventListener ( 'contextmenu', this.#svgContextMenuEL, false ); |
| 115 | this.#svg.removeEventListener ( 'mousemove', this.#svgMouseMoveEL, false ); |
| 116 | this.#svg.removeEventListener ( 'mouseleave', this.#svgMouseLeaveEL, false ); |
| 117 | this.#svgDiv.removeChild ( this.#svg ); |
| 118 | this.#svg = null; |
| 119 | theEventDispatcher.dispatch ( 'removeobject', { objId : this.#markerObjId } ); |
| 120 | this.#nameDiv.textContent = ''; |
| 121 | this.#ascentDiv.textContent = ''; |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | setContent ( route ) { |
| 131 | this.#routeObjId = route.objId; |
| 132 | this.#clean ( ); |
| 133 | this.#svg = new SvgProfileBuilder ( ).createSvg ( route ); |
| 134 | this.#svg.dataset.tanObjId = route.objId; |
| 135 | this.#svg.dataset.tanMarkerObjId = this.#markerObjId; |
| 136 | this.#svg.addEventListener ( 'contextmenu', this.#svgContextMenuEL, false ); |
| 137 | this.#svg.addEventListener ( 'mousemove', this.#svgMouseMoveEL, false ); |
| 138 | this.#svg.addEventListener ( 'mouseleave', this.#svgMouseLeaveEL, false ); |
| 139 | this.#svgDiv.appendChild ( this.#svg ); |
| 140 | this.setContentName ( route ); |
| 141 | } |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | setContentName ( route ) { |
| 150 | this.#nameDiv.textContent = theTranslator.getText ( |
| 151 | 'ProfileWindow - Route {name}', |
| 152 | { |
| 153 | name : route.computedName |
| 154 | } |
| 155 | ); |
| 156 | this.#ascentDiv.textContent = theTranslator.getText ( |
| 157 | 'ProfileWindow - Ascent: {ascent} m. - Descent: {descent} m. - Distance: {distance}', |
| 158 | { |
| 159 | ascent : route.itinerary.ascent.toFixed ( ZERO ), |
| 160 | descent : route.itinerary.descent.toFixed ( ZERO ), |
| 161 | distance : theUtilities.formatDistance ( route.distance ) |
| 162 | } |
| 163 | ); |
| 164 | } |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 169 | |
| 170 | constructor ( ) { |
| 171 | super ( ); |
| 172 | this.#svgContextMenuEL = new SvgContextMenuEL ( ); |
| 173 | this.#svgMouseMoveEL = new SvgMouseMoveEL ( ); |
| 174 | this.#svgMouseLeaveEL = new SvgMouseLeaveEL ( ); |
| 175 | this.#svgDiv = theHTMLElementsFactory.create ( 'div', { className : 'TravelNotes-ProfileDialog-SvgContainer' } ); |
| 176 | this.#nameDiv = theHTMLElementsFactory.create ( 'div', { className : 'TravelNotes-ProfileDialog-NameContainer' } ); |
| 177 | this.#ascentDiv = theHTMLElementsFactory.create ( 'div', { className : 'TravelNotes-ProfileDialog-AscentContainer' } ); |
| 178 | } |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | createContentHTML ( ) { |
| 186 | } |
| 187 | |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | onCancel ( ) { |
| 193 | this.#clean ( ); |
| 194 | super.onCancel ( ); |
| 195 | theEventDispatcher.dispatch ( |
| 196 | 'profileclosed', |
| 197 | { |
| 198 | objId : this.#routeObjId |
| 199 | } |
| 200 | ); |
| 201 | } |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | show ( ) { |
| 208 | super.show ( ); |
| 209 | this.mover.moveDialogToTopLeft ( ); |
| 210 | } |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | |
| 216 | |
| 217 | |
| 218 | get contentHTMLElements ( ) { |
| 219 | return [ |
| 220 | this.#svgDiv, |
| 221 | this.#nameDiv, |
| 222 | this.#ascentDiv |
| 223 | ]; |
| 224 | } |
| 225 | |
| 226 | |
| 227 | |
| 228 | |
| 229 | |
| 230 | |
| 231 | get title ( ) { return theTranslator.getText ( 'ProfileWindow - Profile' ); } |
| 232 | } |
| 233 | |
| 234 | export default ProfileDialog; |
| 235 | |
| 236 | |
| 237 | |