| 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 PasswordDialog from '../passwordDialog/PasswordDialog.js'; |
| 26 | import DataEncryptor from '../../core/lib/DataEncryptor.js'; |
| 27 | import DataEncryptorHandlers from './DataEncryptorHandlers.js'; |
| 28 | |
| 29 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
| 30 | /** |
| 31 | Click event listener for the saveApiKeys to secure file button |
| 32 | */ |
| 33 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
| 34 | |
| 35 | class SaveToSecureFileButtonClickEL { |
| 36 | |
| 37 | /** |
| 38 | A reference to the ApiKeys dialog |
| 39 | @type {ApiKeysDialog} |
| 40 | */ |
| 41 | |
| 42 | #apiKeysDialog; |
| 43 | |
| 44 | /** |
| 45 | A DataEncryptorHandlers object used to encode / decode the ApiKeys |
| 46 | @type {DataEncryptorHandlers} |
| 47 | */ |
| 48 | |
| 49 | #dataEncryptorHandlers; |
| 50 | |
| 51 | /** |
| 52 | The constructor |
| 53 | @param {ApiKeysDialog} apiKeysDialog A reference to the ApiKeys dialog |
| 54 | objects are stored |
| 55 | */ |
| 56 | |
| 57 | constructor ( apiKeysDialog ) { |
| 58 | Object.freeze ( this ); |
| 59 | this.#apiKeysDialog = apiKeysDialog; |
| 60 | this.#dataEncryptorHandlers = new DataEncryptorHandlers ( this.#apiKeysDialog ); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | The destructor |
| 65 | */ |
| 66 | |
| 67 | destructor ( ) { |
| 68 | this.#dataEncryptorHandlers.destructor ( ); |
| 69 | this.#apiKeysDialog = null; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | Event listener method |
| 74 | @param {Event} clickEvent The event to handle |
| 75 | */ |
| 76 | |
| 77 | handleEvent ( clickEvent ) { |
| 78 | clickEvent.stopPropagation ( ); |
| 79 | if ( ! this.#apiKeysDialog.validateApiKeys ( ) ) { |
| 80 | return; |
| 81 | } |
| 82 | this.#apiKeysDialog.showWait ( ); |
| 83 | |
| 84 | this.#apiKeysDialog.keyboardELEnabled = false; |
| 85 | new DataEncryptor ( ).encryptData ( |
| 86 | new window.TextEncoder ( ).encode ( this.#apiKeysDialog.apiKeysJSON ), |
| 87 | data => this.#dataEncryptorHandlers.onOkEncrypt ( data ), |
| 88 | ( ) => this.#dataEncryptorHandlers.onErrorEncrypt ( ), |
| 89 | new PasswordDialog ( true ).show ( ) |
| 90 | ); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | export default SaveToSecureFileButtonClickEL; |
| 95 | |
| 96 | /* --- End of file --------------------------------------------------------------------------------------------------------- */ |
| 97 |