2013-06-11 19:16:04 +00:00
|
|
|
/*!
|
2014-02-24 21:49:48 +00:00
|
|
|
* VisualEditor DataModel MWParameterModel class.
|
2013-06-11 19:16:04 +00:00
|
|
|
*
|
2020-01-08 17:13:04 +00:00
|
|
|
* @copyright 2011-2020 VisualEditor Team and others; see AUTHORS.txt
|
2013-06-11 19:16:04 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2021-06-03 16:25:15 +00:00
|
|
|
* Represents a parameter that's part of a template invocation, centered around the parameter's
|
|
|
|
* value. Holds a reference to the specification of the template and the parameter as it is
|
|
|
|
* documented via TemplateData. Meant to be a sub-element of a {@see ve.dm.MWTemplateModel}, which
|
|
|
|
* is a sub-element of a {@see ve.dm.MWTransclusionModel}.
|
2013-06-11 19:16:04 +00:00
|
|
|
*
|
|
|
|
* @class
|
2013-12-09 19:05:57 +00:00
|
|
|
* @mixins OO.EventEmitter
|
2013-06-11 19:16:04 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {ve.dm.MWTemplateModel} template Template
|
2014-03-04 22:56:14 +00:00
|
|
|
* @param {string} [name=''] Parameter name
|
|
|
|
* @param {string} [value=''] Parameter value
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
2014-02-24 21:49:48 +00:00
|
|
|
ve.dm.MWParameterModel = function VeDmMWParameterModel( template, name, value ) {
|
2013-12-09 19:05:57 +00:00
|
|
|
// Mixin constructors
|
|
|
|
OO.EventEmitter.call( this );
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
// Properties
|
|
|
|
this.template = template;
|
2013-07-10 19:04:11 +00:00
|
|
|
this.originalName = name;
|
2014-03-04 22:56:14 +00:00
|
|
|
this.name = typeof name === 'string' ? name.trim() : '';
|
2013-06-11 19:16:04 +00:00
|
|
|
this.value = value || '';
|
|
|
|
this.id = this.template.getId() + '/' + name;
|
|
|
|
};
|
|
|
|
|
2013-12-09 19:05:57 +00:00
|
|
|
/* Inheritance */
|
|
|
|
|
2014-02-24 21:49:48 +00:00
|
|
|
OO.mixinClass( ve.dm.MWParameterModel, OO.EventEmitter );
|
2013-12-09 19:05:57 +00:00
|
|
|
|
|
|
|
/* Events */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event change
|
|
|
|
*/
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
/* Methods */
|
|
|
|
|
2014-01-14 19:16:49 +00:00
|
|
|
/**
|
|
|
|
* Check if parameter is required.
|
|
|
|
*
|
2015-08-19 18:09:34 +00:00
|
|
|
* @return {boolean} Parameter is required
|
2014-01-14 19:16:49 +00:00
|
|
|
*/
|
2014-02-24 21:49:48 +00:00
|
|
|
ve.dm.MWParameterModel.prototype.isRequired = function () {
|
2014-01-14 19:16:49 +00:00
|
|
|
return this.template.getSpec().isParameterRequired( this.name );
|
|
|
|
};
|
|
|
|
|
2014-04-28 19:10:31 +00:00
|
|
|
/**
|
2014-04-25 23:50:21 +00:00
|
|
|
* Check if parameter is suggested.
|
2014-04-28 19:10:31 +00:00
|
|
|
*
|
|
|
|
* @param {string} name Parameter name
|
2015-08-19 18:09:34 +00:00
|
|
|
* @return {boolean} Parameter is suggested
|
2014-04-28 19:10:31 +00:00
|
|
|
*/
|
|
|
|
ve.dm.MWParameterModel.prototype.isSuggested = function () {
|
|
|
|
return this.template.getSpec().isParameterSuggested( this.name );
|
|
|
|
};
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
/**
|
2014-04-25 23:50:21 +00:00
|
|
|
* Check if parameter is deprecated.
|
|
|
|
*
|
2015-08-19 18:09:34 +00:00
|
|
|
* @return {boolean} Parameter is deprecated
|
2014-04-25 23:50:21 +00:00
|
|
|
*/
|
|
|
|
ve.dm.MWParameterModel.prototype.isDeprecated = function () {
|
|
|
|
return this.template.getSpec().isParameterDeprecated( this.name );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get template of which this parameter is part.
|
2013-06-11 19:16:04 +00:00
|
|
|
*
|
2015-08-19 18:09:34 +00:00
|
|
|
* @return {ve.dm.MWTemplateModel} Template
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
2014-02-24 21:49:48 +00:00
|
|
|
ve.dm.MWParameterModel.prototype.getTemplate = function () {
|
2013-06-11 19:16:04 +00:00
|
|
|
return this.template;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get unique parameter ID within the transclusion.
|
|
|
|
*
|
2015-08-19 18:09:34 +00:00
|
|
|
* @return {string} Unique ID
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
2014-02-24 21:49:48 +00:00
|
|
|
ve.dm.MWParameterModel.prototype.getId = function () {
|
2013-06-11 19:16:04 +00:00
|
|
|
return this.id;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get parameter name.
|
|
|
|
*
|
2015-08-19 18:09:34 +00:00
|
|
|
* @return {string} Parameter name
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
2014-02-24 21:49:48 +00:00
|
|
|
ve.dm.MWParameterModel.prototype.getName = function () {
|
2013-06-11 19:16:04 +00:00
|
|
|
return this.name;
|
|
|
|
};
|
|
|
|
|
2013-07-10 19:04:11 +00:00
|
|
|
/**
|
|
|
|
* Get parameter name.
|
|
|
|
*
|
2015-08-19 18:09:34 +00:00
|
|
|
* @return {string} Parameter name
|
2013-07-10 19:04:11 +00:00
|
|
|
*/
|
2014-02-24 21:49:48 +00:00
|
|
|
ve.dm.MWParameterModel.prototype.getOriginalName = function () {
|
2013-07-10 19:04:11 +00:00
|
|
|
return this.originalName;
|
|
|
|
};
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
/**
|
|
|
|
* Get parameter value.
|
|
|
|
*
|
2015-08-19 18:09:34 +00:00
|
|
|
* @return {string} Parameter value, or automatic value if there is none stored.
|
2014-10-26 15:22:09 +00:00
|
|
|
* Otherwise an empty string.
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
2014-02-24 21:49:48 +00:00
|
|
|
ve.dm.MWParameterModel.prototype.getValue = function () {
|
2014-10-26 15:22:09 +00:00
|
|
|
return this.value || this.getAutoValue() || '';
|
|
|
|
};
|
|
|
|
|
2021-03-11 16:12:45 +00:00
|
|
|
/**
|
|
|
|
* Get parameter suggested values.
|
|
|
|
*
|
|
|
|
* @return {string[]} Parameter suggested values
|
|
|
|
*/
|
|
|
|
ve.dm.MWParameterModel.prototype.getSuggestedValues = function () {
|
|
|
|
return this.template.getSpec().getParameterSuggestedValues( this.name );
|
|
|
|
};
|
|
|
|
|
2014-10-26 15:22:09 +00:00
|
|
|
/**
|
|
|
|
* Get default parameter value.
|
|
|
|
*
|
2015-08-19 18:09:34 +00:00
|
|
|
* @return {string} Default parameter value
|
2014-10-26 15:22:09 +00:00
|
|
|
*/
|
|
|
|
ve.dm.MWParameterModel.prototype.getDefaultValue = function () {
|
|
|
|
return this.template.getSpec().getParameterDefaultValue( this.name );
|
|
|
|
};
|
|
|
|
|
2015-03-04 23:31:05 +00:00
|
|
|
/**
|
|
|
|
* Get default parameter value.
|
|
|
|
*
|
2015-08-19 18:09:34 +00:00
|
|
|
* @return {string} Default parameter value
|
2015-03-04 23:31:05 +00:00
|
|
|
*/
|
|
|
|
ve.dm.MWParameterModel.prototype.getExampleValue = function () {
|
|
|
|
return this.template.getSpec().getParameterExampleValue( this.name );
|
|
|
|
};
|
|
|
|
|
2014-10-26 15:22:09 +00:00
|
|
|
/**
|
|
|
|
* Get automatic parameter value.
|
|
|
|
*
|
2015-08-19 18:09:34 +00:00
|
|
|
* @return {string} Automatic parameter name.
|
2014-10-26 15:22:09 +00:00
|
|
|
*/
|
|
|
|
ve.dm.MWParameterModel.prototype.getAutoValue = function () {
|
|
|
|
return this.template.getSpec().getParameterAutoValue( this.name );
|
2013-06-11 19:16:04 +00:00
|
|
|
};
|
|
|
|
|
2014-10-29 21:50:14 +00:00
|
|
|
/**
|
|
|
|
* Get parameter type.
|
|
|
|
*
|
|
|
|
* @return {string} Parameter type
|
|
|
|
*/
|
|
|
|
ve.dm.MWParameterModel.prototype.getType = function () {
|
|
|
|
return this.template.getSpec().getParameterType( this.name );
|
|
|
|
};
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
/**
|
|
|
|
* Set parameter value.
|
|
|
|
*
|
|
|
|
* @param {string} value Parameter value
|
|
|
|
*/
|
2014-02-24 21:49:48 +00:00
|
|
|
ve.dm.MWParameterModel.prototype.setValue = function ( value ) {
|
2013-06-11 19:16:04 +00:00
|
|
|
this.value = value;
|
2013-12-09 19:05:57 +00:00
|
|
|
this.emit( 'change' );
|
2013-06-11 19:16:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove parameter from template.
|
|
|
|
*/
|
2014-02-24 21:49:48 +00:00
|
|
|
ve.dm.MWParameterModel.prototype.remove = function () {
|
2013-06-29 02:37:42 +00:00
|
|
|
this.template.removeParameter( this );
|
2013-06-11 19:16:04 +00:00
|
|
|
};
|