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
|
|
|
*
|
2015-01-08 23:54:03 +00:00
|
|
|
* @copyright 2011-2015 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 ) {
|
2015-03-04 23:31:05 +00:00
|
|
|
var placeholder = null,
|
|
|
|
paramName = parameter.getName(),
|
2015-01-31 00:41:37 +00:00
|
|
|
page = this;
|
2014-02-12 21:45:37 +00:00
|
|
|
|
2014-04-25 23:50:21 +00:00
|
|
|
// Configuration initialization
|
|
|
|
config = ve.extendObject( {
|
2014-08-22 20:50:48 +00:00
|
|
|
scrollable: false
|
2014-04-25 23:50:21 +00:00
|
|
|
}, 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();
|
2014-10-26 15:22:09 +00:00
|
|
|
this.defaultValue = parameter.getDefaultValue();
|
2015-03-04 23:31:05 +00:00
|
|
|
this.exampleValue = parameter.getExampleValue();
|
2014-10-22 22:46:20 +00:00
|
|
|
|
2015-04-09 23:47:15 +00:00
|
|
|
this.$info = $( '<div>' );
|
|
|
|
this.$actions = $( '<div>' );
|
|
|
|
this.$labelElement = $( '<div>' );
|
|
|
|
this.$field = $( '<div>' );
|
|
|
|
this.$more = $( '<div>' );
|
|
|
|
this.$description = $( '<div>' );
|
2015-03-04 23:31:05 +00:00
|
|
|
if ( this.defaultValue ) {
|
|
|
|
placeholder = ve.msg( 'visualeditor-dialog-transclusion-param-default', this.defaultValue );
|
|
|
|
} else if ( this.exampleValue ) {
|
|
|
|
placeholder = ve.msg( 'visualeditor-dialog-transclusion-param-example', this.exampleValue );
|
|
|
|
}
|
2014-01-22 20:13:59 +00:00
|
|
|
this.valueInput = new OO.ui.TextInputWidget( {
|
2014-08-22 20:50:48 +00:00
|
|
|
multiline: true,
|
|
|
|
autosize: true,
|
2015-03-04 23:31:05 +00:00
|
|
|
placeholder: placeholder
|
2014-06-26 10:41:18 +00:00
|
|
|
} )
|
2014-10-22 22:46:20 +00:00
|
|
|
.setValue( this.parameter.getValue() )
|
2014-08-22 20:50:48 +00:00
|
|
|
.connect( this, { change: 'onValueInputChange' } );
|
2014-06-26 10:41:18 +00:00
|
|
|
|
2014-06-03 19:38:09 +00:00
|
|
|
if ( this.parameter.isRequired() ) {
|
2014-10-17 16:54:16 +00:00
|
|
|
this.valueInput.$input
|
|
|
|
.prop( 'required', true )
|
|
|
|
.on( 'blur', function () {
|
|
|
|
page.valueInput.setValidation( 'non-empty' );
|
|
|
|
page.valueInput.setValidityFlag();
|
|
|
|
} );
|
2014-06-03 19:38:09 +00:00
|
|
|
}
|
|
|
|
|
2014-01-17 14:24:12 +00:00
|
|
|
this.removeButton = new OO.ui.ButtonWidget( {
|
2014-08-22 20:50:48 +00:00
|
|
|
framed: false,
|
|
|
|
icon: 'remove',
|
|
|
|
title: ve.msg( 'visualeditor-dialog-transclusion-remove-param' ),
|
2014-12-09 22:28:40 +00:00
|
|
|
flags: [ 'destructive' ],
|
2014-08-22 20:50:48 +00:00
|
|
|
classes: [ 've-ui-mwParameterPage-removeButton' ]
|
2014-06-26 10:41:18 +00:00
|
|
|
} )
|
2014-08-14 20:26:51 +00:00
|
|
|
.connect( this, { click: 'onRemoveButtonClick' } )
|
|
|
|
.toggle( !this.parameter.isRequired() );
|
2014-06-26 10:41:18 +00:00
|
|
|
|
2014-04-25 23:50:21 +00:00
|
|
|
this.infoButton = new OO.ui.PopupButtonWidget( {
|
2014-08-22 20:50:48 +00:00
|
|
|
framed: false,
|
|
|
|
icon: 'info',
|
|
|
|
title: ve.msg( 'visualeditor-dialog-transclusion-param-info' ),
|
|
|
|
classes: [ 've-ui-mwParameterPage-infoButton' ]
|
2014-06-26 10:41:18 +00:00
|
|
|
} );
|
|
|
|
|
2014-03-04 22:56:14 +00:00
|
|
|
this.addButton = new OO.ui.ButtonWidget( {
|
2014-08-22 20:50:48 +00:00
|
|
|
framed: false,
|
|
|
|
icon: 'parameter',
|
|
|
|
label: ve.msg( 'visualeditor-dialog-transclusion-add-param' ),
|
|
|
|
tabIndex: -1
|
2014-06-26 10:41:18 +00:00
|
|
|
} )
|
2014-08-22 20:50:48 +00:00
|
|
|
.connect( this, { click: 'onAddButtonFocus' } );
|
2014-06-26 10:41:18 +00:00
|
|
|
|
2014-04-25 23:50:21 +00:00
|
|
|
this.statusIndicator = new OO.ui.IndicatorWidget( {
|
2014-08-22 20:50:48 +00:00
|
|
|
classes: [ 've-ui-mwParameterPage-statusIndicator' ]
|
2014-04-25 23:50:21 +00:00
|
|
|
} );
|
2013-12-02 20:10:55 +00:00
|
|
|
|
|
|
|
// TODO: Use spec.type
|
|
|
|
|
2014-02-26 00:29:13 +00:00
|
|
|
// Events
|
2014-09-04 21:00:27 +00:00
|
|
|
this.$labelElement.on( 'click', this.onLabelClick.bind( this ) );
|
2014-02-26 00:29:13 +00:00
|
|
|
|
2013-12-02 20:10:55 +00:00
|
|
|
// Initialization
|
2014-04-25 23:50:21 +00:00
|
|
|
this.$info
|
|
|
|
.addClass( 've-ui-mwParameterPage-info' )
|
2014-09-04 21:00:27 +00:00
|
|
|
.append( this.$labelElement, this.statusIndicator.$element );
|
2014-04-25 23:50:21 +00:00
|
|
|
this.$actions
|
|
|
|
.addClass( 've-ui-mwParameterPage-actions' )
|
|
|
|
.append( this.infoButton.$element, this.removeButton.$element );
|
2014-09-04 21:00:27 +00:00
|
|
|
this.$labelElement
|
2014-02-26 00:29:13 +00:00
|
|
|
.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' )
|
2014-07-21 21:06:54 +00:00
|
|
|
.append( this.addButton.$element )
|
|
|
|
.focus( this.onAddButtonFocus.bind( this ) );
|
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' )
|
2015-04-09 23:47:15 +00:00
|
|
|
.append( $( '<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(
|
2015-04-09 23:47:15 +00:00
|
|
|
$( '<p>' )
|
2014-04-25 23:50:21 +00:00
|
|
|
.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(
|
2015-04-09 23:47:15 +00:00
|
|
|
$( '<p>' )
|
2014-04-25 23:50:21 +00:00
|
|
|
.addClass( 've-ui-mwParameterPage-description-deprecated' )
|
|
|
|
.text(
|
|
|
|
ve.msg(
|
|
|
|
'visualeditor-dialog-transclusion-deprecated-parameter-description',
|
|
|
|
this.spec.getParameterDeprecationDescription( paramName )
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2015-03-04 23:31:05 +00:00
|
|
|
|
|
|
|
if ( this.defaultValue ) {
|
|
|
|
this.$description.append(
|
2015-04-09 23:47:15 +00:00
|
|
|
$( '<p>' )
|
2015-03-04 23:31:05 +00:00
|
|
|
.addClass( 've-ui-mwParameterPage-description-default' )
|
|
|
|
.text(
|
|
|
|
ve.msg( 'visualeditor-dialog-transclusion-param-default', this.defaultValue )
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( this.exampleValue ) {
|
|
|
|
this.$description.append(
|
2015-04-09 23:47:15 +00:00
|
|
|
$( '<p>' )
|
2015-03-04 23:31:05 +00:00
|
|
|
.addClass( 've-ui-mwParameterPage-description-example' )
|
|
|
|
.text(
|
|
|
|
ve.msg( 'visualeditor-dialog-transclusion-param-example', this.exampleValue )
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
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 ) {
|
2014-08-22 20:50:48 +00:00
|
|
|
this.outlineItem.setFlags( { empty: this.isEmpty() } );
|
2014-02-26 00:29:13 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ve.ui.MWParameterPage.prototype.onRemoveButtonClick = function () {
|
|
|
|
this.parameter.remove();
|
|
|
|
};
|
|
|
|
|
2014-07-21 21:06:54 +00:00
|
|
|
ve.ui.MWParameterPage.prototype.onAddButtonFocus = function () {
|
2014-03-04 22:56:14 +00:00
|
|
|
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-08-22 20:50:48 +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
|
|
|
}
|
|
|
|
};
|