mediawiki-extensions-Visual.../modules/ve-mw/ui/dialogs/ve.ui.MWConfirmationDialog.js
WMDE-Fisch cede096333 Update accept button in confirmation dialog
The only places where this dialog is used now will have the same
button labels and format. We want to use "normal" destructive here
so no additional "primary" styling.

It seems that the focus on the action will only be applied
automatically when it is primary. So extra code is needed.

Bug: T299647
Change-Id: Ib5250b79e85d27ea197b83c6380863d0749e5d89
2022-01-21 15:32:58 +00:00

98 lines
2.7 KiB
JavaScript

/*!
* VisualEditor user interface MWConfirmationDialog class.
*
* @copyright 2011-2020 VisualEditor Team and others; see http://ve.mit-license.org
*/
/**
* 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
*
* @param {string} prompt message key to show as dialog content
* @param {Function} successCmd callback if continue action is chosen
*/
ve.ui.MWConfirmationDialog.confirm = function ( prompt, successCmd ) {
var windowManager = new OO.ui.WindowManager();
$( document.body ).append( windowManager.$element );
var dialog = new ve.ui.MWConfirmationDialog();
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
*
* @param {Object} [data] Dialog opening data
* @param {jQuery|string|Function|null} [data.title] Dialog title, omit to use
* the {@link #static-title static title}
* @param {Object[]} [data.actions] List of configuration options for each
* {@link OO.ui.ActionWidget action widget}, omit to use the default "OK".
*/
ve.ui.MWConfirmationDialog.prototype.getSetupProcess = function ( data ) {
data = data || {};
data = ve.extendObject( {
actions: [
{
action: 'reject',
label: OO.ui.deferMsg( 'visualeditor-dialog-transclusion-confirmation-reject' ),
flags: 'safe'
},
{
action: 'accept',
label: OO.ui.deferMsg( 'visualeditor-dialog-transclusion-confirmation-discard' ),
flags: 'destructive'
}
]
}, data );
return ve.ui.MWConfirmationDialog.super.prototype.getSetupProcess.call( this, data );
};
/**
* @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 );
};