mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-12-01 09:26:37 +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 );
|
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.
|
* 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
|
* @method
|
||||||
*/
|
*/
|
||||||
ve.dm.MWTemplateModel.prototype.addRequiredParameters = function () {
|
ve.dm.MWTemplateModel.prototype.addPromptedParameters = function () {
|
||||||
var i, len,
|
var i, len,
|
||||||
spec = this.getSpec(),
|
spec = this.getSpec(),
|
||||||
names = spec.getParameterNames();
|
names = spec.getParameterNames();
|
||||||
|
|
||||||
for ( i = 0, len = names.length; i < len; i++ ) {
|
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] ) );
|
this.addParameter( new ve.dm.MWParameterModel( this, names[i] ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,6 +106,7 @@ ve.dm.MWTemplateSpecModel.prototype.getDefaultParameterSpec = function ( name )
|
||||||
'aliases': [],
|
'aliases': [],
|
||||||
'name': name,
|
'name': name,
|
||||||
'required': false,
|
'required': false,
|
||||||
|
'suggested': false,
|
||||||
'deprecated': false
|
'deprecated': false
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -256,6 +257,16 @@ ve.dm.MWTemplateSpecModel.prototype.isParameterRequired = function ( name ) {
|
||||||
return !!this.params[name].required;
|
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.
|
* 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 ) {
|
if ( added instanceof ve.dm.MWTemplateModel && this.loaded ) {
|
||||||
// Prevent selection changes
|
// Prevent selection changes
|
||||||
this.preventReselection = true;
|
this.preventReselection = true;
|
||||||
added.addRequiredParameters();
|
added.addPromptedParameters();
|
||||||
this.preventReselection = false;
|
this.preventReselection = false;
|
||||||
names = added.getParameterNames();
|
names = added.getParameterNames();
|
||||||
params = added.getParameters();
|
params = added.getParameters();
|
||||||
|
@ -333,7 +333,7 @@ ve.ui.MWTemplateDialog.prototype.setup = function ( data ) {
|
||||||
if ( data.template ) {
|
if ( data.template ) {
|
||||||
template = ve.dm.MWTemplateModel.newFromName( this.transclusion, data.template );
|
template = ve.dm.MWTemplateModel.newFromName( this.transclusion, data.template );
|
||||||
promise = this.transclusion.addPart( template ).done( function () {
|
promise = this.transclusion.addPart( template ).done( function () {
|
||||||
template.addRequiredParameters();
|
template.addPromptedParameters();
|
||||||
} );
|
} );
|
||||||
} else {
|
} else {
|
||||||
promise = this.transclusion.addPart(
|
promise = this.transclusion.addPart(
|
||||||
|
|
Loading…
Reference in a new issue