mediawiki-extensions-Visual.../modules/ve-mw/dm/models/ve.dm.MWParameterModel.js
Trevor Parscal 853e4872b4 Restyle parameter pages
* Move description to a popup behind a little info icon button
* Make required indicator generic status indicator (required/deprecated)
  and move to left of the field
* Move param name and actions to above the field
* Show deprecated status and description

Bonus:

* Use auto-focus on CitationDialog (whoops!)
* Make pages that aren't meant to scroll not scroll (whoops again!?)

Depends on I59211b2 in OOUI

Bug: 53612
Change-Id: I3b968ad14aa6c43b6484e2565a9367d2ebc72fc5
2014-04-30 16:27:19 -07:00

135 lines
2.7 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
* @returns {boolean} Parameter is required
*/
ve.dm.MWParameterModel.prototype.isRequired = function () {
return this.template.getSpec().isParameterRequired( this.name );
};
/**
* Check if parameter is suggested.
*
* @method
* @param {string} name Parameter name
* @returns {boolean} Parameter is suggested
*/
ve.dm.MWParameterModel.prototype.isSuggested = function () {
return this.template.getSpec().isParameterSuggested( this.name );
};
/**
* 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.
*
* @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 );
};