2014-09-16 20:33:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the MediaWiki extension MultimediaViewer.
|
|
|
|
*
|
|
|
|
* MultimediaViewer is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MultimediaViewer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with MultimediaViewer. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2023-05-19 20:26:45 +00:00
|
|
|
const Dialog = require( './mmv.ui.dialog.js' );
|
|
|
|
|
2018-11-12 16:33:24 +00:00
|
|
|
( function () {
|
2014-09-16 20:33:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents the file download dialog and the link to open it.
|
|
|
|
*/
|
2023-05-20 12:38:59 +00:00
|
|
|
class DownloadDialog extends Dialog {
|
|
|
|
/**
|
|
|
|
* @param {jQuery} $container the element to which the dialog will be appended
|
|
|
|
* @param {jQuery} $openButton the button which opens the dialog. Only used for positioning.
|
|
|
|
* @param {Config} config
|
|
|
|
*/
|
|
|
|
constructor( $container, $openButton, config ) {
|
|
|
|
super( $container, $openButton, config );
|
2014-09-16 20:33:05 +00:00
|
|
|
|
2023-05-20 12:38:59 +00:00
|
|
|
this.loadDependencies.push( 'mmv.ui.download.pane' );
|
2014-09-16 20:33:05 +00:00
|
|
|
|
2023-05-20 12:38:59 +00:00
|
|
|
this.$dialog.addClass( 'mw-mmv-download-dialog' );
|
2014-09-16 20:33:05 +00:00
|
|
|
|
2023-05-20 12:38:59 +00:00
|
|
|
this.eventPrefix = 'download';
|
|
|
|
}
|
2014-09-16 20:33:05 +00:00
|
|
|
|
2023-05-20 12:38:59 +00:00
|
|
|
/**
|
|
|
|
* Registers listeners.
|
|
|
|
*/
|
|
|
|
attach() {
|
|
|
|
this.handleEvent( 'mmv-download-open', this.handleOpenCloseClick.bind( this ) );
|
|
|
|
|
|
|
|
this.handleEvent( 'mmv-reuse-open', this.closeDialog.bind( this ) );
|
|
|
|
this.handleEvent( 'mmv-options-open', this.closeDialog.bind( this ) );
|
|
|
|
|
|
|
|
this.$container.on( 'mmv-download-cta-open', () => this.$warning.hide() );
|
|
|
|
this.$container.on( 'mmv-download-cta-close', () => {
|
|
|
|
if ( this.$dialog.hasClass( 'mw-mmv-warning-visible' ) ) {
|
|
|
|
this.$warning.show();
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
}
|
2014-12-07 08:09:04 +00:00
|
|
|
|
2023-05-20 12:38:59 +00:00
|
|
|
/**
|
|
|
|
* Clears listeners.
|
|
|
|
*/
|
|
|
|
unattach() {
|
|
|
|
super.unattach();
|
2014-09-16 20:33:05 +00:00
|
|
|
|
2023-05-20 12:38:59 +00:00
|
|
|
this.$container.off( 'mmv-download-cta-open mmv-download-cta-close' );
|
|
|
|
}
|
2014-12-07 08:09:04 +00:00
|
|
|
|
2023-05-20 12:38:59 +00:00
|
|
|
/**
|
|
|
|
* Sets data needed by contained tabs and makes dialog launch link visible.
|
|
|
|
*
|
|
|
|
* @param {Image} image
|
|
|
|
* @param {Repo} repo
|
|
|
|
*/
|
|
|
|
set( image, repo ) {
|
|
|
|
if ( this.download ) {
|
|
|
|
this.download.set( image, repo );
|
|
|
|
this.showImageWarnings( image );
|
|
|
|
} else {
|
|
|
|
this.setValues = {
|
|
|
|
image: image,
|
|
|
|
repo: repo
|
|
|
|
};
|
2014-12-07 08:09:04 +00:00
|
|
|
}
|
2023-05-20 12:38:59 +00:00
|
|
|
}
|
2014-12-07 08:09:04 +00:00
|
|
|
|
2023-05-20 12:38:59 +00:00
|
|
|
/**
|
|
|
|
* @event mmv-download-opened
|
|
|
|
* Fired when the dialog is opened.
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* Opens a dialog with information about file download.
|
|
|
|
*/
|
|
|
|
openDialog() {
|
|
|
|
if ( !this.download ) {
|
|
|
|
const DownloadPane = require( 'mmv.ui.download.pane' );
|
|
|
|
this.download = new DownloadPane( this.$dialog );
|
|
|
|
this.download.attach();
|
|
|
|
}
|
2019-05-28 21:11:18 +00:00
|
|
|
|
2023-05-20 12:38:59 +00:00
|
|
|
if ( this.setValues ) {
|
|
|
|
this.download.set( this.setValues.image, this.setValues.repo );
|
|
|
|
this.showImageWarnings( this.setValues.image );
|
|
|
|
this.setValues = undefined;
|
|
|
|
}
|
2014-09-16 20:33:05 +00:00
|
|
|
|
2023-05-20 12:38:59 +00:00
|
|
|
super.openDialog();
|
2014-09-16 20:33:05 +00:00
|
|
|
|
2023-05-20 12:38:59 +00:00
|
|
|
$( document ).trigger( 'mmv-download-opened' );
|
2014-09-16 20:33:05 +00:00
|
|
|
}
|
|
|
|
|
2023-05-20 12:38:59 +00:00
|
|
|
/**
|
|
|
|
* @event mmv-download-closed
|
|
|
|
* Fired when the dialog is closed.
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* Closes the download dialog.
|
|
|
|
*/
|
|
|
|
closeDialog() {
|
|
|
|
super.closeDialog();
|
|
|
|
|
|
|
|
$( document ).trigger( 'mmv-download-closed' );
|
2014-09-16 20:33:05 +00:00
|
|
|
}
|
2023-05-20 12:38:59 +00:00
|
|
|
}
|
2014-09-16 20:33:05 +00:00
|
|
|
|
2023-05-19 20:26:45 +00:00
|
|
|
module.exports = DownloadDialog;
|
2018-11-12 16:33:24 +00:00
|
|
|
}() );
|