2015-02-25 22:56:28 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor MWTransclusionContextItem class.
|
|
|
|
*
|
2023-12-01 16:06:11 +00:00
|
|
|
* @copyright See AUTHORS.txt
|
2015-02-25 22:56:28 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Context item for a MWTransclusion.
|
|
|
|
*
|
|
|
|
* @class
|
2015-08-18 15:55:13 +00:00
|
|
|
* @extends ve.ui.LinearContextItem
|
2015-02-25 22:56:28 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
2023-07-10 13:31:31 +00:00
|
|
|
* @param {ve.ui.LinearContext} context Context the item is in
|
|
|
|
* @param {ve.dm.Model} model Model the item is related to
|
2023-02-02 09:47:32 +00:00
|
|
|
* @param {Object} [config]
|
2015-02-25 22:56:28 +00:00
|
|
|
*/
|
2015-08-18 12:54:51 +00:00
|
|
|
ve.ui.MWTransclusionContextItem = function VeUiMWTransclusionContextItem() {
|
2015-02-25 22:56:28 +00:00
|
|
|
// Parent constructor
|
2015-03-27 18:56:16 +00:00
|
|
|
ve.ui.MWTransclusionContextItem.super.apply( this, arguments );
|
2015-02-25 22:56:28 +00:00
|
|
|
|
|
|
|
// Initialization
|
|
|
|
this.$element.addClass( 've-ui-mwTransclusionContextItem' );
|
|
|
|
if ( !this.model.isSingleTemplate() ) {
|
2022-01-21 10:42:18 +00:00
|
|
|
this.setLabel( ve.msg( 'visualeditor-dialog-transclusion-title-edit-transclusion' ) );
|
2015-02-25 22:56:28 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2015-08-18 15:55:13 +00:00
|
|
|
OO.inheritClass( ve.ui.MWTransclusionContextItem, ve.ui.LinearContextItem );
|
2015-02-25 22:56:28 +00:00
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
|
|
|
ve.ui.MWTransclusionContextItem.static.name = 'transclusion';
|
|
|
|
|
2017-07-06 16:52:56 +00:00
|
|
|
ve.ui.MWTransclusionContextItem.static.icon = 'puzzle';
|
2015-02-25 22:56:28 +00:00
|
|
|
|
|
|
|
ve.ui.MWTransclusionContextItem.static.label =
|
|
|
|
OO.ui.deferMsg( 'visualeditor-dialogbutton-template-tooltip' );
|
|
|
|
|
|
|
|
ve.ui.MWTransclusionContextItem.static.modelClasses = [ ve.dm.MWTransclusionNode ];
|
|
|
|
|
|
|
|
ve.ui.MWTransclusionContextItem.static.commandName = 'transclusion';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Only display item for single-template transclusions of these templates.
|
|
|
|
*
|
|
|
|
* @property {string|string[]|null}
|
|
|
|
* @static
|
|
|
|
* @inheritable
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionContextItem.static.template = null;
|
|
|
|
|
|
|
|
/* Static Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @static
|
|
|
|
* @localdoc Sharing implementation with ve.ui.MWTransclusionDialogTool
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionContextItem.static.isCompatibleWith =
|
|
|
|
ve.ui.MWTransclusionDialogTool.static.isCompatibleWith;
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionContextItem.prototype.getDescription = function () {
|
2022-07-12 08:03:41 +00:00
|
|
|
/** @type {ve.ce.MWTransclusionNode} */
|
2019-02-19 13:23:14 +00:00
|
|
|
var nodeClass = ve.ce.nodeFactory.lookup( this.model.constructor.static.name );
|
2015-02-25 22:56:28 +00:00
|
|
|
return ve.msg(
|
|
|
|
'visualeditor-dialog-transclusion-contextitem-description',
|
2019-02-19 13:23:14 +00:00
|
|
|
nodeClass.static.getDescription( this.model ),
|
2022-03-04 09:14:20 +00:00
|
|
|
this.model.getPartsList().length
|
2015-02-25 22:56:28 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2023-02-20 15:33:52 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionContextItem.prototype.renderBody = function () {
|
|
|
|
var nodeClass = ve.ce.nodeFactory.lookup( this.model.constructor.static.name );
|
|
|
|
// eslint-disable-next-line no-jquery/no-append-html
|
|
|
|
this.$body.append( ve.htmlMsg(
|
|
|
|
'visualeditor-dialog-transclusion-contextitem-description',
|
|
|
|
nodeClass.static.getDescriptionDom( this.model ),
|
|
|
|
this.model.getPartsList().length
|
|
|
|
) );
|
|
|
|
};
|
|
|
|
|
2015-08-03 14:25:03 +00:00
|
|
|
/**
|
2023-07-11 17:10:33 +00:00
|
|
|
* @inheritdoc
|
2015-08-03 14:25:03 +00:00
|
|
|
*/
|
2023-07-11 17:10:33 +00:00
|
|
|
ve.ui.MWTransclusionContextItem.prototype.onEditButtonClick = function () {
|
2015-08-03 14:25:03 +00:00
|
|
|
var surfaceModel = this.context.getSurface().getModel(),
|
2023-07-11 17:10:33 +00:00
|
|
|
selection = surfaceModel.getSelection(),
|
|
|
|
contextItem = this;
|
2015-08-03 14:25:03 +00:00
|
|
|
|
|
|
|
if ( selection instanceof ve.dm.TableSelection ) {
|
2018-10-29 19:40:44 +00:00
|
|
|
surfaceModel.setLinearSelection( selection.getOuterRanges(
|
|
|
|
surfaceModel.getDocument()
|
|
|
|
)[ 0 ] );
|
2015-08-03 14:25:03 +00:00
|
|
|
}
|
|
|
|
|
2023-07-11 17:10:33 +00:00
|
|
|
ve.ui.MWTransclusionContextItem.super.prototype.onEditButtonClick.apply( this, arguments );
|
2022-01-07 12:10:53 +00:00
|
|
|
|
2023-07-11 17:10:33 +00:00
|
|
|
this.context.getSurface().getDialogs().once( 'opening', function ( win, opening ) {
|
|
|
|
opening.then( function () {
|
|
|
|
contextItem.toggleLoadingVisualization( false );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
this.toggleLoadingVisualization( true );
|
2022-01-07 12:10:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @param {boolean} [isLoading=false]
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionContextItem.prototype.toggleLoadingVisualization = function ( isLoading ) {
|
|
|
|
this.editButton.setDisabled( isLoading );
|
|
|
|
if ( isLoading ) {
|
|
|
|
this.originalEditButtonLabel = this.editButton.getLabel();
|
|
|
|
this.editButton.setLabel( ve.msg( 'visualeditor-dialog-transclusion-contextitem-loading' ) );
|
|
|
|
} else if ( this.originalEditButtonLabel ) {
|
|
|
|
this.editButton.setLabel( this.originalEditButtonLabel );
|
|
|
|
}
|
2015-08-03 14:25:03 +00:00
|
|
|
};
|
|
|
|
|
2015-02-25 22:56:28 +00:00
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.ui.contextItemFactory.register( ve.ui.MWTransclusionContextItem );
|