2022-01-10 11:56:42 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor user interface MWConfirmationDialog class.
|
|
|
|
*
|
2023-12-01 16:06:11 +00:00
|
|
|
* @copyright See AUTHORS.txt
|
2022-01-10 11:56:42 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dialog for displaying a confirmation.
|
|
|
|
*
|
|
|
|
* This class exists to override the static MessageDialog actions.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends OO.ui.MessageDialog
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} [config] Configuration options
|
|
|
|
*/
|
|
|
|
ve.ui.MWConfirmationDialog = function VeUiMWConfirmationDialog( config ) {
|
|
|
|
// Parent constructor
|
|
|
|
ve.ui.MWConfirmationDialog.super.call( this, config );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.ui.MWConfirmationDialog, OO.ui.MessageDialog );
|
|
|
|
|
|
|
|
/* Static properties */
|
|
|
|
|
|
|
|
ve.ui.MWConfirmationDialog.static.name = 'confirmation';
|
|
|
|
|
|
|
|
ve.ui.MWConfirmationDialog.static.size = 'small';
|
|
|
|
|
|
|
|
/* Static methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Open a confirmation dialog
|
|
|
|
*
|
2022-01-21 16:09:39 +00:00
|
|
|
* @static
|
2022-01-10 11:56:42 +00:00
|
|
|
* @param {string} prompt message key to show as dialog content
|
|
|
|
* @param {Function} successCmd callback if continue action is chosen
|
|
|
|
*/
|
2022-01-21 16:09:39 +00:00
|
|
|
ve.ui.MWConfirmationDialog.static.confirm = function ( prompt, successCmd ) {
|
2022-01-10 11:56:42 +00:00
|
|
|
var windowManager = new OO.ui.WindowManager();
|
2023-10-31 21:06:04 +00:00
|
|
|
$( OO.ui.getTeleportTarget() ).append( windowManager.$element );
|
2022-01-21 14:12:27 +00:00
|
|
|
var dialog = new ve.ui.MWConfirmationDialog();
|
2022-01-10 11:56:42 +00:00
|
|
|
windowManager.addWindows( [ dialog ] );
|
|
|
|
windowManager.openWindow( dialog, {
|
|
|
|
// Messages that can be used here:
|
|
|
|
// * visualeditor-dialog-transclusion-back-confirmation-prompt
|
|
|
|
// * visualeditor-dialog-transclusion-close-confirmation-prompt
|
|
|
|
message: mw.message( prompt ).text()
|
|
|
|
} ).closed.then( function ( data ) {
|
|
|
|
if ( data && data.action === 'accept' ) {
|
|
|
|
successCmd();
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWConfirmationDialog.prototype.getSetupProcess = function ( data ) {
|
|
|
|
data = data || {};
|
|
|
|
data = ve.extendObject( {
|
|
|
|
actions: [
|
2022-01-10 12:45:04 +00:00
|
|
|
{
|
|
|
|
action: 'reject',
|
|
|
|
label: OO.ui.deferMsg( 'visualeditor-dialog-transclusion-confirmation-reject' ),
|
|
|
|
flags: 'safe'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
action: 'accept',
|
2022-01-21 14:12:27 +00:00
|
|
|
label: OO.ui.deferMsg( 'visualeditor-dialog-transclusion-confirmation-discard' ),
|
|
|
|
flags: 'destructive'
|
2022-01-10 12:45:04 +00:00
|
|
|
}
|
2022-01-10 11:56:42 +00:00
|
|
|
]
|
|
|
|
}, data );
|
|
|
|
|
|
|
|
return ve.ui.MWConfirmationDialog.super.prototype.getSetupProcess.call( this, data );
|
|
|
|
};
|
2022-01-21 14:12:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWConfirmationDialog.prototype.getReadyProcess = function ( data ) {
|
|
|
|
// "normal" destructive actions don't get focus by default
|
|
|
|
this.getActions().get( { actions: 'accept' } )[ 0 ].focus();
|
|
|
|
|
|
|
|
return ve.ui.MWConfirmationDialog.super.prototype.getReadyProcess.call( this, data );
|
|
|
|
};
|