2013-07-02 20:40:54 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor UserInterface MWParameterResultWidget class.
|
|
|
|
*
|
2020-01-08 17:13:04 +00:00
|
|
|
* @copyright 2011-2020 VisualEditor Team and others; see AUTHORS.txt
|
2013-07-02 20:40:54 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an ve.ui.MWParameterResultWidget object.
|
|
|
|
*
|
|
|
|
* @class
|
2014-10-28 00:46:32 +00:00
|
|
|
* @extends OO.ui.DecoratedOptionWidget
|
2013-07-02 20:40:54 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
2021-09-11 08:05:31 +00:00
|
|
|
* @param {Object} config
|
|
|
|
* @cfg {Object} data
|
|
|
|
* @cfg {string} [data.name] Parameter name
|
|
|
|
* @cfg {string[]} [data.aliases]
|
|
|
|
* @cfg {string} data.label
|
|
|
|
* @cfg {string} [data.description='']
|
|
|
|
* @cfg {boolean} [data.isUnknown=false] If the parameter is unknown, i.e. not documented via
|
|
|
|
* TemplateData
|
2013-07-02 20:40:54 +00:00
|
|
|
*/
|
2014-11-22 01:40:00 +00:00
|
|
|
ve.ui.MWParameterResultWidget = function VeUiMWParameterResultWidget( config ) {
|
2013-07-09 22:48:08 +00:00
|
|
|
// Configuration initialization
|
2014-08-22 20:50:48 +00:00
|
|
|
config = ve.extendObject( { icon: 'parameter' }, config );
|
2013-07-09 22:48:08 +00:00
|
|
|
|
2013-07-02 20:40:54 +00:00
|
|
|
// Parent constructor
|
2016-08-22 21:44:59 +00:00
|
|
|
ve.ui.MWParameterResultWidget.super.call( this, config );
|
2013-07-02 20:40:54 +00:00
|
|
|
|
|
|
|
// Initialization
|
2013-11-01 19:45:59 +00:00
|
|
|
this.$element.addClass( 've-ui-mwParameterResultWidget' );
|
2013-07-02 20:40:54 +00:00
|
|
|
this.setLabel( this.buildLabel() );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2014-10-28 00:46:32 +00:00
|
|
|
OO.inheritClass( ve.ui.MWParameterResultWidget, OO.ui.DecoratedOptionWidget );
|
2013-07-02 20:40:54 +00:00
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
2019-04-16 15:17:29 +00:00
|
|
|
/**
|
|
|
|
* Build the label element
|
|
|
|
*
|
2021-09-17 09:29:50 +00:00
|
|
|
* @private
|
2019-04-16 15:17:29 +00:00
|
|
|
* @return {jQuery}
|
|
|
|
*/
|
2013-07-02 20:40:54 +00:00
|
|
|
ve.ui.MWParameterResultWidget.prototype.buildLabel = function () {
|
2021-06-21 08:10:27 +00:00
|
|
|
var $label = $( '<div>' )
|
2013-07-02 20:40:54 +00:00
|
|
|
.addClass( 've-ui-mwParameterResultWidget-label' )
|
|
|
|
.text( this.data.label ),
|
2015-04-09 23:47:15 +00:00
|
|
|
$names = $( '<div>' )
|
2013-07-02 20:40:54 +00:00
|
|
|
.addClass( 've-ui-mwParameterResultWidget-names' ),
|
2015-04-09 23:47:15 +00:00
|
|
|
$description = $( '<div>' )
|
2013-07-02 20:40:54 +00:00
|
|
|
.addClass( 've-ui-mwParameterResultWidget-description' )
|
|
|
|
.text( this.data.description || '' );
|
|
|
|
|
2021-07-07 15:00:58 +00:00
|
|
|
if ( this.data.isUnknown ) {
|
|
|
|
$description.addClass( 've-ui-mwParameterResultWidget-unknown' )
|
|
|
|
.text( ve.msg( 'visualeditor-parameter-search-unknown' ) );
|
|
|
|
}
|
|
|
|
|
Reduce duplication/clutter in MWParameterResultWidget
The MWParameterSearchWidget that shows a list of all available
template parameters displays the (human-readable) label and
description of each parameter (both given via <templatedata>), as
well as the parameter's internal name and aliases, if there are
any.
This turns out to be non-helpful in the majority of situations:
* When there is no <templatedata> yet, there are no labels.
Instead, the names are used as labels, which means they are
*all* identical and everything is shown twice.
* The same happens when manually adding an "unknown field". Simply
start typing, and you can add parameters with any name. What you
type is shown twice (actually 3 times, 1 time in the input
field, 2 times in the result widget).
* Many template parameters are already nice, human-readable. Even
if <templatedata> exists and specifies labels, these labels are
often identical to the names. There is no need to come up with
something else if the name is already good enough. (Exception:
Localizations, but these are rare.)
Furthermore, this is a *search* result widget. The pretty much
only reason the names and aliases are shown is because the user
can search for them, and needs to understand why a parameter was
found. This still works fine.
For comparison, when a parameter is required you will *never* see
it's name, because the parameter is always there, and never shows
up as a search result.
Change-Id: I6b1dca1c94b2c496930b5bfdfe1c6f76898faa2a
2020-08-20 10:04:48 +00:00
|
|
|
if ( this.data.name && this.data.name !== this.data.label ) {
|
2013-07-02 20:40:54 +00:00
|
|
|
$names.append(
|
2015-04-09 23:47:15 +00:00
|
|
|
$( '<span>' )
|
2013-07-02 20:40:54 +00:00
|
|
|
.addClass( 've-ui-mwParameterResultWidget-name' )
|
|
|
|
.text( this.data.name )
|
|
|
|
);
|
|
|
|
}
|
2021-06-21 08:10:27 +00:00
|
|
|
for ( var i = 0; i < this.data.aliases.length; i++ ) {
|
Reduce duplication/clutter in MWParameterResultWidget
The MWParameterSearchWidget that shows a list of all available
template parameters displays the (human-readable) label and
description of each parameter (both given via <templatedata>), as
well as the parameter's internal name and aliases, if there are
any.
This turns out to be non-helpful in the majority of situations:
* When there is no <templatedata> yet, there are no labels.
Instead, the names are used as labels, which means they are
*all* identical and everything is shown twice.
* The same happens when manually adding an "unknown field". Simply
start typing, and you can add parameters with any name. What you
type is shown twice (actually 3 times, 1 time in the input
field, 2 times in the result widget).
* Many template parameters are already nice, human-readable. Even
if <templatedata> exists and specifies labels, these labels are
often identical to the names. There is no need to come up with
something else if the name is already good enough. (Exception:
Localizations, but these are rare.)
Furthermore, this is a *search* result widget. The pretty much
only reason the names and aliases are shown is because the user
can search for them, and needs to understand why a parameter was
found. This still works fine.
For comparison, when a parameter is required you will *never* see
it's name, because the parameter is always there, and never shows
up as a search result.
Change-Id: I6b1dca1c94b2c496930b5bfdfe1c6f76898faa2a
2020-08-20 10:04:48 +00:00
|
|
|
if ( this.data.aliases[ i ] === this.data.label ) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-07-02 20:40:54 +00:00
|
|
|
$names.append(
|
2015-04-09 23:47:15 +00:00
|
|
|
$( '<span>' )
|
Reduce duplication/clutter in MWParameterResultWidget
The MWParameterSearchWidget that shows a list of all available
template parameters displays the (human-readable) label and
description of each parameter (both given via <templatedata>), as
well as the parameter's internal name and aliases, if there are
any.
This turns out to be non-helpful in the majority of situations:
* When there is no <templatedata> yet, there are no labels.
Instead, the names are used as labels, which means they are
*all* identical and everything is shown twice.
* The same happens when manually adding an "unknown field". Simply
start typing, and you can add parameters with any name. What you
type is shown twice (actually 3 times, 1 time in the input
field, 2 times in the result widget).
* Many template parameters are already nice, human-readable. Even
if <templatedata> exists and specifies labels, these labels are
often identical to the names. There is no need to come up with
something else if the name is already good enough. (Exception:
Localizations, but these are rare.)
Furthermore, this is a *search* result widget. The pretty much
only reason the names and aliases are shown is because the user
can search for them, and needs to understand why a parameter was
found. This still works fine.
For comparison, when a parameter is required you will *never* see
it's name, because the parameter is always there, and never shows
up as a search result.
Change-Id: I6b1dca1c94b2c496930b5bfdfe1c6f76898faa2a
2020-08-20 10:04:48 +00:00
|
|
|
.addClass( 've-ui-mwParameterResultWidget-name ve-ui-mwParameterResultWidget-alias' )
|
2015-08-19 17:33:02 +00:00
|
|
|
.text( this.data.aliases[ i ] )
|
2013-07-02 20:40:54 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $label.add( $names ).add( $description );
|
2013-07-31 22:53:29 +00:00
|
|
|
};
|