mediawiki-extensions-Visual.../modules/ve-mw/dm/models/ve.dm.MWParameterModel.js
Trevor Parscal e2f6d798b8 Rename MWTemplateParameter* classes to MWParameter*
* The name was getting super long, and the Template prefix doesn't
  appear to be important.
* Soon we will add a placeholder class, which would have been
  MWTemplateParameterPlaceholder, but now just MWParameterPlaceholder
  which seems a little less ridiculous.

Change-Id: Ie2dfe0d4c7b960cd554f89fa6340173e8786c88a
2014-02-26 10:54:45 +00:00

115 lines
2.2 KiB
JavaScript

/*!
* VisualEditor DataModel MWParameterModel class.
*
* @copyright 2011-2014 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* MediaWiki template parameter.
*
* @class
* @mixins OO.EventEmitter
*
* @constructor
* @param {ve.dm.MWTemplateModel} template Template
* @param {string} name Parameter name
* @param {string} value Parameter value
*/
ve.dm.MWParameterModel = function VeDmMWParameterModel( template, name, value ) {
// Mixin constructors
OO.EventEmitter.call( this );
// Properties
this.template = template;
this.originalName = name;
this.name = name.trim();
this.value = value || '';
this.id = this.template.getId() + '/' + name;
};
/* Inheritance */
OO.mixinClass( ve.dm.MWParameterModel, OO.EventEmitter );
/* Events */
/**
* @event change
*/
/* Methods */
/**
* Check if parameter is required.
*
* @method
* @param {string} name Parameter name
* @returns {boolean} Parameter is required
*/
ve.dm.MWParameterModel.prototype.isRequired = function () {
return this.template.getSpec().isParameterRequired( this.name );
};
/**
* Get template parameter is part of.
*
* @returns {ve.dm.MWTemplateModel} Template
*/
ve.dm.MWParameterModel.prototype.getTemplate = function () {
return this.template;
};
/**
* Get unique parameter ID within the transclusion.
*
* @returns {string} Unique ID
*/
ve.dm.MWParameterModel.prototype.getId = function () {
return this.id;
};
/**
* Get parameter name.
*
* @returns {string} Parameter name
*/
ve.dm.MWParameterModel.prototype.getName = function () {
return this.name;
};
/**
* Get parameter name.
*
* @returns {string} Parameter name
*/
ve.dm.MWParameterModel.prototype.getOriginalName = function () {
return this.originalName;
};
/**
* Get parameter value.
*
* @returns {string} Parameter value
*/
ve.dm.MWParameterModel.prototype.getValue = function () {
return this.value;
};
/**
* Set parameter value.
*
* @param {string} value Parameter value
*/
ve.dm.MWParameterModel.prototype.setValue = function ( value ) {
this.value = value;
this.emit( 'change' );
};
/**
* Remove parameter from template.
*/
ve.dm.MWParameterModel.prototype.remove = function () {
this.template.removeParameter( this );
};