2014-07-14 21:32:49 +00:00
|
|
|
/*
|
|
|
|
* VisualEditor user interface MWWikitextSwitchConfirmDialog class.
|
|
|
|
*
|
|
|
|
* @copyright 2011-2014 VisualEditor Team and others; see AUTHORS.txt
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
2014-06-25 20:13:11 +00:00
|
|
|
/**
|
2014-07-14 21:32:49 +00:00
|
|
|
* Dialog for letting the user choose how to switch to wikitext mode.
|
2014-06-25 20:13:11 +00:00
|
|
|
*
|
|
|
|
* @class
|
2014-07-14 21:32:49 +00:00
|
|
|
* @extends OO.ui.MessageDialog
|
2014-06-25 20:13:11 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} [config] Configuration options
|
|
|
|
*/
|
2014-08-21 00:50:54 +00:00
|
|
|
ve.ui.MWWikitextSwitchConfirmDialog = function VeUiMWWikitextSwitchConfirmDialog( config ) {
|
2014-06-25 20:13:11 +00:00
|
|
|
// Parent constructor
|
2014-08-21 00:50:54 +00:00
|
|
|
ve.ui.MWWikitextSwitchConfirmDialog.super.call( this, config );
|
2014-06-25 20:13:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2014-07-14 21:32:49 +00:00
|
|
|
OO.inheritClass( ve.ui.MWWikitextSwitchConfirmDialog, OO.ui.MessageDialog );
|
2014-06-25 20:13:11 +00:00
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
|
|
|
ve.ui.MWWikitextSwitchConfirmDialog.static.name = 'wikitextswitchconfirm';
|
|
|
|
|
2014-07-14 21:32:49 +00:00
|
|
|
ve.ui.MWWikitextSwitchConfirmDialog.static.verbose = true;
|
|
|
|
|
|
|
|
ve.ui.MWWikitextSwitchConfirmDialog.static.size = 'small';
|
|
|
|
|
2014-06-25 20:13:11 +00:00
|
|
|
ve.ui.MWWikitextSwitchConfirmDialog.static.icon = 'help';
|
|
|
|
|
2014-07-14 21:32:49 +00:00
|
|
|
ve.ui.MWWikitextSwitchConfirmDialog.static.title =
|
|
|
|
OO.ui.deferMsg( 'visualeditor-mweditmodesource-title' );
|
|
|
|
|
|
|
|
ve.ui.MWWikitextSwitchConfirmDialog.static.message =
|
|
|
|
OO.ui.deferMsg( 'visualeditor-mweditmodesource-warning' );
|
|
|
|
|
|
|
|
ve.ui.MWWikitextSwitchConfirmDialog.static.actions = [
|
|
|
|
{
|
2014-08-22 20:50:48 +00:00
|
|
|
action: 'cancel',
|
|
|
|
label: OO.ui.deferMsg( 'visualeditor-mweditmodesource-warning-cancel' ),
|
|
|
|
flags: 'safe'
|
2014-07-14 21:32:49 +00:00
|
|
|
},
|
|
|
|
{
|
2014-08-22 20:50:48 +00:00
|
|
|
action: 'switch',
|
|
|
|
label: OO.ui.deferMsg( 'visualeditor-mweditmodesource-warning-switch' ),
|
|
|
|
flags: 'primary'
|
2014-07-14 21:32:49 +00:00
|
|
|
},
|
|
|
|
{
|
2014-08-22 20:50:48 +00:00
|
|
|
action: 'discard',
|
|
|
|
label: OO.ui.deferMsg( 'visualeditor-mweditmodesource-warning-switch-discard' ),
|
|
|
|
flags: 'destructive'
|
2014-07-14 21:32:49 +00:00
|
|
|
}
|
|
|
|
];
|
2014-06-25 20:13:11 +00:00
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2014-07-14 21:32:49 +00:00
|
|
|
ve.ui.MWWikitextSwitchConfirmDialog.prototype.getActionProcess = function ( action ) {
|
2014-07-07 19:51:41 +00:00
|
|
|
if ( action === 'switch' ) {
|
|
|
|
return new OO.ui.Process( function () {
|
|
|
|
this.getActions().setAbilities( { cancel: false, discard: false } );
|
|
|
|
this.getActions().get()[1].pushPending();
|
|
|
|
this.target.switchToWikitextEditor( false );
|
|
|
|
}, this );
|
|
|
|
} else if ( action === 'discard' ) {
|
|
|
|
return new OO.ui.Process( function () {
|
|
|
|
this.getActions().setAbilities( { cancel: false, switch: false } );
|
|
|
|
this.getActions().get()[2].pushPending();
|
|
|
|
this.target.switchToWikitextEditor( true );
|
|
|
|
}, this );
|
|
|
|
} else if ( action === 'cancel' ) {
|
2014-07-14 21:32:49 +00:00
|
|
|
return new OO.ui.Process( function () {
|
2014-08-22 20:50:48 +00:00
|
|
|
this.close( { action: action } );
|
2014-07-07 19:51:41 +00:00
|
|
|
this.target.resetDocumentOpacity();
|
2014-07-14 21:32:49 +00:00
|
|
|
}, this );
|
|
|
|
}
|
|
|
|
|
2014-06-25 20:13:11 +00:00
|
|
|
// Parent method
|
2014-07-14 21:32:49 +00:00
|
|
|
return ve.ui.MWWikitextSwitchConfirmDialog.super.prototype.getActionProcess.call( this, action );
|
2014-06-25 20:13:11 +00:00
|
|
|
};
|
|
|
|
|
2014-07-07 19:51:41 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
**/
|
|
|
|
ve.ui.MWWikitextSwitchConfirmDialog.prototype.setup = function ( data ) {
|
|
|
|
this.target = data.target;
|
|
|
|
|
|
|
|
// Parent method
|
|
|
|
return ve.ui.MWWikitextSwitchConfirmDialog.super.prototype.setup.call( this, data );
|
|
|
|
};
|
|
|
|
|
2014-06-25 20:13:11 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWWikitextSwitchConfirmDialog.prototype.getTeardownProcess = function ( data ) {
|
2014-07-15 22:49:51 +00:00
|
|
|
data = data || {};
|
2014-06-25 20:13:11 +00:00
|
|
|
return ve.ui.MWWikitextSwitchConfirmDialog.super.prototype.getTeardownProcess.call( this, data )
|
|
|
|
.first( function () {
|
2014-07-14 21:32:49 +00:00
|
|
|
// EVIL HACK - we shouldn't be reaching into the manager for these promises
|
2014-06-25 20:13:11 +00:00
|
|
|
if ( data.action === 'switch' || data.action === 'discard' ) {
|
2014-07-14 21:32:49 +00:00
|
|
|
this.manager.closing.resolve( data );
|
2014-06-25 20:13:11 +00:00
|
|
|
} else {
|
2014-07-14 21:32:49 +00:00
|
|
|
this.manager.closing.reject( data );
|
2014-06-25 20:13:11 +00:00
|
|
|
}
|
|
|
|
}, this );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.ui.windowFactory.register( ve.ui.MWWikitextSwitchConfirmDialog );
|