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
|
|
|
*
|
2014-01-05 12:05:05 +00:00
|
|
|
* @copyright 2011-2014 VisualEditor Team and others; see AUTHORS.txt
|
2013-06-11 19:16:04 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MediaWiki template parameter.
|
|
|
|
*
|
|
|
|
* @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.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @returns {boolean} Parameter is required
|
|
|
|
*/
|
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
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {string} name Parameter name
|
|
|
|
* @returns {boolean} Parameter is suggested
|
|
|
|
*/
|
|
|
|
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.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @returns {boolean} Parameter is deprecated
|
|
|
|
*/
|
|
|
|
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
|
|
|
*
|
|
|
|
* @returns {ve.dm.MWTemplateModel} Template
|
|
|
|
*/
|
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.
|
|
|
|
*
|
2013-06-17 10:50:24 +00:00
|
|
|
* @returns {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.
|
|
|
|
*
|
|
|
|
* @returns {string} Parameter name
|
|
|
|
*/
|
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.
|
|
|
|
*
|
|
|
|
* @returns {string} Parameter name
|
|
|
|
*/
|
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.
|
|
|
|
*
|
|
|
|
* @returns {string} Parameter value
|
|
|
|
*/
|
2014-02-24 21:49:48 +00:00
|
|
|
ve.dm.MWParameterModel.prototype.getValue = function () {
|
2013-06-11 19:16:04 +00:00
|
|
|
return this.value;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
};
|