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
|
|
|
|
2014-04-25 23:50:21 +00:00
|
|
|
// Configuration initialization
|
|
|
|
config = ve.extendObject( {
|
|
|
|
'scrollable': false
|
|
|
|
}, config );
|
|
|
|
|
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 );
|
2014-04-25 23:50:21 +00:00
|
|
|
this.$info = this.$( '<div>' );
|
|
|
|
this.$actions = this.$( '<div>' );
|
2014-02-26 00:29:13 +00:00
|
|
|
this.$label = this.$( '<div>' );
|
|
|
|
this.$field = this.$( '<div>' );
|
2014-03-04 22:56:14 +00:00
|
|
|
this.$more = this.$( '<div>' );
|
2014-04-25 23:50:21 +00:00
|
|
|
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-04-25 23:50:21 +00:00
|
|
|
'tabIndex': -1,
|
|
|
|
'classes': [ 've-ui-mwParameterPage-removeButton' ]
|
2013-12-02 20:10:55 +00:00
|
|
|
} )
|
|
|
|
.connect( this, { 'click': 'onRemoveButtonClick' } );
|
2014-04-25 23:50:21 +00:00
|
|
|
this.infoButton = new OO.ui.PopupButtonWidget( {
|
|
|
|
'$': this.$,
|
|
|
|
'frameless': true,
|
|
|
|
'icon': 'info',
|
|
|
|
'title': ve.msg( 'visualeditor-dialog-transclusion-param-info' ),
|
|
|
|
'tabIndex': -1,
|
|
|
|
'classes': [ 've-ui-mwParameterPage-infoButton' ]
|
|
|
|
} );
|
2014-03-04 22:56:14 +00:00
|
|
|
this.addButton = new OO.ui.ButtonWidget( {
|
|
|
|
'$': this.$,
|
|
|
|
'frameless': true,
|
|
|
|
'icon': 'parameter',
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-transclusion-add-param' ),
|
|
|
|
'tabIndex': -1
|
|
|
|
} )
|
|
|
|
.connect( this, { 'click': 'onAddButtonClick' } );
|
2014-04-25 23:50:21 +00:00
|
|
|
this.statusIndicator = new OO.ui.IndicatorWidget( {
|
|
|
|
'$': this.$,
|
|
|
|
'classes': [ 've-ui-mwParameterPage-statusIndicator' ]
|
|
|
|
} );
|
2013-12-02 20:10:55 +00:00
|
|
|
|
|
|
|
// 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-04-25 23:50:21 +00:00
|
|
|
this.$info
|
|
|
|
.addClass( 've-ui-mwParameterPage-info' )
|
|
|
|
.append( this.$label, this.statusIndicator.$element );
|
|
|
|
this.$actions
|
|
|
|
.addClass( 've-ui-mwParameterPage-actions' )
|
|
|
|
.append( this.infoButton.$element, this.removeButton.$element );
|
2014-02-26 00:29:13 +00:00
|
|
|
this.$label
|
|
|
|
.addClass( 've-ui-mwParameterPage-label' )
|
|
|
|
.text( this.spec.getParameterLabel( paramName ) );
|
|
|
|
this.$field
|
|
|
|
.addClass( 've-ui-mwParameterPage-field' )
|
2014-04-25 23:50:21 +00:00
|
|
|
.append(
|
|
|
|
this.valueInput.$element
|
|
|
|
);
|
2014-03-04 22:56:14 +00:00
|
|
|
this.$more
|
|
|
|
.addClass( 've-ui-mwParameterPage-more' )
|
|
|
|
.append( this.addButton.$element );
|
2014-02-26 00:29:13 +00:00
|
|
|
this.$element
|
|
|
|
.addClass( 've-ui-mwParameterPage' )
|
2014-04-25 23:50:21 +00:00
|
|
|
.append( this.$info, this.$actions, this.$field, this.$more );
|
|
|
|
this.$description
|
|
|
|
.addClass( 've-ui-mwParameterPage-description' )
|
|
|
|
.append( this.$( '<p>' ).text( this.spec.getParameterDescription( paramName ) || '' ) );
|
2014-03-06 22:00:43 +00:00
|
|
|
|
|
|
|
if ( this.parameter.isRequired() ) {
|
2014-04-25 23:50:21 +00:00
|
|
|
this.statusIndicator
|
2014-03-06 22:00:43 +00:00
|
|
|
.setIndicator( 'required' )
|
|
|
|
.setIndicatorTitle(
|
|
|
|
ve.msg( 'visualeditor-dialog-transclusion-required-parameter' )
|
|
|
|
);
|
2014-04-25 23:50:21 +00:00
|
|
|
this.$description.append(
|
|
|
|
this.$( '<p>' )
|
|
|
|
.addClass( 've-ui-mwParameterPage-description-required' )
|
|
|
|
.text(
|
|
|
|
ve.msg( 'visualeditor-dialog-transclusion-required-parameter-description' )
|
|
|
|
)
|
|
|
|
);
|
|
|
|
} else if ( this.parameter.isDeprecated() ) {
|
|
|
|
this.statusIndicator
|
|
|
|
.setIndicator( 'alert' )
|
|
|
|
.setIndicatorTitle(
|
|
|
|
ve.msg( 'visualeditor-dialog-transclusion-deprecated-parameter' )
|
|
|
|
);
|
|
|
|
this.$description.append(
|
|
|
|
this.$( '<p>' )
|
|
|
|
.addClass( 've-ui-mwParameterPage-description-deprecated' )
|
|
|
|
.text(
|
|
|
|
ve.msg(
|
|
|
|
'visualeditor-dialog-transclusion-deprecated-parameter-description',
|
|
|
|
this.spec.getParameterDeprecationDescription( paramName )
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2014-05-30 17:17:38 +00:00
|
|
|
if ( this.$description.text().trim() === '' ) {
|
2014-04-25 23:50:21 +00:00
|
|
|
this.infoButton
|
|
|
|
.setDisabled( true )
|
|
|
|
.setTitle(
|
|
|
|
ve.msg( 'visualeditor-dialog-transclusion-param-info-missing' )
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
this.infoButton.getPopup().$body.append( this.$description );
|
2014-03-06 22:00:43 +00:00
|
|
|
}
|
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();
|
|
|
|
};
|
|
|
|
|
2014-03-04 22:56:14 +00:00
|
|
|
ve.ui.MWParameterPage.prototype.onAddButtonClick = function () {
|
|
|
|
var template = this.parameter.getTemplate();
|
|
|
|
template.addParameter( new ve.dm.MWParameterModel( template ) );
|
|
|
|
};
|
|
|
|
|
2014-02-26 00:29:13 +00:00
|
|
|
ve.ui.MWParameterPage.prototype.onLabelClick = function () {
|
|
|
|
this.valueInput.simulateLabelClick();
|
|
|
|
};
|
|
|
|
|
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
|
|
|
}
|
2014-04-25 23:50:21 +00:00
|
|
|
if ( this.parameter.isDeprecated() ) {
|
|
|
|
this.outlineItem
|
|
|
|
.setIndicator( 'alert' )
|
|
|
|
.setIndicatorTitle(
|
|
|
|
ve.msg( 'visualeditor-dialog-transclusion-deprecated-parameter' )
|
|
|
|
);
|
|
|
|
}
|
2014-02-15 01:37:32 +00:00
|
|
|
}
|
|
|
|
};
|