mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-28 16:20:52 +00:00
Merge "Use TemplateData's suggested
status for parameters"
This commit is contained in:
commit
0e4ed61772
|
@ -51,6 +51,17 @@ ve.dm.MWParameterModel.prototype.isRequired = function () {
|
|||
return this.template.getSpec().isParameterRequired( this.name );
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if parameter is suggestyed.
|
||||
*
|
||||
* @method
|
||||
* @param {string} name Parameter name
|
||||
* @returns {boolean} Parameter is suggested
|
||||
*/
|
||||
ve.dm.MWParameterModel.prototype.isSuggested = function () {
|
||||
return this.template.getSpec().isParameterSuggested( this.name );
|
||||
};
|
||||
|
||||
/**
|
||||
* Get template parameter is part of.
|
||||
*
|
||||
|
|
|
@ -285,17 +285,23 @@ ve.dm.MWTemplateModel.prototype.removeParameter = function ( param ) {
|
|||
};
|
||||
|
||||
/**
|
||||
* Add all non-existing required parameters, if any.
|
||||
* Add all non-existing required and suggested parameters, if any.
|
||||
*
|
||||
* @method
|
||||
*/
|
||||
ve.dm.MWTemplateModel.prototype.addRequiredParameters = function () {
|
||||
ve.dm.MWTemplateModel.prototype.addPromptedParameters = function () {
|
||||
var i, len,
|
||||
spec = this.getSpec(),
|
||||
names = spec.getParameterNames();
|
||||
|
||||
for ( i = 0, len = names.length; i < len; i++ ) {
|
||||
if ( !this.params[name] && spec.isParameterRequired( names[i] ) ) {
|
||||
if (
|
||||
!this.params[name] &&
|
||||
(
|
||||
spec.isParameterRequired( names[i] ) ||
|
||||
spec.isParameterSuggested( names[i] )
|
||||
)
|
||||
) {
|
||||
this.addParameter( new ve.dm.MWParameterModel( this, names[i] ) );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -106,6 +106,7 @@ ve.dm.MWTemplateSpecModel.prototype.getDefaultParameterSpec = function ( name )
|
|||
'aliases': [],
|
||||
'name': name,
|
||||
'required': false,
|
||||
'suggested': false,
|
||||
'deprecated': false
|
||||
};
|
||||
};
|
||||
|
@ -256,6 +257,16 @@ ve.dm.MWTemplateSpecModel.prototype.isParameterRequired = function ( name ) {
|
|||
return !!this.params[name].required;
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if parameter is suggsted.
|
||||
*
|
||||
* @param {string} name Parameter name
|
||||
* @returns {boolean} Parameter is suggested
|
||||
*/
|
||||
ve.dm.MWTemplateSpecModel.prototype.isParameterSuggested = function ( name ) {
|
||||
return !!this.params[name].suggested;
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if parameter is deprecated.
|
||||
*
|
||||
|
|
|
@ -106,11 +106,11 @@ ve.ui.MWTemplateDialog.prototype.onReplacePart = function ( removed, added ) {
|
|||
}
|
||||
}
|
||||
|
||||
// Add required params to user created templates
|
||||
// Add required and suggested params to user created templates
|
||||
if ( added instanceof ve.dm.MWTemplateModel && this.loaded ) {
|
||||
// Prevent selection changes
|
||||
this.preventReselection = true;
|
||||
added.addRequiredParameters();
|
||||
added.addPromptedParameters();
|
||||
this.preventReselection = false;
|
||||
names = added.getParameterNames();
|
||||
params = added.getParameters();
|
||||
|
@ -333,7 +333,7 @@ ve.ui.MWTemplateDialog.prototype.setup = function ( data ) {
|
|||
if ( data.template ) {
|
||||
template = ve.dm.MWTemplateModel.newFromName( this.transclusion, data.template );
|
||||
promise = this.transclusion.addPart( template ).done( function () {
|
||||
template.addRequiredParameters();
|
||||
template.addPromptedParameters();
|
||||
} );
|
||||
} else {
|
||||
promise = this.transclusion.addPart(
|
||||
|
|
Loading…
Reference in a new issue