mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-25 23:05:35 +00:00
37f4996392
* Automatically select single mode when possible * Allow dynamic switching when possible * Hide most of the controls and information when in single mode * Allow parameter model to be instantiated without name and value args * Place add param buttons at the bottom of template and param pages which are only visible when in single mode and on the last page Change-Id: Iaffbf1863b808c8089dfcf09a976d165f28c8b74
115 lines
2.3 KiB
JavaScript
115 lines
2.3 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 = typeof name === 'string' ? 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 );
|
|
};
|