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
|
|
|
|
* @param {string} name Parameter name
|
|
|
|
* @param {string} value Parameter value
|
|
|
|
*/
|
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;
|
|
|
|
this.name = 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
|
|
|
|
* @param {string} name Parameter name
|
|
|
|
* @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 );
|
|
|
|
};
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
/**
|
|
|
|
* Get template parameter is part of.
|
|
|
|
*
|
|
|
|
* @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
|
|
|
};
|