| 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 theIndexedDb from '../../core/uiLib/IndexedDb.js'; |
| 26 | import theTravelHTMLViewsFactory from '../../viewsFactories/TravelHTMLViewsFactory.js'; |
| 27 | import theUtilities from '../../core/uiLib/Utilities.js'; |
| 28 | import theMouseUI from '../../uis/mouseUI/MouseUI.js'; |
| 29 | import theTravelNotesData from '../../data/TravelNotesData.js'; |
| 30 | import { SAVE_STATUS } from '../Constants.js'; |
| 31 | |
| 32 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
| 33 | /** |
| 34 | roadbookupdate event listener |
| 35 | */ |
| 36 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
| 37 | |
| 38 | class RoadbookUpdateEL { |
| 39 | |
| 40 | /** |
| 41 | A boolean indicating when the local storage is available |
| 42 | @type {Boolean} |
| 43 | */ |
| 44 | |
| 45 | #storageAvailable; |
| 46 | |
| 47 | /** |
| 48 | The constructor |
| 49 | */ |
| 50 | |
| 51 | constructor ( ) { |
| 52 | Object.freeze ( this ); |
| 53 | this.#storageAvailable = theUtilities.storageAvailable ( 'localStorage' ); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | Event listener method |
| 58 | */ |
| 59 | |
| 60 | handleEvent ( ) { |
| 61 | theMouseUI.saveStatus = SAVE_STATUS.modified; |
| 62 | |
| 63 | if ( this.#storageAvailable ) { |
| 64 | theIndexedDb.getOpenPromise ( ) |
| 65 | .then ( |
| 66 | ( ) => { |
| 67 | theIndexedDb.getWritePromise ( |
| 68 | theTravelNotesData.UUID, |
| 69 | theTravelHTMLViewsFactory.getTravelHTML ( 'TravelNotes-Roadbook-' ).outerHTML |
| 70 | ); |
| 71 | } |
| 72 | ) |
| 73 | .then ( ( ) => localStorage.setItem ( theTravelNotesData.UUID, Date.now ( ) ) ) |
| 74 | .catch ( err => { |
| 75 | if ( err instanceof Error ) { |
| 76 | console.error ( err ); |
| 77 | } |
| 78 | } |
| 79 | ); |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | export default RoadbookUpdateEL; |
| 85 | |
| 86 | /* --- End of file --------------------------------------------------------------------------------------------------------- */ |
| 87 |