mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-12-01 17:36:35 +00:00
cb5a9b948c
* Show label, input and remove control on a single line * Right align label to conserve vertical space without sacrificing fill-out speed * Show description in gray text below the input * Show remove button only when page is active * Make description lighter when page is innactive Change-Id: Iaa09f3bf909ccd415de7af8f428495fef3046893
138 lines
3.8 KiB
JavaScript
138 lines
3.8 KiB
JavaScript
/*!
|
|
* VisualEditor user interface MWParameterPage class.
|
|
*
|
|
* @copyright 2011-2014 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* MediaWiki transclusion dialog template page.
|
|
*
|
|
* @class
|
|
* @extends OO.ui.PageLayout
|
|
*
|
|
* @constructor
|
|
* @param {ve.dm.MWParameterModel} parameter Template parameter
|
|
* @param {string} name Unique symbolic name of page
|
|
* @param {Object} [config] Configuration options
|
|
*/
|
|
ve.ui.MWParameterPage = function VeUiMWParameter( parameter, name, config ) {
|
|
var paramName = parameter.getName();
|
|
|
|
// Parent constructor
|
|
OO.ui.PageLayout.call( this, name, config );
|
|
|
|
// Properties
|
|
this.parameter = parameter;
|
|
this.spec = parameter.getTemplate().getSpec();
|
|
this.defaultValue = this.spec.getParameterDefaultValue( paramName );
|
|
this.$label = this.$( '<div>' );
|
|
this.$field = this.$( '<div>' );
|
|
this.$actions = this.$( '<div>' );
|
|
this.$info = this.$( '<div>' );
|
|
this.$description = this.$( '<div>' );
|
|
this.valueInput = new OO.ui.TextInputWidget( {
|
|
'$': this.$,
|
|
'multiline': true,
|
|
'autosize': true,
|
|
'placeholder': this.defaultValue
|
|
} )
|
|
.setValue( this.parameter.getValue() )
|
|
.connect( this, { 'change': 'onValueInputChange' } );
|
|
this.removeButton = new OO.ui.ButtonWidget( {
|
|
'$': this.$,
|
|
'frameless': true,
|
|
'icon': 'remove',
|
|
'title': ve.msg( 'visualeditor-dialog-transclusion-remove-param' ),
|
|
'tabIndex': -1
|
|
} )
|
|
.connect( this, { 'click': 'onRemoveButtonClick' } );
|
|
|
|
// TODO: Use spec.required
|
|
// TODO: Use spec.deprecation
|
|
// TODO: Use spec.type
|
|
|
|
// Events
|
|
this.$label.on( 'click', ve.bind( this.onLabelClick, this ) );
|
|
this.$description.on( 'click', ve.bind( this.onDescriptionClick, this ) );
|
|
|
|
// Initialization
|
|
this.$label
|
|
.addClass( 've-ui-mwParameterPage-label' )
|
|
.text( this.spec.getParameterLabel( paramName ) );
|
|
this.$actions
|
|
.addClass( 've-ui-mwParameterPage-actions' )
|
|
.append( this.removeButton.$element );
|
|
this.$description
|
|
.addClass( 've-ui-mwParameterPage-description' )
|
|
.text( this.spec.getParameterDescription( paramName ) || '' );
|
|
this.$info
|
|
.addClass( 've-ui-mwParameterPage-info' )
|
|
.append( this.$description );
|
|
this.$field
|
|
.addClass( 've-ui-mwParameterPage-field' )
|
|
.append( this.valueInput.$element, this.$actions, this.$info );
|
|
this.$element
|
|
.addClass( 've-ui-mwParameterPage' )
|
|
.append( this.$label, this.$field );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
OO.inheritClass( ve.ui.MWParameterPage, OO.ui.PageLayout );
|
|
|
|
/* Methods */
|
|
|
|
ve.ui.MWParameterPage.prototype.isEmpty = function () {
|
|
return this.valueInput.getValue() === '' && this.defaultValue === '';
|
|
};
|
|
|
|
ve.ui.MWParameterPage.prototype.onValueInputChange = function () {
|
|
var value = this.valueInput.getValue();
|
|
|
|
this.parameter.setValue( value );
|
|
|
|
if ( this.outlineItem ) {
|
|
this.outlineItem.setFlags( { 'empty': this.isEmpty() } );
|
|
}
|
|
};
|
|
|
|
ve.ui.MWParameterPage.prototype.onRemoveButtonClick = function () {
|
|
this.parameter.remove();
|
|
};
|
|
|
|
ve.ui.MWParameterPage.prototype.onLabelClick = function () {
|
|
this.valueInput.simulateLabelClick();
|
|
};
|
|
|
|
ve.ui.MWParameterPage.prototype.onDescriptionClick = function () {
|
|
this.valueInput.simulateLabelClick();
|
|
this.$description.toggleClass( 've-ui-mwParameterPage-description-all' );
|
|
};
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
ve.ui.MWParameterPage.prototype.setOutlineItem = function ( outlineItem ) {
|
|
// Parent method
|
|
OO.ui.PageLayout.prototype.setOutlineItem.call( this, outlineItem );
|
|
|
|
if ( this.outlineItem ) {
|
|
this.outlineItem
|
|
.setIcon( 'parameter' )
|
|
.setMovable( false )
|
|
.setRemovable( true )
|
|
.setLevel( 1 )
|
|
.setFlags( { 'empty': this.isEmpty() } )
|
|
.setLabel( this.spec.getParameterLabel( this.parameter.getName() ) );
|
|
|
|
if ( this.parameter.isRequired() ) {
|
|
this.outlineItem
|
|
.setIndicator( 'required' )
|
|
.setIndicatorTitle(
|
|
ve.msg( 'visualeditor-dialog-transclusion-required-parameter' )
|
|
);
|
|
}
|
|
}
|
|
};
|