2014-02-27 23:58:37 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor user interface MWParameterPlaceholderPage class.
|
|
|
|
*
|
2020-01-08 17:13:04 +00:00
|
|
|
* @copyright 2011-2020 VisualEditor Team and others; see AUTHORS.txt
|
2014-02-27 23:58:37 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MediaWiki transclusion dialog parameter placeholder page.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends OO.ui.PageLayout
|
|
|
|
*
|
|
|
|
* @constructor
|
2021-07-07 08:04:40 +00:00
|
|
|
* @param {ve.dm.MWParameterModel} parameter Reference to a placeholder parameter with an empty
|
|
|
|
* name, as well as to the template the parameter belongs to
|
2014-02-27 23:58:37 +00:00
|
|
|
* @param {string} name Unique symbolic name of page
|
|
|
|
* @param {Object} [config] Configuration options
|
2018-04-04 20:37:32 +00:00
|
|
|
* @cfg {jQuery} [$overlay] Overlay to render dropdowns in
|
2021-09-11 08:05:31 +00:00
|
|
|
* @cfg {boolean} [expandedParamList=false] If the {@see ve.ui.MWParameterSearchWidget} results
|
|
|
|
* should be initially expanded
|
2014-02-27 23:58:37 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWParameterPlaceholderPage = function VeUiMWParameterPlaceholderPage( parameter, name, config ) {
|
2021-07-15 08:49:06 +00:00
|
|
|
var veConfig = mw.config.get( 'wgVisualEditorConfig' );
|
|
|
|
|
2014-04-25 23:50:21 +00:00
|
|
|
// Configuration initialization
|
|
|
|
config = ve.extendObject( {
|
2014-08-22 20:50:48 +00:00
|
|
|
scrollable: false
|
2014-04-25 23:50:21 +00:00
|
|
|
}, config );
|
|
|
|
|
2014-02-27 23:58:37 +00:00
|
|
|
// Parent constructor
|
2016-08-22 21:44:59 +00:00
|
|
|
ve.ui.MWParameterPlaceholderPage.super.call( this, name, config );
|
2014-02-27 23:58:37 +00:00
|
|
|
|
|
|
|
// Properties
|
2021-06-07 14:03:48 +00:00
|
|
|
// TODO: the unique `name` seems to be a relic of when BookletLayout held
|
|
|
|
// the parameters in separate pages rather than in a StackLayout.
|
2015-04-13 21:30:41 +00:00
|
|
|
this.name = name;
|
2014-02-27 23:58:37 +00:00
|
|
|
this.parameter = parameter;
|
|
|
|
this.template = this.parameter.getTemplate();
|
2021-06-25 16:23:38 +00:00
|
|
|
this.addParameterSearch = new ve.ui.MWParameterSearchWidget( this.template, {
|
|
|
|
showAll: !!config.expandedParamList
|
|
|
|
} )
|
|
|
|
.connect( this, {
|
|
|
|
choose: 'onParameterChoose',
|
|
|
|
showAll: 'onParameterShowAll'
|
|
|
|
} );
|
2014-06-26 10:41:18 +00:00
|
|
|
|
2014-02-27 23:58:37 +00:00
|
|
|
this.addParameterFieldset = new OO.ui.FieldsetLayout( {
|
2014-08-22 20:50:48 +00:00
|
|
|
label: ve.msg( 'visualeditor-dialog-transclusion-add-param' ),
|
|
|
|
icon: 'parameter',
|
|
|
|
classes: [ 've-ui-mwTransclusionDialog-addParameterFieldset' ],
|
|
|
|
$content: this.addParameterSearch.$element
|
2014-02-27 23:58:37 +00:00
|
|
|
} );
|
|
|
|
|
2020-04-03 04:02:55 +00:00
|
|
|
this.addParameterFieldset.$element.attr( 'aria-label', ve.msg( 'visualeditor-dialog-transclusion-add-param' ) );
|
|
|
|
|
2014-02-27 23:58:37 +00:00
|
|
|
// Initialization
|
2014-02-28 01:18:49 +00:00
|
|
|
this.$element
|
|
|
|
.addClass( 've-ui-mwParameterPlaceholderPage' )
|
2021-07-15 08:49:06 +00:00
|
|
|
.append( this.addParameterFieldset.$element );
|
|
|
|
|
|
|
|
if ( !veConfig.transclusionDialogNewSidebar ) {
|
|
|
|
var removeButton = new OO.ui.ButtonWidget( {
|
|
|
|
framed: false,
|
|
|
|
icon: 'trash',
|
|
|
|
title: ve.msg( 'visualeditor-dialog-transclusion-remove-param' ),
|
|
|
|
flags: [ 'destructive' ],
|
|
|
|
classes: [ 've-ui-mwTransclusionDialog-removeButton' ]
|
|
|
|
} )
|
|
|
|
.connect( this, { click: 'onRemoveButtonClick' } );
|
|
|
|
|
|
|
|
this.$element.append( removeButton.$element );
|
|
|
|
}
|
2014-02-27 23:58:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.ui.MWParameterPlaceholderPage, OO.ui.PageLayout );
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
2021-06-25 16:23:38 +00:00
|
|
|
/**
|
|
|
|
* Respond to the parameter search widget showAll event
|
|
|
|
*
|
2021-09-17 09:29:50 +00:00
|
|
|
* @private
|
2021-06-25 16:23:38 +00:00
|
|
|
* @fires showAll
|
|
|
|
*/
|
|
|
|
ve.ui.MWParameterPlaceholderPage.prototype.onParameterShowAll = function () {
|
|
|
|
this.emit( 'showAll', this.name );
|
|
|
|
};
|
|
|
|
|
2014-02-27 23:58:37 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2021-09-15 10:10:56 +00:00
|
|
|
ve.ui.MWParameterPlaceholderPage.prototype.setupOutlineItem = function () {
|
|
|
|
this.outlineItem
|
|
|
|
.setIcon( 'parameter' )
|
|
|
|
.setMovable( false )
|
|
|
|
.setRemovable( true )
|
|
|
|
.setLevel( 1 )
|
|
|
|
.setFlags( [ 'placeholder' ] )
|
|
|
|
.setLabel( ve.msg( 'visualeditor-dialog-transclusion-add-param' ) );
|
2014-02-27 23:58:37 +00:00
|
|
|
};
|
|
|
|
|
2021-09-17 09:29:50 +00:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @param {string} name
|
2021-09-30 11:04:30 +00:00
|
|
|
* @fires focusTemplateParameterById
|
2021-09-17 09:29:50 +00:00
|
|
|
*/
|
2015-07-24 18:05:22 +00:00
|
|
|
ve.ui.MWParameterPlaceholderPage.prototype.onParameterChoose = function ( name ) {
|
2021-08-05 09:08:34 +00:00
|
|
|
this.addParameterSearch.query.setValue( '' );
|
|
|
|
|
|
|
|
if ( !name || this.template.hasParameter( name ) ) {
|
2021-06-04 10:49:53 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-11-25 12:44:24 +00:00
|
|
|
|
2021-06-04 10:49:53 +00:00
|
|
|
// Note that every parameter is known after it is added
|
2021-08-05 09:08:34 +00:00
|
|
|
var knownBefore = this.template.getSpec().isKnownParameterOrAlias( name );
|
2020-11-25 12:44:24 +00:00
|
|
|
|
2021-09-10 14:20:51 +00:00
|
|
|
var param = new ve.dm.MWParameterModel( this.template, name );
|
|
|
|
this.template.addParameter( param );
|
2021-09-07 15:53:37 +00:00
|
|
|
this.emit( 'focusTemplateParameterById', param.getId() );
|
2021-06-04 10:49:53 +00:00
|
|
|
|
|
|
|
ve.track( 'activity.transclusion', {
|
|
|
|
action: knownBefore ? 'add-known-parameter' : 'add-unknown-parameter'
|
|
|
|
} );
|
2014-02-27 23:58:37 +00:00
|
|
|
};
|
|
|
|
|
2021-09-17 09:29:50 +00:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
2014-02-27 23:58:37 +00:00
|
|
|
ve.ui.MWParameterPlaceholderPage.prototype.onRemoveButtonClick = function () {
|
|
|
|
this.parameter.remove();
|
|
|
|
};
|