2015-10-14 23:34:34 +00:00
|
|
|
/*
|
|
|
|
* VisualEditor user interface MWVESwitchConfirmDialog class.
|
|
|
|
*
|
2016-01-03 22:56:59 +00:00
|
|
|
* @copyright 2011-2016 VisualEditor Team and others; see AUTHORS.txt
|
2015-10-14 23:34:34 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
2015-11-03 18:32:13 +00:00
|
|
|
mw.libs.ve = mw.libs.ve || {};
|
2015-10-14 23:34:34 +00:00
|
|
|
/**
|
|
|
|
* Dialog for letting the user choose how to switch to wikitext mode.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends OO.ui.MessageDialog
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} [config] Configuration options
|
|
|
|
*/
|
2015-11-03 18:32:13 +00:00
|
|
|
mw.libs.ve.SwitchConfirmDialog = function MWLibsVESwitchConfirmDialog( config ) {
|
2015-10-14 23:34:34 +00:00
|
|
|
// Parent constructor
|
2015-11-03 18:32:13 +00:00
|
|
|
mw.libs.ve.SwitchConfirmDialog.super.call( this, config );
|
2015-10-14 23:34:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2015-11-03 18:32:13 +00:00
|
|
|
OO.inheritClass( mw.libs.ve.SwitchConfirmDialog, OO.ui.MessageDialog );
|
2015-10-14 23:34:34 +00:00
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
2015-11-03 18:32:13 +00:00
|
|
|
mw.libs.ve.SwitchConfirmDialog.static.name = 'veswitchconfirm';
|
2015-10-14 23:34:34 +00:00
|
|
|
|
2015-11-03 18:32:13 +00:00
|
|
|
mw.libs.ve.SwitchConfirmDialog.static.verbose = true;
|
2015-10-14 23:34:34 +00:00
|
|
|
|
2015-11-03 18:32:13 +00:00
|
|
|
mw.libs.ve.SwitchConfirmDialog.static.size = 'small';
|
2015-10-14 23:34:34 +00:00
|
|
|
|
2015-11-03 18:32:13 +00:00
|
|
|
mw.libs.ve.SwitchConfirmDialog.static.title =
|
2015-10-14 23:34:34 +00:00
|
|
|
mw.msg( 'visualeditor-mweditmodeve-title' );
|
|
|
|
|
2015-11-03 18:32:13 +00:00
|
|
|
mw.libs.ve.SwitchConfirmDialog.static.message =
|
2015-10-14 23:34:34 +00:00
|
|
|
mw.msg( 'visualeditor-mweditmodeve-warning' );
|
|
|
|
|
2015-11-03 18:32:13 +00:00
|
|
|
mw.libs.ve.SwitchConfirmDialog.static.actions = [
|
2015-10-14 23:34:34 +00:00
|
|
|
{
|
|
|
|
action: 'cancel',
|
|
|
|
label: mw.msg( 'visualeditor-mweditmodesource-warning-cancel' ),
|
2015-11-03 18:57:15 +00:00
|
|
|
flags: [ 'safe', 'back' ],
|
|
|
|
modes: [ 'restbase', 'simple' ]
|
2015-10-14 23:34:34 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
action: 'discard',
|
|
|
|
label: mw.msg( 'visualeditor-mweditmodesource-warning-switch-discard' ),
|
2015-11-03 18:57:15 +00:00
|
|
|
flags: 'destructive',
|
2016-03-07 20:07:41 +00:00
|
|
|
modes: [ 'simple' ]
|
2015-11-03 18:57:15 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
action: 'keep',
|
|
|
|
label: mw.msg( 'visualeditor-mweditmodesource-warning-switch' ),
|
|
|
|
flags: [ 'progressive', 'primary' ],
|
|
|
|
modes: [ 'restbase' ]
|
2015-10-14 23:34:34 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2016-09-06 19:16:55 +00:00
|
|
|
mw.libs.ve.SwitchConfirmDialog.prototype.getSetupProcess = function ( data ) {
|
2015-11-03 18:32:13 +00:00
|
|
|
return mw.libs.ve.SwitchConfirmDialog.super.prototype.getSetupProcess.apply( this, arguments )
|
2015-10-14 23:34:34 +00:00
|
|
|
.next( function () {
|
2016-09-06 19:16:55 +00:00
|
|
|
if ( data && data.mode ) {
|
|
|
|
this.actions.setMode( data.mode );
|
|
|
|
} else if (
|
2015-11-04 16:19:36 +00:00
|
|
|
mw.config.get( 'wgVisualEditorConfig' ).fullRestbaseUrl &&
|
|
|
|
!$( 'input[name=wpSection]' ).val()
|
|
|
|
) {
|
|
|
|
this.actions.setMode( 'restbase' );
|
|
|
|
} else {
|
|
|
|
this.actions.setMode( 'simple' );
|
|
|
|
}
|
2015-10-14 23:34:34 +00:00
|
|
|
}, this );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2015-11-03 18:32:13 +00:00
|
|
|
mw.libs.ve.SwitchConfirmDialog.prototype.getActionProcess = function ( action ) {
|
2015-10-14 23:34:34 +00:00
|
|
|
if ( action === 'keep' ) {
|
|
|
|
return new OO.ui.Process( function () {
|
2015-11-03 18:58:59 +00:00
|
|
|
this.getActions()
|
|
|
|
.setAbilities( { cancel: false, discard: false } )
|
|
|
|
.get( { actions: 'keep' } )[ 0 ].pushPending();
|
2015-10-14 23:34:34 +00:00
|
|
|
this.close( { action: 'keep' } );
|
|
|
|
}, this );
|
|
|
|
} else if ( action === 'discard' ) {
|
|
|
|
return new OO.ui.Process( function () {
|
2015-11-03 18:58:59 +00:00
|
|
|
this.getActions()
|
|
|
|
.setAbilities( { cancel: false, keep: false } )
|
|
|
|
.get( { actions: 'discard' } )[ 0 ].pushPending();
|
2015-10-14 23:34:34 +00:00
|
|
|
this.close( { action: 'discard' } );
|
|
|
|
}, this );
|
|
|
|
} else if ( action === 'cancel' ) {
|
|
|
|
return new OO.ui.Process( function () {
|
|
|
|
this.close( { action: 'cancel' } );
|
|
|
|
}, this );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parent method
|
2015-11-03 18:32:13 +00:00
|
|
|
return mw.libs.ve.SwitchConfirmDialog.super.prototype.getActionProcess.call( this, action );
|
2015-10-14 23:34:34 +00:00
|
|
|
};
|