2013-12-02 20:10:55 +00:00
|
|
|
/*!
|
2014-02-24 21:49:48 +00:00
|
|
|
* VisualEditor user interface MWParameterPage class.
|
2013-12-02 20:10:55 +00:00
|
|
|
*
|
2014-01-05 12:05:05 +00:00
|
|
|
* @copyright 2011-2014 VisualEditor Team and others; see AUTHORS.txt
|
2013-12-02 20:10:55 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MediaWiki transclusion dialog template page.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends OO.ui.PageLayout
|
|
|
|
*
|
|
|
|
* @constructor
|
2014-02-24 21:49:48 +00:00
|
|
|
* @param {ve.dm.MWParameterModel} parameter Template parameter
|
2013-12-02 20:10:55 +00:00
|
|
|
* @param {string} name Unique symbolic name of page
|
|
|
|
* @param {Object} [config] Configuration options
|
|
|
|
*/
|
2014-02-28 00:00:10 +00:00
|
|
|
ve.ui.MWParameterPage = function VeUiMWParameterPage( parameter, name, config ) {
|
2014-02-26 00:29:13 +00:00
|
|
|
var paramName = parameter.getName();
|
2014-02-12 21:45:37 +00:00
|
|
|
|
2013-12-02 20:10:55 +00:00
|
|
|
// Parent constructor
|
|
|
|
OO.ui.PageLayout.call( this, name, config );
|
|
|
|
|
|
|
|
// Properties
|
|
|
|
this.parameter = parameter;
|
2014-02-26 00:29:13 +00:00
|
|
|
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>' );
|
2014-01-22 20:13:59 +00:00
|
|
|
this.valueInput = new OO.ui.TextInputWidget( {
|
2013-12-02 20:10:55 +00:00
|
|
|
'$': this.$,
|
|
|
|
'multiline': true,
|
2014-02-20 20:07:18 +00:00
|
|
|
'autosize': true,
|
2014-02-26 00:29:13 +00:00
|
|
|
'placeholder': this.defaultValue
|
2013-12-02 20:10:55 +00:00
|
|
|
} )
|
|
|
|
.setValue( this.parameter.getValue() )
|
2014-02-26 00:29:13 +00:00
|
|
|
.connect( this, { 'change': 'onValueInputChange' } );
|
2014-01-17 14:24:12 +00:00
|
|
|
this.removeButton = new OO.ui.ButtonWidget( {
|
2013-12-02 20:10:55 +00:00
|
|
|
'$': this.$,
|
2014-01-17 14:24:12 +00:00
|
|
|
'frameless': true,
|
2013-12-06 20:24:36 +00:00
|
|
|
'icon': 'remove',
|
|
|
|
'title': ve.msg( 'visualeditor-dialog-transclusion-remove-param' ),
|
2014-02-26 00:29:13 +00:00
|
|
|
'tabIndex': -1
|
2013-12-02 20:10:55 +00:00
|
|
|
} )
|
|
|
|
.connect( this, { 'click': 'onRemoveButtonClick' } );
|
|
|
|
|
|
|
|
// TODO: Use spec.deprecation
|
|
|
|
// TODO: Use spec.type
|
|
|
|
|
2014-02-26 00:29:13 +00:00
|
|
|
// Events
|
|
|
|
this.$label.on( 'click', ve.bind( this.onLabelClick, this ) );
|
|
|
|
this.$description.on( 'click', ve.bind( this.onDescriptionClick, this ) );
|
|
|
|
|
2013-12-02 20:10:55 +00:00
|
|
|
// Initialization
|
2014-02-26 00:29:13 +00:00
|
|
|
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 );
|
2013-12-02 20:10:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2014-02-24 21:49:48 +00:00
|
|
|
OO.inheritClass( ve.ui.MWParameterPage, OO.ui.PageLayout );
|
2013-12-02 20:10:55 +00:00
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
2014-02-26 00:29:13 +00:00
|
|
|
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' );
|
|
|
|
};
|
|
|
|
|
2014-02-15 01:37:32 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2014-02-24 21:49:48 +00:00
|
|
|
ve.ui.MWParameterPage.prototype.setOutlineItem = function ( outlineItem ) {
|
2014-02-15 01:37:32 +00:00
|
|
|
// Parent method
|
|
|
|
OO.ui.PageLayout.prototype.setOutlineItem.call( this, outlineItem );
|
|
|
|
|
|
|
|
if ( this.outlineItem ) {
|
|
|
|
this.outlineItem
|
|
|
|
.setIcon( 'parameter' )
|
|
|
|
.setMovable( false )
|
2014-03-01 00:39:02 +00:00
|
|
|
.setRemovable( true )
|
2014-02-15 01:37:32 +00:00
|
|
|
.setLevel( 1 )
|
2014-02-26 00:29:13 +00:00
|
|
|
.setFlags( { 'empty': this.isEmpty() } )
|
2014-02-15 01:37:32 +00:00
|
|
|
.setLabel( this.spec.getParameterLabel( this.parameter.getName() ) );
|
|
|
|
|
|
|
|
if ( this.parameter.isRequired() ) {
|
|
|
|
this.outlineItem
|
|
|
|
.setIndicator( 'required' )
|
2014-02-26 00:29:13 +00:00
|
|
|
.setIndicatorTitle(
|
|
|
|
ve.msg( 'visualeditor-dialog-transclusion-required-parameter' )
|
|
|
|
);
|
2014-02-15 01:37:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|