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
|
|
|
// Shortcut for prototype later
|
|
|
|
var DP;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents the file download dialog and the link to open it.
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2023-05-19 20:26:45 +00:00
|
|
|
* @class DownloadDialog
|
|
|
|
* @extends Dialog
|
2014-09-16 20:33:05 +00:00
|
|
|
* @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 {mw.mmv.Config} config
|
|
|
|
*/
|
2023-05-19 20:26:45 +00:00
|
|
|
function DownloadDialog( $container, $openButton, config ) {
|
|
|
|
Dialog.call( this, $container, $openButton, config );
|
2014-09-16 20:33:05 +00:00
|
|
|
|
|
|
|
this.loadDependencies.push( 'mmv.ui.download.pane' );
|
|
|
|
|
|
|
|
this.$dialog.addClass( 'mw-mmv-download-dialog' );
|
|
|
|
|
|
|
|
this.eventPrefix = 'download';
|
|
|
|
}
|
|
|
|
|
2023-05-19 20:26:45 +00:00
|
|
|
OO.inheritClass( DownloadDialog, Dialog );
|
|
|
|
DP = DownloadDialog.prototype;
|
2014-09-16 20:33:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Registers listeners.
|
|
|
|
*/
|
|
|
|
DP.attach = function () {
|
2014-12-07 08:09:04 +00:00
|
|
|
var dialog = this;
|
|
|
|
|
2019-01-03 13:47:16 +00:00
|
|
|
this.handleEvent( 'mmv-download-open', this.handleOpenCloseClick.bind( this ) );
|
2014-09-16 20:33:05 +00:00
|
|
|
|
2019-01-03 13:47:16 +00:00
|
|
|
this.handleEvent( 'mmv-reuse-open', this.closeDialog.bind( this ) );
|
|
|
|
this.handleEvent( 'mmv-options-open', this.closeDialog.bind( this ) );
|
2014-12-07 08:09:04 +00:00
|
|
|
|
|
|
|
this.$container.on( 'mmv-download-cta-open', function () {
|
|
|
|
dialog.$warning.hide();
|
|
|
|
} );
|
|
|
|
this.$container.on( 'mmv-download-cta-close', function () {
|
|
|
|
if ( dialog.$dialog.hasClass( 'mw-mmv-warning-visible' ) ) {
|
|
|
|
dialog.$warning.show();
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clears listeners.
|
|
|
|
*/
|
|
|
|
DP.unattach = function () {
|
2023-05-19 20:26:45 +00:00
|
|
|
Dialog.prototype.unattach.call( this );
|
2019-05-28 21:11:18 +00:00
|
|
|
|
2014-12-07 08:09:04 +00:00
|
|
|
this.$container.off( 'mmv-download-cta-open mmv-download-cta-close' );
|
2014-09-16 20:33:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2019-05-18 16:19:44 +00:00
|
|
|
* Sets data needed by contained tabs and makes dialog launch link visible.
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2014-09-16 20:33:05 +00:00
|
|
|
* @param {mw.mmv.model.Image} image
|
|
|
|
* @param {mw.mmv.model.Repo} repo
|
|
|
|
*/
|
|
|
|
DP.set = function ( image, repo ) {
|
|
|
|
if ( this.download ) {
|
|
|
|
this.download.set( image, repo );
|
2014-12-07 10:09:25 +00:00
|
|
|
this.showImageWarnings( image );
|
2014-09-16 20:33:05 +00:00
|
|
|
} else {
|
|
|
|
this.setValues = {
|
|
|
|
image: image,
|
|
|
|
repo: repo
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event mmv-download-opened
|
|
|
|
* Fired when the dialog is opened.
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* Opens a dialog with information about file download.
|
|
|
|
*/
|
|
|
|
DP.openDialog = function () {
|
|
|
|
if ( !this.download ) {
|
2023-05-19 20:26:45 +00:00
|
|
|
const DownloadPane = require( 'mmv.ui.download.pane' );
|
|
|
|
this.download = new DownloadPane( this.$dialog );
|
2014-09-16 20:33:05 +00:00
|
|
|
this.download.attach();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( this.setValues ) {
|
|
|
|
this.download.set( this.setValues.image, this.setValues.repo );
|
2014-12-07 10:09:25 +00:00
|
|
|
this.showImageWarnings( this.setValues.image );
|
2014-09-16 20:33:05 +00:00
|
|
|
this.setValues = undefined;
|
|
|
|
}
|
|
|
|
|
2023-05-19 20:26:45 +00:00
|
|
|
Dialog.prototype.openDialog.call( this );
|
2014-09-16 20:33:05 +00:00
|
|
|
|
|
|
|
$( document ).trigger( 'mmv-download-opened' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event mmv-download-closed
|
|
|
|
* Fired when the dialog is closed.
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* Closes the download dialog.
|
|
|
|
*/
|
|
|
|
DP.closeDialog = function () {
|
2023-05-19 20:26:45 +00:00
|
|
|
Dialog.prototype.closeDialog.call( this );
|
2014-09-16 20:33:05 +00:00
|
|
|
|
|
|
|
$( document ).trigger( 'mmv-download-closed' );
|
|
|
|
};
|
|
|
|
|
2023-05-19 20:26:45 +00:00
|
|
|
module.exports = DownloadDialog;
|
2018-11-12 16:33:24 +00:00
|
|
|
}() );
|