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-24 21:49:48 +00:00
|
|
|
ve.ui.MWParameterPage = function VeUiMWParameter( parameter, name, config ) {
|
2014-02-12 21:45:37 +00:00
|
|
|
var spec = parameter.getTemplate().getSpec();
|
|
|
|
|
2013-12-02 20:10:55 +00:00
|
|
|
// Parent constructor
|
|
|
|
OO.ui.PageLayout.call( this, name, config );
|
|
|
|
|
|
|
|
// Properties
|
|
|
|
this.parameter = parameter;
|
2014-02-12 21:45:37 +00:00
|
|
|
this.spec = spec;
|
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,
|
2013-12-02 20:10:55 +00:00
|
|
|
'classes': [ 've-ui-mwTransclusionDialog-input' ]
|
|
|
|
} )
|
|
|
|
.setValue( this.parameter.getValue() )
|
|
|
|
.connect( this, { 'change': 'onTextInputChange' } );
|
2014-01-22 20:13:59 +00:00
|
|
|
this.valueField = new OO.ui.FieldLayout( this.valueInput, {
|
2013-12-02 20:10:55 +00:00
|
|
|
'$': this.$,
|
2014-01-22 20:13:59 +00:00
|
|
|
'align': 'top',
|
2013-12-02 20:10:55 +00:00
|
|
|
'label': this.spec.getParameterDescription( this.parameter.getName() ) || ''
|
|
|
|
} );
|
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' ),
|
2013-12-02 20:10:55 +00:00
|
|
|
'flags': ['destructive'],
|
|
|
|
'classes': [ 've-ui-mwTransclusionDialog-removeButton' ]
|
|
|
|
} )
|
|
|
|
.connect( this, { 'click': 'onRemoveButtonClick' } );
|
|
|
|
this.valueFieldset = new OO.ui.FieldsetLayout( {
|
|
|
|
'$': this.$,
|
|
|
|
'label': this.spec.getParameterLabel( this.parameter.getName() ),
|
|
|
|
'icon': 'parameter',
|
2014-01-22 20:13:59 +00:00
|
|
|
'items': [ this.valueInput ]
|
2013-12-02 20:10:55 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
// TODO: Use spec.required
|
|
|
|
// TODO: Use spec.deprecation
|
|
|
|
// TODO: Use spec.default
|
|
|
|
// TODO: Use spec.type
|
|
|
|
|
|
|
|
// Initialization
|
|
|
|
this.$element.append( this.valueFieldset.$element, this.removeButton.$element );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* 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-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 )
|
|
|
|
.setLevel( 1 )
|
|
|
|
.setLabel( this.spec.getParameterLabel( this.parameter.getName() ) );
|
|
|
|
|
|
|
|
if ( this.parameter.isRequired() ) {
|
|
|
|
this.outlineItem
|
|
|
|
.setIndicator( 'required' )
|
|
|
|
.setIndicatorTitle( ve.msg( 'visualeditor-dialog-transclusion-required-parameter' ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-02-24 21:49:48 +00:00
|
|
|
ve.ui.MWParameterPage.prototype.onTextInputChange = function () {
|
2014-01-22 20:13:59 +00:00
|
|
|
this.parameter.setValue( this.valueInput.getValue() );
|
2013-12-02 20:10:55 +00:00
|
|
|
};
|
|
|
|
|
2014-02-24 21:49:48 +00:00
|
|
|
ve.ui.MWParameterPage.prototype.onRemoveButtonClick = function () {
|
2013-12-02 20:10:55 +00:00
|
|
|
this.parameter.remove();
|
|
|
|
};
|