| 1 | /* |
| 2 | * This file is part of the MediaWiki extension MultimediaViewer. |
| 3 | * |
| 4 | * MultimediaViewer is free software: you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation, either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * MultimediaViewer 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 MultimediaViewer. If not, see <http://www.gnu.org/licenses/>. |
| 16 | */ |
| 17 | |
| 18 | const { Dialog } = require( 'mmv' ); |
| 19 | const DownloadPane = require( './mmv.ui.download.pane.js' ); |
| 20 | |
| 21 | /** |
| 22 | * Represents the file download dialog and the link to open it. |
| 23 | */ |
| 24 | class DownloadDialog extends Dialog { |
| 25 | /** |
| 26 | * @param {jQuery} $container the element to which the dialog will be appended |
| 27 | * @param {jQuery} $openButton the button which opens the dialog. Only used for positioning. |
| 28 | */ |
| 29 | constructor( $container, $openButton ) { |
| 30 | super( $container, $openButton ); |
| 31 | |
| 32 | this.download = new DownloadPane( this.$dialog ); |
| 33 | this.$dialog.addClass( 'mw-mmv-download-dialog' ); |
| 34 | |
| 35 | this.eventPrefix = 'download'; |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Registers listeners. |
| 40 | */ |
| 41 | attach() { |
| 42 | this.download.attach(); |
| 43 | |
| 44 | this.handleEvent( 'mmv-download-open', this.handleOpenCloseClick.bind( this ) ); |
| 45 | |
| 46 | this.handleEvent( 'mmv-reuse-open', this.closeDialog.bind( this ) ); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Sets data needed by contained tabs and makes dialog launch link visible. |
| 51 | * |
| 52 | * @param {ImageModel} image |
| 53 | */ |
| 54 | set( image ) { |
| 55 | this.download.set( image ); |
| 56 | this.showImageWarnings( image ); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Fired when the dialog is opened. |
| 61 | * |
| 62 | * @event DownloadDialog#mmv-download-opened |
| 63 | */ |
| 64 | |
| 65 | /** |
| 66 | * Opens a dialog with information about file download. |
| 67 | */ |
| 68 | openDialog() { |
| 69 | super.openDialog(); |
| 70 | |
| 71 | $( document ).trigger( 'mmv-download-opened' ); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Fired when the dialog is closed. |
| 76 | * |
| 77 | * @event DownloadDialog#mmv-download-closed |
| 78 | */ |
| 79 | |
| 80 | /** |
| 81 | * Closes the download dialog. |
| 82 | */ |
| 83 | closeDialog() { |
| 84 | super.closeDialog(); |
| 85 | |
| 86 | $( document ).trigger( 'mmv-download-closed' ); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | module.exports = DownloadDialog; |