/*! * VisualEditor user interface MWParameterPage class. * * @copyright 2011-2015 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 VeUiMWParameterPage( parameter, name, config ) { var placeholder = null, paramName = parameter.getName(); // Configuration initialization config = ve.extendObject( { scrollable: false }, config ); // Parent constructor OO.ui.PageLayout.call( this, name, config ); // Properties this.parameter = parameter; this.spec = parameter.getTemplate().getSpec(); this.defaultValue = parameter.getDefaultValue(); this.exampleValue = parameter.getExampleValue(); this.$info = $( '
' ).text( this.spec.getParameterDescription( paramName ) || '' ) ); if ( this.parameter.isRequired() ) { this.statusIndicator .setIndicator( 'required' ) .setIndicatorTitle( ve.msg( 'visualeditor-dialog-transclusion-required-parameter' ) ); this.$description.append( $( '
' ) .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( $( '
' ) .addClass( 've-ui-mwParameterPage-description-deprecated' ) .text( ve.msg( 'visualeditor-dialog-transclusion-deprecated-parameter-description', this.spec.getParameterDeprecationDescription( paramName ) ) ) ); } if ( this.defaultValue ) { this.$description.append( $( '
' ) .addClass( 've-ui-mwParameterPage-description-default' ) .text( ve.msg( 'visualeditor-dialog-transclusion-param-default', this.defaultValue ) ) ); } if ( this.exampleValue ) { this.$description.append( $( '
' ) .addClass( 've-ui-mwParameterPage-description-example' ) .text( ve.msg( 'visualeditor-dialog-transclusion-param-example', this.exampleValue ) ) ); } if ( this.$description.text().trim() === '' ) { this.infoButton .setDisabled( true ) .setTitle( ve.msg( 'visualeditor-dialog-transclusion-param-info-missing' ) ); } else { this.infoButton.getPopup().$body.append( this.$description ); } }; /* Inheritance */ OO.inheritClass( ve.ui.MWParameterPage, OO.ui.PageLayout ); /* Methods */ /** * Check if the parameter is empty * * @return {boolean} The parameter is empty */ ve.ui.MWParameterPage.prototype.isEmpty = function () { return this.valueInput.getValue() === '' && this.defaultValue === ''; }; /** * Handle change events from the value input * * @param {string} value Value */ ve.ui.MWParameterPage.prototype.onValueInputChange = function () { var value = this.valueInput.getValue(); this.parameter.setValue( value ); if ( this.outlineItem ) { this.outlineItem.setFlags( { empty: this.isEmpty() } ); } }; /** * Handle click events from the remove button */ ve.ui.MWParameterPage.prototype.onRemoveButtonClick = function () { this.parameter.remove(); }; /** * Handle click events from the add button */ ve.ui.MWParameterPage.prototype.onAddButtonFocus = function () { var template = this.parameter.getTemplate(); template.addParameter( new ve.dm.MWParameterModel( template ) ); }; /** * Handle click events from the label element * * @param {jQuery.Event} e Click event */ ve.ui.MWParameterPage.prototype.onLabelClick = function () { this.valueInput.simulateLabelClick(); }; /** * @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' ) ); } if ( this.parameter.isDeprecated() ) { this.outlineItem .setIndicator( 'alert' ) .setIndicatorTitle( ve.msg( 'visualeditor-dialog-transclusion-deprecated-parameter' ) ); } } }; /** * @inheritdoc */ ve.ui.MWParameterPage.prototype.focus = function () { this.valueInput.focus(); };