2018-09-26 12:49:10 +00:00
|
|
|
/*!
|
2013-06-11 19:16:04 +00:00
|
|
|
* VisualEditor user interface MWTransclusionDialog class.
|
|
|
|
*
|
2020-01-08 17:13:04 +00:00
|
|
|
* @copyright 2011-2020 VisualEditor Team and others; see AUTHORS.txt
|
2013-06-11 19:16:04 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2021-06-03 16:25:15 +00:00
|
|
|
* Dialog for inserting and editing MediaWiki transclusions, i.e. a sequence of one or more template
|
|
|
|
* invocations that strictly belong to each other (e.g. because they are unbalanced), possibly
|
|
|
|
* mixed with raw wikitext snippets.
|
|
|
|
*
|
|
|
|
* Note the base class {@see ve.ui.MWTemplateDialog} alone does not allow to manage more than a
|
|
|
|
* single template invocation. Most of the code for this feature set is exclusive to this subclass.
|
2013-06-11 19:16:04 +00:00
|
|
|
*
|
|
|
|
* @class
|
2014-04-10 19:07:40 +00:00
|
|
|
* @extends ve.ui.MWTemplateDialog
|
2013-06-11 19:16:04 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
2013-09-25 10:21:09 +00:00
|
|
|
* @param {Object} [config] Configuration options
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
2014-08-21 00:50:54 +00:00
|
|
|
ve.ui.MWTransclusionDialog = function VeUiMWTransclusionDialog( config ) {
|
2013-06-11 19:16:04 +00:00
|
|
|
// Parent constructor
|
2014-08-21 00:50:54 +00:00
|
|
|
ve.ui.MWTransclusionDialog.super.call( this, config );
|
2013-07-03 01:30:10 +00:00
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
// Properties
|
2021-06-04 15:41:41 +00:00
|
|
|
this.isSidebarExpanded = null;
|
2021-05-07 10:40:36 +00:00
|
|
|
this.closeButton = null;
|
|
|
|
this.backButton = null;
|
2021-05-03 10:40:02 +00:00
|
|
|
|
2021-05-07 14:03:25 +00:00
|
|
|
this.resetConfirmation = new OO.ui.FieldsetLayout( {
|
|
|
|
classes: [ 'oo-ui-processDialog-errors' ]
|
|
|
|
} );
|
|
|
|
this.resetConfirmationTitle = new OO.ui.LabelWidget( {
|
|
|
|
label: OO.ui.deferMsg( 'visualeditor-dialog-transclusion-reset-confirmation-title' )
|
|
|
|
} );
|
|
|
|
this.resetConfirmationMessage = new OO.ui.MessageWidget( {
|
|
|
|
label: OO.ui.deferMsg( 'visualeditor-dialog-transclusion-reset-confirmation-message' ),
|
|
|
|
type: 'error'
|
|
|
|
} );
|
|
|
|
this.resetConfirmationCancelButton = new OO.ui.ButtonWidget( {
|
|
|
|
label: OO.ui.deferMsg( 'visualeditor-dialog-transclusion-reset-confirmation-cancel' )
|
|
|
|
} );
|
|
|
|
this.resetConfirmationResetButton = new OO.ui.ButtonWidget( {
|
|
|
|
label: OO.ui.deferMsg( 'visualeditor-dialog-transclusion-reset-confirmation-reset' ),
|
|
|
|
flags: [ 'primary', 'destructive' ]
|
|
|
|
} );
|
|
|
|
|
|
|
|
// Events
|
|
|
|
this.resetConfirmationCancelButton.connect( this, {
|
|
|
|
click: 'resetConfirmationHide'
|
|
|
|
} );
|
|
|
|
this.resetConfirmationResetButton.connect( this, {
|
|
|
|
click: 'resetConfirmationReset'
|
|
|
|
} );
|
|
|
|
|
|
|
|
// Initialization
|
|
|
|
this.resetConfirmation.addItems( [
|
|
|
|
new OO.ui.HorizontalLayout( {
|
|
|
|
items: [ this.resetConfirmationTitle ],
|
|
|
|
classes: [ 'oo-ui-processDialog-errors-title' ]
|
|
|
|
} ),
|
|
|
|
this.resetConfirmationMessage,
|
|
|
|
new OO.ui.HorizontalLayout( {
|
|
|
|
items: [ this.resetConfirmationCancelButton, this.resetConfirmationResetButton ],
|
|
|
|
classes: [ 'oo-ui-processDialog-errors-actions' ]
|
|
|
|
} )
|
|
|
|
] );
|
|
|
|
this.resetConfirmation.toggle( false );
|
|
|
|
this.$content.append( this.resetConfirmation.$element );
|
|
|
|
|
2021-05-03 10:40:02 +00:00
|
|
|
// Temporary override while feature flag is in place.
|
|
|
|
this.isBigger = mw.config.get( 'wgVisualEditorConfig' ).transclusionDialogInlineDescriptions;
|
|
|
|
if ( this.isBigger ) {
|
|
|
|
this.$element.addClass( 've-ui-mwTransclusionDialog-bigger' );
|
|
|
|
}
|
2021-05-10 12:56:03 +00:00
|
|
|
|
|
|
|
// Temporary change bolding while feature flag is in place.
|
|
|
|
if ( mw.config.get( 'wgVisualEditorConfig' ).templateSearchImprovements ) {
|
|
|
|
this.$element.addClass( 've-ui-mwTransclusionDialog-enhancedSearch' );
|
|
|
|
}
|
2013-06-11 19:16:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2014-04-10 19:07:40 +00:00
|
|
|
OO.inheritClass( ve.ui.MWTransclusionDialog, ve.ui.MWTemplateDialog );
|
2013-07-03 01:30:10 +00:00
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
/* Static Properties */
|
|
|
|
|
2014-03-04 22:56:14 +00:00
|
|
|
ve.ui.MWTransclusionDialog.static.name = 'transclusion';
|
|
|
|
|
2014-04-30 21:34:45 +00:00
|
|
|
ve.ui.MWTransclusionDialog.static.title =
|
2021-05-27 09:13:24 +00:00
|
|
|
OO.ui.deferMsg( 'visualeditor-dialog-transclusion-title-edit-transclusion' );
|
2014-04-30 21:34:45 +00:00
|
|
|
|
2014-07-14 21:32:49 +00:00
|
|
|
ve.ui.MWTransclusionDialog.static.actions = ve.ui.MWTemplateDialog.static.actions.concat( [
|
|
|
|
{
|
2014-08-22 20:50:48 +00:00
|
|
|
action: 'mode',
|
2017-06-14 18:34:24 +00:00
|
|
|
modes: [ 'edit', 'insert' ],
|
|
|
|
// HACK: Will be set later, but we want measurements to be accurate in the mean time, this
|
|
|
|
// will not be needed when T93290 is resolved
|
|
|
|
label: $( document.createTextNode( '\u00a0' ) )
|
2021-05-07 10:40:36 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
action: 'back',
|
|
|
|
label: OO.ui.deferMsg( 'visualeditor-dialog-action-goback' ),
|
|
|
|
modes: [ 'edit', 'insert' ],
|
|
|
|
flags: [ 'safe', 'back' ]
|
2014-07-14 21:32:49 +00:00
|
|
|
}
|
|
|
|
] );
|
|
|
|
|
2014-04-10 19:07:40 +00:00
|
|
|
ve.ui.MWTransclusionDialog.static.bookletLayoutConfig = ve.extendObject(
|
|
|
|
{},
|
|
|
|
ve.ui.MWTemplateDialog.static.bookletLayoutConfig,
|
2014-08-22 20:50:48 +00:00
|
|
|
{ outlined: true, editable: true }
|
2014-04-10 19:07:40 +00:00
|
|
|
);
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
/* Methods */
|
|
|
|
|
2014-03-04 22:56:14 +00:00
|
|
|
/**
|
|
|
|
* Handle outline controls move events.
|
|
|
|
*
|
|
|
|
* @param {number} places Number of places to move the selected item
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.onOutlineControlsMove = function ( places ) {
|
|
|
|
var part, promise,
|
2014-04-24 00:22:45 +00:00
|
|
|
parts = this.transclusionModel.getParts(),
|
2021-06-04 12:55:01 +00:00
|
|
|
itemId = this.transclusions.getFocusedPart();
|
2014-03-04 22:56:14 +00:00
|
|
|
|
2021-06-04 12:55:01 +00:00
|
|
|
if ( itemId ) {
|
|
|
|
part = this.transclusionModel.getPartFromId( itemId );
|
2014-03-04 22:56:14 +00:00
|
|
|
// Move part to new location, and if dialog is loaded switch to new part page
|
2015-03-10 12:50:42 +00:00
|
|
|
promise = this.transclusionModel.addPart( part, parts.indexOf( part ) + places );
|
2014-03-04 22:56:14 +00:00
|
|
|
if ( this.loaded && !this.preventReselection ) {
|
2021-06-04 12:46:34 +00:00
|
|
|
promise.done( this.transclusions.focusPart.bind( this.transclusions, part.getId() ) );
|
2014-03-04 22:56:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle outline controls remove events.
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.onOutlineControlsRemove = function () {
|
2021-06-04 12:55:01 +00:00
|
|
|
var part, param,
|
|
|
|
id = this.transclusions.getFocusedPart();
|
2014-03-04 22:56:14 +00:00
|
|
|
|
2021-06-04 12:55:01 +00:00
|
|
|
if ( id ) {
|
2014-04-24 00:22:45 +00:00
|
|
|
part = this.transclusionModel.getPartFromId( id );
|
2014-03-04 22:56:14 +00:00
|
|
|
// Check if the part is the actual template, or one of its parameters
|
|
|
|
if ( part instanceof ve.dm.MWTemplateModel && id !== part.getId() ) {
|
|
|
|
param = part.getParameterFromId( id );
|
|
|
|
if ( param instanceof ve.dm.MWParameterModel ) {
|
|
|
|
part.removeParameter( param );
|
|
|
|
}
|
|
|
|
} else if ( part instanceof ve.dm.MWTransclusionPartModel ) {
|
2014-04-24 00:22:45 +00:00
|
|
|
this.transclusionModel.removePart( part );
|
2014-03-04 22:56:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle add template button click events.
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.onAddTemplateButtonClick = function () {
|
2014-04-24 00:22:45 +00:00
|
|
|
this.addPart( new ve.dm.MWTemplatePlaceholderModel( this.transclusionModel ) );
|
2014-03-04 22:56:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle add content button click events.
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.onAddContentButtonClick = function () {
|
2014-04-24 00:22:45 +00:00
|
|
|
this.addPart( new ve.dm.MWTransclusionContentModel( this.transclusionModel, '' ) );
|
2014-03-04 22:56:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle add parameter button click events.
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.onAddParameterButtonClick = function () {
|
|
|
|
var part, param,
|
2021-06-04 12:55:01 +00:00
|
|
|
itemId = this.transclusions.getFocusedPart();
|
2014-03-04 22:56:14 +00:00
|
|
|
|
2021-06-04 12:55:01 +00:00
|
|
|
if ( itemId ) {
|
|
|
|
part = this.transclusionModel.getPartFromId( itemId );
|
2014-03-04 22:56:14 +00:00
|
|
|
if ( part instanceof ve.dm.MWTemplateModel ) {
|
|
|
|
param = new ve.dm.MWParameterModel( part, '', null );
|
|
|
|
part.addParameter( param );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle booklet layout page set events.
|
|
|
|
*
|
|
|
|
* @param {OO.ui.PageLayout} page Active page
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.onBookletLayoutSet = function ( page ) {
|
|
|
|
this.addParameterButton.setDisabled(
|
2019-02-24 12:38:03 +00:00
|
|
|
!( page instanceof ve.ui.MWTemplatePage || page instanceof ve.ui.MWParameterPage ) ||
|
|
|
|
this.isReadOnly()
|
2014-03-04 22:56:14 +00:00
|
|
|
);
|
2014-08-27 19:58:54 +00:00
|
|
|
this.bookletLayout.getOutlineControls().removeButton.toggle( !(
|
2015-07-25 13:43:09 +00:00
|
|
|
(
|
|
|
|
page instanceof ve.ui.MWParameterPage &&
|
|
|
|
page.parameter.isRequired()
|
|
|
|
) || (
|
|
|
|
this.transclusionModel.getParts().length === 1 &&
|
|
|
|
page instanceof ve.ui.MWTemplatePlaceholderPage
|
|
|
|
)
|
2014-08-27 19:58:54 +00:00
|
|
|
) );
|
2014-03-04 22:56:14 +00:00
|
|
|
};
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
/**
|
2014-04-10 19:07:40 +00:00
|
|
|
* @inheritdoc
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
2013-12-02 20:10:55 +00:00
|
|
|
ve.ui.MWTransclusionDialog.prototype.onReplacePart = function ( removed, added ) {
|
2018-11-29 22:10:56 +00:00
|
|
|
var single;
|
2014-07-14 21:32:49 +00:00
|
|
|
|
2014-04-10 19:07:40 +00:00
|
|
|
ve.ui.MWTransclusionDialog.super.prototype.onReplacePart.call( this, removed, added );
|
2014-07-14 21:32:49 +00:00
|
|
|
|
2014-10-23 18:37:50 +00:00
|
|
|
if ( this.transclusionModel.getParts().length === 0 ) {
|
|
|
|
this.addParameterButton.setDisabled( true );
|
2015-03-19 22:54:48 +00:00
|
|
|
this.addPart( new ve.dm.MWTemplatePlaceholderModel( this.transclusionModel ) );
|
2014-10-23 18:37:50 +00:00
|
|
|
}
|
|
|
|
|
2014-07-14 21:32:49 +00:00
|
|
|
single = this.isSingleTemplateTransclusion();
|
2018-11-29 22:10:56 +00:00
|
|
|
this.actions.setAbilities( { mode: single } );
|
2021-05-07 10:40:36 +00:00
|
|
|
this.updateActionSet();
|
2013-06-11 19:16:04 +00:00
|
|
|
};
|
|
|
|
|
2013-06-18 21:24:16 +00:00
|
|
|
/**
|
2021-06-04 15:41:41 +00:00
|
|
|
* @return {boolean} True if the dialog contains a single template or template placeholder. False
|
|
|
|
* otherwise. Also false if there is no data model connected yet.
|
2013-06-18 21:24:16 +00:00
|
|
|
*/
|
2014-03-06 23:39:40 +00:00
|
|
|
ve.ui.MWTransclusionDialog.prototype.isSingleTemplateTransclusion = function () {
|
2014-04-24 00:22:45 +00:00
|
|
|
var parts = this.transclusionModel && this.transclusionModel.getParts();
|
2014-03-04 22:56:14 +00:00
|
|
|
|
|
|
|
return parts && parts.length === 1 && (
|
2015-08-19 17:33:02 +00:00
|
|
|
parts[ 0 ] instanceof ve.dm.MWTemplateModel ||
|
|
|
|
parts[ 0 ] instanceof ve.dm.MWTemplatePlaceholderModel
|
2014-02-26 00:22:26 +00:00
|
|
|
);
|
2013-06-18 21:24:16 +00:00
|
|
|
};
|
|
|
|
|
2014-03-06 23:39:40 +00:00
|
|
|
/**
|
2014-04-10 19:07:40 +00:00
|
|
|
* @inheritdoc
|
2014-03-04 22:56:14 +00:00
|
|
|
*/
|
2014-04-10 19:07:40 +00:00
|
|
|
ve.ui.MWTransclusionDialog.prototype.getPageFromPart = function ( part ) {
|
|
|
|
var page = ve.ui.MWTransclusionDialog.super.prototype.getPageFromPart.call( this, part );
|
|
|
|
if ( !page && part instanceof ve.dm.MWTransclusionContentModel ) {
|
2019-02-24 12:38:03 +00:00
|
|
|
return new ve.ui.MWTransclusionContentPage( part, part.getId(), { $overlay: this.$overlay, isReadOnly: this.isReadOnly() } );
|
2014-04-10 19:07:40 +00:00
|
|
|
}
|
|
|
|
return page;
|
2014-03-04 22:56:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2021-06-04 15:41:41 +00:00
|
|
|
* Set if the dialog is expanded and the sidebar visible, or collapsed. `auto` will choose
|
|
|
|
* `collapsed` if possible.
|
2014-03-04 22:56:14 +00:00
|
|
|
*
|
2021-06-04 15:41:41 +00:00
|
|
|
* @param {string} [mode='expanded'] Symbolic name of dialog mode, `expanded`, `collapsed` or 'auto'
|
2014-03-04 22:56:14 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.setMode = function ( mode ) {
|
2021-06-04 15:41:41 +00:00
|
|
|
var isSidebarExpanded;
|
|
|
|
if ( mode === 'auto' && this.isSingleTemplateTransclusion() ) {
|
|
|
|
isSidebarExpanded = false;
|
|
|
|
} else {
|
|
|
|
isSidebarExpanded = mode !== 'collapsed';
|
2014-03-04 22:56:14 +00:00
|
|
|
}
|
2014-11-08 00:41:03 +00:00
|
|
|
|
2021-06-04 15:41:41 +00:00
|
|
|
if ( this.isSidebarExpanded !== isSidebarExpanded ) {
|
|
|
|
this.isSidebarExpanded = isSidebarExpanded;
|
2014-11-08 00:41:03 +00:00
|
|
|
if ( this.$content ) {
|
2021-06-04 15:41:41 +00:00
|
|
|
this.$content
|
|
|
|
.toggleClass( 've-ui-mwTransclusionDialog-collapsed', !isSidebarExpanded )
|
|
|
|
.toggleClass( 've-ui-mwTransclusionDialog-expanded', isSidebarExpanded );
|
2014-03-04 22:56:14 +00:00
|
|
|
}
|
2021-06-04 15:41:41 +00:00
|
|
|
this.setSize( isSidebarExpanded ? ( this.isBigger ? 'larger' : 'large' ) : 'medium' );
|
|
|
|
this.bookletLayout.toggleOutline( isSidebarExpanded );
|
2014-11-08 00:41:03 +00:00
|
|
|
this.updateTitle();
|
2017-06-14 15:52:18 +00:00
|
|
|
this.updateModeActionState();
|
2014-11-08 00:41:03 +00:00
|
|
|
|
|
|
|
// HACK blur any active input so that its dropdown will be hidden and won't end
|
|
|
|
// up being mispositioned
|
2019-01-18 21:03:38 +00:00
|
|
|
this.$content.find( 'input:focus' ).trigger( 'blur' );
|
2014-03-04 22:56:14 +00:00
|
|
|
}
|
2014-03-06 23:39:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the dialog title.
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.updateTitle = function () {
|
2021-05-27 09:13:24 +00:00
|
|
|
if ( !this.isSingleTemplateTransclusion() ) {
|
2014-07-14 21:32:49 +00:00
|
|
|
this.title.setLabel( this.constructor.static.title );
|
2014-04-30 21:34:45 +00:00
|
|
|
} else {
|
|
|
|
// Parent method
|
|
|
|
ve.ui.MWTransclusionDialog.super.prototype.updateTitle.call( this );
|
|
|
|
}
|
2014-03-04 22:56:14 +00:00
|
|
|
};
|
|
|
|
|
2014-11-08 00:41:03 +00:00
|
|
|
/**
|
2017-06-14 15:52:18 +00:00
|
|
|
* Update the state of the 'mode' action
|
2014-11-08 00:41:03 +00:00
|
|
|
*/
|
2017-06-14 15:52:18 +00:00
|
|
|
ve.ui.MWTransclusionDialog.prototype.updateModeActionState = function () {
|
|
|
|
var parts = this.transclusionModel && this.transclusionModel.getParts(),
|
2021-06-04 15:41:41 +00:00
|
|
|
isSidebarExpanded = this.isSidebarExpanded,
|
|
|
|
label = ve.msg( isSidebarExpanded ?
|
2021-06-10 10:31:44 +00:00
|
|
|
'visualeditor-dialog-transclusion-single-mode' :
|
|
|
|
'visualeditor-dialog-transclusion-multiple-mode' );
|
2014-11-08 00:41:03 +00:00
|
|
|
this.actions.forEach( { actions: [ 'mode' ] }, function ( action ) {
|
2020-03-19 13:39:53 +00:00
|
|
|
action.setLabel( label );
|
2021-06-04 15:41:41 +00:00
|
|
|
action.$button.attr( 'aria-expanded', isSidebarExpanded ? 1 : 0 );
|
2014-11-08 00:41:03 +00:00
|
|
|
} );
|
2017-06-14 15:52:18 +00:00
|
|
|
|
|
|
|
// Decide whether the button should be enabled or not. It needs to be:
|
|
|
|
// * disabled when we're in the initial add-new-template phase, because it's
|
|
|
|
// meaningless
|
|
|
|
// * disabled if we're in a multi-part transclusion, because the sidebar's
|
|
|
|
// forced open
|
|
|
|
// * enabled if we're in a single-part transclusion, because the sidebar's
|
|
|
|
// closed but can be opened to add more parts
|
|
|
|
if ( parts ) {
|
|
|
|
if ( parts.length === 1 && parts[ 0 ] instanceof ve.dm.MWTemplatePlaceholderModel ) {
|
|
|
|
// Initial new-template phase: button is meaningless
|
|
|
|
this.actions.setAbilities( { mode: false } );
|
|
|
|
} else if ( !this.isSingleTemplateTransclusion() ) {
|
|
|
|
// Multi-part transclusion: button disabled because sidebar forced-open
|
|
|
|
this.actions.setAbilities( { mode: false } );
|
|
|
|
} else {
|
|
|
|
// Single-part transclusion: button enabled because sidebar is optional
|
|
|
|
this.actions.setAbilities( { mode: true } );
|
|
|
|
}
|
|
|
|
}
|
2014-11-08 00:41:03 +00:00
|
|
|
};
|
|
|
|
|
2014-03-04 22:56:14 +00:00
|
|
|
/**
|
|
|
|
* Add a part to the transclusion.
|
|
|
|
*
|
|
|
|
* @param {ve.dm.MWTransclusionPartModel} part Part to add
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.addPart = function ( part ) {
|
|
|
|
var index, promise,
|
2014-04-24 00:22:45 +00:00
|
|
|
parts = this.transclusionModel.getParts(),
|
2021-06-04 12:55:01 +00:00
|
|
|
itemId = this.transclusions.getFocusedPart();
|
2014-03-04 22:56:14 +00:00
|
|
|
|
|
|
|
if ( part ) {
|
|
|
|
// Insert after selected part, or at the end if nothing is selected
|
2021-06-04 12:55:01 +00:00
|
|
|
index = itemId ?
|
|
|
|
parts.indexOf( this.transclusionModel.getPartFromId( itemId ) ) + 1 :
|
2014-03-04 22:56:14 +00:00
|
|
|
parts.length;
|
|
|
|
// Add the part, and if dialog is loaded switch to part page
|
2014-04-24 00:22:45 +00:00
|
|
|
promise = this.transclusionModel.addPart( part, index );
|
2014-03-04 22:56:14 +00:00
|
|
|
if ( this.loaded && !this.preventReselection ) {
|
2021-06-04 12:46:34 +00:00
|
|
|
promise.done( this.transclusions.focusPart.bind( this.transclusions, part.getId() ) );
|
2014-03-04 22:56:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-07-14 21:32:49 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.getActionProcess = function ( action ) {
|
2021-05-07 10:40:36 +00:00
|
|
|
if ( action === 'back' ) {
|
2021-05-07 14:03:25 +00:00
|
|
|
if ( this.isEmpty() ) {
|
|
|
|
return this.getActionProcess( 'reset' );
|
|
|
|
}
|
|
|
|
return new OO.ui.Process( function () {
|
|
|
|
this.resetConfirmation.toggle( true );
|
|
|
|
}, this );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( action === 'reset' ) {
|
2021-05-07 10:40:36 +00:00
|
|
|
return new OO.ui.Process( function () {
|
|
|
|
this.resetDialog();
|
|
|
|
}, this );
|
|
|
|
}
|
|
|
|
|
2014-07-14 21:32:49 +00:00
|
|
|
if ( action === 'mode' ) {
|
|
|
|
return new OO.ui.Process( function () {
|
2021-06-04 15:41:41 +00:00
|
|
|
this.setMode( this.isSidebarExpanded ? 'collapsed' : 'expanded' );
|
2014-07-14 21:32:49 +00:00
|
|
|
}, this );
|
|
|
|
}
|
|
|
|
|
|
|
|
return ve.ui.MWTransclusionDialog.super.prototype.getActionProcess.call( this, action );
|
|
|
|
};
|
|
|
|
|
2021-05-07 10:40:36 +00:00
|
|
|
/**
|
|
|
|
* Update the widgets in the dialog's action bar.
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.updateActionSet = function () {
|
|
|
|
var veConfig = mw.config.get( 'wgVisualEditorConfig' ),
|
2021-06-02 09:59:38 +00:00
|
|
|
backButton = this.actions.get( { flags: [ 'back' ] } ).pop(),
|
|
|
|
saveButton = this.actions.get( { actions: [ 'done' ] } ).pop();
|
|
|
|
|
|
|
|
if ( saveButton && this.getMode() === 'edit' ) {
|
|
|
|
saveButton.setLabel( ve.msg( 'visualeditor-dialog-transclusion-action-save' ) );
|
|
|
|
}
|
2021-05-07 10:40:36 +00:00
|
|
|
|
|
|
|
if ( backButton ) {
|
|
|
|
// Todo: this won't be needed if https://gerrit.wikimedia.org/r/c/oojs/ui/+/686439 is resolved
|
|
|
|
this.backButton = backButton;
|
|
|
|
}
|
|
|
|
|
2021-05-26 06:47:52 +00:00
|
|
|
// T283511
|
|
|
|
if ( !this.backButton ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-07 10:40:36 +00:00
|
|
|
if ( veConfig.transclusionDialogBackButton ) {
|
|
|
|
var closeButton = this.actions.get( { flags: [ 'close' ] } ).pop(),
|
|
|
|
parts = this.transclusionModel && this.transclusionModel.getParts(),
|
|
|
|
isInitialPage = parts && parts.length === 1 && parts[ 0 ] instanceof ve.dm.MWTemplatePlaceholderModel,
|
|
|
|
isInsertMode = this.getMode() === 'insert';
|
|
|
|
|
|
|
|
if ( closeButton ) {
|
|
|
|
// Todo: this won't be needed if https://gerrit.wikimedia.org/r/c/oojs/ui/+/686439 is resolved
|
|
|
|
this.closeButton = closeButton;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.closeButton.toggle( !isInsertMode || isInitialPage );
|
|
|
|
this.backButton.toggle( isInsertMode && !isInitialPage );
|
|
|
|
} else {
|
2021-05-26 06:47:52 +00:00
|
|
|
this.backButton.toggle( false );
|
2021-05-07 10:40:36 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-05-07 14:03:25 +00:00
|
|
|
/**
|
|
|
|
* Dismisses the reset confirmation.
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.resetConfirmationHide = function () {
|
|
|
|
this.resetConfirmation.toggle( false );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dismisses the reset confirmation and runs the reset action.
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.resetConfirmationReset = function () {
|
|
|
|
this.resetConfirmationHide();
|
|
|
|
this.executeAction( 'reset' );
|
|
|
|
};
|
|
|
|
|
2021-05-07 10:40:36 +00:00
|
|
|
/**
|
|
|
|
* Revert the dialog back to its initial state.
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.resetDialog = function () {
|
|
|
|
var target = this;
|
|
|
|
this.transclusionModel.reset();
|
|
|
|
this.bookletLayout.clearPages();
|
|
|
|
this.transclusionModel
|
|
|
|
.addPart( new ve.dm.MWTemplatePlaceholderModel( this.transclusionModel ), 0 )
|
|
|
|
.done( function () {
|
2021-06-04 15:41:41 +00:00
|
|
|
target.setMode( 'collapsed' );
|
2021-05-07 10:40:36 +00:00
|
|
|
target.updateModeActionState();
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2021-05-17 11:26:11 +00:00
|
|
|
/**
|
|
|
|
* @return {boolean} False if any transclusion part contains non-default input
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.isEmpty = function () {
|
|
|
|
return this.transclusionModel.getParts().every( function ( part ) {
|
|
|
|
return part.isEmpty();
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2013-11-05 00:29:50 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.initialize = function () {
|
|
|
|
// Parent method
|
2014-04-10 19:07:40 +00:00
|
|
|
ve.ui.MWTransclusionDialog.super.prototype.initialize.call( this );
|
2013-11-05 00:29:50 +00:00
|
|
|
|
|
|
|
// Properties
|
2014-03-04 22:56:14 +00:00
|
|
|
this.addTemplateButton = new OO.ui.ButtonWidget( {
|
2014-08-22 20:50:48 +00:00
|
|
|
framed: false,
|
2017-07-06 16:52:56 +00:00
|
|
|
icon: 'puzzle',
|
2021-05-11 10:49:06 +00:00
|
|
|
title: ve.msg( 'visualeditor-dialog-transclusion-add-template' )
|
2014-03-04 22:56:14 +00:00
|
|
|
} );
|
|
|
|
this.addContentButton = new OO.ui.ButtonWidget( {
|
2014-08-22 20:50:48 +00:00
|
|
|
framed: false,
|
2015-11-04 14:15:29 +00:00
|
|
|
icon: 'wikiText',
|
2014-08-22 20:50:48 +00:00
|
|
|
title: ve.msg( 'visualeditor-dialog-transclusion-add-content' )
|
2014-03-04 22:56:14 +00:00
|
|
|
} );
|
|
|
|
this.addParameterButton = new OO.ui.ButtonWidget( {
|
2014-08-22 20:50:48 +00:00
|
|
|
framed: false,
|
|
|
|
icon: 'parameter',
|
|
|
|
title: ve.msg( 'visualeditor-dialog-transclusion-add-param' )
|
2014-03-04 22:56:14 +00:00
|
|
|
} );
|
2013-11-05 00:29:50 +00:00
|
|
|
|
|
|
|
// Events
|
2014-08-22 20:50:48 +00:00
|
|
|
this.bookletLayout.connect( this, { set: 'onBookletLayoutSet' } );
|
2020-02-19 20:46:11 +00:00
|
|
|
this.bookletLayout.$menu.find( '[ role="listbox" ]' ).first().attr( 'aria-label', ve.msg( 'visualeditor-dialog-transclusion-templates-menu-aria-label' ) );
|
2014-08-22 20:50:48 +00:00
|
|
|
this.addTemplateButton.connect( this, { click: 'onAddTemplateButtonClick' } );
|
|
|
|
this.addContentButton.connect( this, { click: 'onAddContentButtonClick' } );
|
|
|
|
this.addParameterButton.connect( this, { click: 'onAddParameterButtonClick' } );
|
2014-03-04 22:56:14 +00:00
|
|
|
this.bookletLayout.getOutlineControls()
|
|
|
|
.addItems( [ this.addTemplateButton, this.addContentButton, this.addParameterButton ] )
|
|
|
|
.connect( this, {
|
2014-08-22 20:50:48 +00:00
|
|
|
move: 'onOutlineControlsMove',
|
|
|
|
remove: 'onOutlineControlsRemove'
|
2014-03-04 22:56:14 +00:00
|
|
|
} );
|
2014-04-17 22:03:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2014-05-31 04:47:08 +00:00
|
|
|
ve.ui.MWTransclusionDialog.prototype.getSetupProcess = function ( data ) {
|
|
|
|
return ve.ui.MWTransclusionDialog.super.prototype.getSetupProcess.call( this, data )
|
2014-07-14 21:32:49 +00:00
|
|
|
.next( function () {
|
2019-02-24 12:38:03 +00:00
|
|
|
var isReadOnly = this.isReadOnly();
|
|
|
|
this.addTemplateButton.setDisabled( isReadOnly );
|
|
|
|
this.addContentButton.setDisabled( isReadOnly );
|
|
|
|
this.addParameterButton.setDisabled( isReadOnly );
|
|
|
|
this.bookletLayout.getOutlineControls().setAbilities( {
|
|
|
|
move: !isReadOnly,
|
|
|
|
remove: !isReadOnly
|
|
|
|
} );
|
|
|
|
|
2017-06-14 15:52:18 +00:00
|
|
|
this.updateModeActionState();
|
2018-06-21 21:08:17 +00:00
|
|
|
this.setMode( 'auto' );
|
2014-05-31 04:47:08 +00:00
|
|
|
}, this );
|
2013-11-05 00:29:50 +00:00
|
|
|
};
|
|
|
|
|
2021-05-03 10:40:02 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*
|
|
|
|
* Temporary override to increase dialog size when a feature flag is enabled.
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.getSizeProperties = function () {
|
2021-05-12 08:14:23 +00:00
|
|
|
var sizeProps = ve.ui.MWTransclusionDialog.super.prototype.getSizeProperties.call( this );
|
2021-05-03 10:40:02 +00:00
|
|
|
|
|
|
|
if ( this.isBigger ) {
|
2021-05-12 08:14:23 +00:00
|
|
|
sizeProps = ve.extendObject( { height: '90%' }, sizeProps );
|
2021-05-03 10:40:02 +00:00
|
|
|
}
|
|
|
|
|
2021-05-12 08:14:23 +00:00
|
|
|
return sizeProps;
|
2021-05-03 10:40:02 +00:00
|
|
|
};
|
|
|
|
|
2014-03-04 22:56:14 +00:00
|
|
|
/* Registration */
|
|
|
|
|
2014-04-21 22:31:21 +00:00
|
|
|
ve.ui.windowFactory.register( ve.ui.MWTransclusionDialog );
|