mediawiki-extensions-Visual.../modules/ve-mw/ui/pages/ve.ui.MWAddParameterPage.js
Thiemo Kreuz c8536f1a71 Remove unnecessary title parsing from template related code
There are 2 situations:

1. Either the template name is used in a [[…]] link. In this case
we must provide the namespace. MWTemplateModel.getTitle() does
this. However, it's not a mw.Title object and therefor not really
guaranteed to be a valid title. This is fine. The worst thing
that can happen is that the link points to an error message.
But this should be entirely unreachable anyway.

2. Some messages want to display the name of the template.
Ideally without the namespace. That's what
MWTemplateSpecModel.getLabel() is for. Again this is not
guaranteed to be a valid mw.Title. But it doesn't need to. It's
only used as a label.

Change-Id: I03d0481201620a2f5c444ee32b656bcaade98aac
2021-08-26 15:58:15 +02:00

108 lines
3.3 KiB
JavaScript

/**
* Placeholder page for a currently unnamed parameter. Represented as a unnamed
* {@see ve.dm.MWParameterModel} in the corresponding {@see ve.dm.MWTemplateModel}.
*
* @class
* @extends OO.ui.PageLayout
*
* @constructor
* @param {ve.dm.MWParameterModel} parameter Reference to a placeholder parameter with an empty
* name, as well as to the template the parameter belongs to
* @param {string} name Unique symbolic name of page
* @param {Object} [config] Configuration options
* @cfg {jQuery} [$overlay] Overlay to render dropdowns in
*/
ve.ui.MWAddParameterPage = function VeUiMWAddParameterPage( parameter, name, config ) {
// Parent constructor
ve.ui.MWAddParameterPage.super.call( this, name, ve.extendObject( {
scrollable: false
}, config ) );
this.template = parameter.getTemplate();
this.isExpanded = false;
// Header button to expand
this.addParameterInputHeader = new OO.ui.ButtonWidget( {
label: ve.msg( 'visualeditor-dialog-transclusion-add-undocumented-param' ),
icon: 'add',
framed: false,
inline: true,
classes: [ 've-ui-mwTransclusionDialog-addParameterFieldset-header' ]
} )
.connect( this, { click: 'togglePlaceholder' } );
// Input field and button
this.paramInputField = new OO.ui.TextInputWidget().connect( this, { enter: 'onParameterInput' } );
var saveButton = new OO.ui.ButtonWidget( {
label: ve.msg( 'visualeditor-dialog-transclusion-add-param-save' ),
flags: [ 'primary', 'progressive' ]
} )
.connect( this, { click: 'onParameterInput' } );
this.addParameterInputField = new OO.ui.ActionFieldLayout(
this.paramInputField,
saveButton,
{ classes: [ 've-ui-mwTransclusionDialog-addParameterFieldset-input' ] }
);
this.addParameterFieldset = new OO.ui.FieldsetLayout( {
label: this.addParameterInputHeader.$element,
helpInline: true,
help: mw.message(
'visualeditor-dialog-transclusion-add-param-help',
this.template.getTitle() || this.template.getTarget().wt
).parseDom(),
classes: [ 've-ui-mwTransclusionDialog-addParameterFieldset' ],
$content: this.addParameterInputField.$element
} );
// Init visibility
this.togglePlaceholder( false );
// Initialization
this.$element
.addClass( 've-ui-mwParameterPlaceholderPage' )
.append( this.addParameterFieldset.$element );
};
/* Inheritance */
OO.inheritClass( ve.ui.MWAddParameterPage, OO.ui.PageLayout );
/* Methods */
ve.ui.MWAddParameterPage.prototype.onParameterInput = function () {
var name = this.paramInputField.getValue().trim();
this.paramInputField.setValue( '' );
if ( !name || this.template.hasParameter( name ) ) {
return;
}
if ( this.template.getSpec().isParameterDocumented( name ) ) {
// TODO: This special case needs a proper error message for the user
return;
}
this.template.addParameter( new ve.dm.MWParameterModel( this.template, name ) );
ve.track( 'activity.transclusion', {
action: 'add-unknown-parameter'
} );
};
/**
* @private
* @param {boolean} [expand]
*/
ve.ui.MWAddParameterPage.prototype.togglePlaceholder = function ( expand ) {
this.isExpanded = expand === undefined ? !this.isExpanded : !!expand;
this.addParameterInputField.toggle( this.isExpanded );
this.addParameterInputHeader.setIcon( this.isExpanded ? 'subtract' : 'add' );
this.addParameterFieldset.$element.toggleClass(
've-ui-mwTransclusionDialog-addParameterFieldset-collapsed',
!this.isExpanded
);
};