From 3569efba3bce28920dcdea0e3d9119838379e627 Mon Sep 17 00:00:00 2001 From: "James D. Forrester" Date: Mon, 28 Apr 2014 12:10:31 -0700 Subject: [PATCH] Use TemplateData's `suggested` status for parameters Change-Id: I8c8522d1fcc7e7b26984d72a8f8aaaedbddb9cb4 --- modules/ve-mw/dm/models/ve.dm.MWParameterModel.js | 11 +++++++++++ modules/ve-mw/dm/models/ve.dm.MWTemplateModel.js | 12 +++++++++--- modules/ve-mw/dm/models/ve.dm.MWTemplateSpecModel.js | 11 +++++++++++ modules/ve-mw/ui/dialogs/ve.ui.MWTemplateDialog.js | 6 +++--- 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/modules/ve-mw/dm/models/ve.dm.MWParameterModel.js b/modules/ve-mw/dm/models/ve.dm.MWParameterModel.js index e5d532afda..f3a961489d 100644 --- a/modules/ve-mw/dm/models/ve.dm.MWParameterModel.js +++ b/modules/ve-mw/dm/models/ve.dm.MWParameterModel.js @@ -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. * diff --git a/modules/ve-mw/dm/models/ve.dm.MWTemplateModel.js b/modules/ve-mw/dm/models/ve.dm.MWTemplateModel.js index 9e761c510e..a95e4df65e 100644 --- a/modules/ve-mw/dm/models/ve.dm.MWTemplateModel.js +++ b/modules/ve-mw/dm/models/ve.dm.MWTemplateModel.js @@ -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] ) ); } } diff --git a/modules/ve-mw/dm/models/ve.dm.MWTemplateSpecModel.js b/modules/ve-mw/dm/models/ve.dm.MWTemplateSpecModel.js index 1ee46c0cab..2bb2ea5248 100644 --- a/modules/ve-mw/dm/models/ve.dm.MWTemplateSpecModel.js +++ b/modules/ve-mw/dm/models/ve.dm.MWTemplateSpecModel.js @@ -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. * diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWTemplateDialog.js b/modules/ve-mw/ui/dialogs/ve.ui.MWTemplateDialog.js index a3d7fad6bc..5d4be158a3 100644 --- a/modules/ve-mw/ui/dialogs/ve.ui.MWTemplateDialog.js +++ b/modules/ve-mw/ui/dialogs/ve.ui.MWTemplateDialog.js @@ -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(