2021-08-06 11:56:40 +00:00
|
|
|
/**
|
|
|
|
* 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
|
2021-08-23 13:41:07 +00:00
|
|
|
ve.ui.MWAddParameterPage.super.call( this, name, ve.extendObject( {
|
|
|
|
scrollable: false
|
|
|
|
}, config ) );
|
2021-08-06 11:56:40 +00:00
|
|
|
|
|
|
|
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
|
2021-08-31 10:18:19 +00:00
|
|
|
this.paramInputField = new OO.ui.TextInputWidget( {
|
|
|
|
placeholder: ve.msg( 'visualeditor-dialog-transclusion-add-param-placeholder' )
|
|
|
|
} )
|
|
|
|
.connect( this, { enter: 'onParameterInput' } );
|
2021-08-06 11:56:40 +00:00
|
|
|
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' ] }
|
|
|
|
);
|
|
|
|
|
2021-09-01 13:46:25 +00:00
|
|
|
var link = this.template.getTitle() || this.template.getTarget().wt;
|
2021-08-31 10:18:19 +00:00
|
|
|
var $helpText = mw.message(
|
|
|
|
'visualeditor-dialog-transclusion-add-param-help',
|
2021-09-01 13:46:25 +00:00
|
|
|
link
|
2021-08-31 10:18:19 +00:00
|
|
|
).parseDom();
|
2021-09-01 13:46:25 +00:00
|
|
|
ve.init.platform.linkCache.styleElement( link, $helpText );
|
2021-08-06 11:56:40 +00:00
|
|
|
this.addParameterFieldset = new OO.ui.FieldsetLayout( {
|
|
|
|
label: this.addParameterInputHeader.$element,
|
|
|
|
helpInline: true,
|
2021-08-31 10:18:19 +00:00
|
|
|
help: $helpText,
|
2021-08-06 11:56:40 +00:00
|
|
|
classes: [ 've-ui-mwTransclusionDialog-addParameterFieldset' ],
|
|
|
|
$content: this.addParameterInputField.$element
|
|
|
|
} );
|
|
|
|
|
2021-08-31 10:18:19 +00:00
|
|
|
ve.targetLinksToNewWindow( this.addParameterFieldset.$element[ 0 ] );
|
|
|
|
|
2021-08-06 11:56:40 +00:00
|
|
|
// 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.addParameterInputHeader.setIcon( this.isExpanded ? 'subtract' : 'add' );
|
|
|
|
this.addParameterFieldset.$element.toggleClass(
|
|
|
|
've-ui-mwTransclusionDialog-addParameterFieldset-collapsed',
|
|
|
|
!this.isExpanded
|
|
|
|
);
|
2021-08-30 15:03:30 +00:00
|
|
|
if ( this.isExpanded ) {
|
|
|
|
this.paramInputField.focus();
|
|
|
|
}
|
2021-08-06 11:56:40 +00:00
|
|
|
};
|
2021-08-27 16:22:37 +00:00
|
|
|
|
|
|
|
ve.ui.MWAddParameterPage.prototype.setOutlineItem = function () {
|
|
|
|
// Parent method
|
|
|
|
ve.ui.MWParameterPage.super.prototype.setOutlineItem.apply( this, arguments );
|
|
|
|
|
|
|
|
if ( this.outlineItem ) {
|
|
|
|
// This page should not be shown in the (BookletLayout-based) sidebar
|
2021-08-30 10:58:32 +00:00
|
|
|
this.outlineItem.$element.empty().removeAttr( 'class' );
|
2021-08-27 16:22:37 +00:00
|
|
|
}
|
|
|
|
};
|