2021-05-17 15:43:49 +00:00
|
|
|
/*!
|
2021-08-16 12:56:27 +00:00
|
|
|
* VisualEditor user interface MWTransclusionOutlineParameterWidget class.
|
2021-05-17 15:43:49 +00:00
|
|
|
*
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2021-08-16 16:17:14 +00:00
|
|
|
* A widget that represents a template parameter, with a checkbox to add/remove the parameter.
|
|
|
|
* Modelled after {@see OO.ui.OutlineOptionWidget}. Also see {@see OO.ui.CheckboxMultioptionWidget}
|
|
|
|
* for inspiration.
|
2021-05-17 15:43:49 +00:00
|
|
|
*
|
|
|
|
* @class
|
2021-08-16 14:06:39 +00:00
|
|
|
* @extends OO.ui.OptionWidget
|
2021-05-17 15:43:49 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
2021-07-13 19:01:30 +00:00
|
|
|
* @param {Object} config
|
|
|
|
* @cfg {string} data Parameter name
|
|
|
|
* @cfg {string} label
|
|
|
|
* @cfg {boolean} [required]
|
|
|
|
* @cfg {boolean} [selected]
|
2021-05-17 15:43:49 +00:00
|
|
|
*/
|
2021-08-16 12:56:27 +00:00
|
|
|
ve.ui.MWTransclusionOutlineParameterWidget = function VeUiMWTransclusionOutlineParameterWidget( config ) {
|
2021-08-10 14:42:21 +00:00
|
|
|
this.checkbox = new OO.ui.CheckboxInputWidget( {
|
2021-08-16 16:17:14 +00:00
|
|
|
title: config.required ?
|
|
|
|
ve.msg( 'visualeditor-dialog-transclusion-required-parameter' ) :
|
|
|
|
null,
|
2021-05-17 15:43:49 +00:00
|
|
|
disabled: config.required,
|
2021-08-16 16:17:14 +00:00
|
|
|
selected: config.selected || config.required,
|
|
|
|
// Keyboard navigation is handled by the outer OO.ui.SelectWidget
|
|
|
|
tabIndex: -1
|
2021-05-17 15:43:49 +00:00
|
|
|
} )
|
2021-08-16 16:17:14 +00:00
|
|
|
.connect( this, {
|
|
|
|
// The array syntax is a way to call `this.emit( 'change' )`.
|
|
|
|
change: [ 'emit', 'change' ]
|
|
|
|
} );
|
|
|
|
this.checkbox.$input.on( {
|
|
|
|
mousedown: this.onMouseDown.bind( this )
|
|
|
|
} );
|
2021-05-17 15:43:49 +00:00
|
|
|
|
|
|
|
// Parent constructor
|
2021-08-16 12:56:27 +00:00
|
|
|
ve.ui.MWTransclusionOutlineParameterWidget.super.call( this, ve.extendObject( config, {
|
2021-08-16 14:06:39 +00:00
|
|
|
$label: $( '<label>' )
|
|
|
|
} ) );
|
2021-05-17 15:43:49 +00:00
|
|
|
|
|
|
|
// Initialization
|
2021-08-09 16:35:53 +00:00
|
|
|
this.$element
|
|
|
|
.addClass( 've-ui-mwTransclusionOutlineItem' )
|
2021-08-16 16:17:14 +00:00
|
|
|
.append( this.checkbox.$element, this.$label );
|
2021-05-17 15:43:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2021-08-16 12:56:27 +00:00
|
|
|
OO.inheritClass( ve.ui.MWTransclusionOutlineParameterWidget, OO.ui.OptionWidget );
|
2021-06-29 19:45:09 +00:00
|
|
|
|
2021-05-17 15:43:49 +00:00
|
|
|
/* Methods */
|
2021-06-29 19:45:09 +00:00
|
|
|
|
2021-08-09 16:35:53 +00:00
|
|
|
/**
|
2021-08-16 14:06:39 +00:00
|
|
|
* @private
|
2021-08-09 16:35:53 +00:00
|
|
|
*/
|
2021-08-16 16:17:14 +00:00
|
|
|
ve.ui.MWTransclusionOutlineParameterWidget.prototype.onMouseDown = function ( e ) {
|
|
|
|
// Mouse clicks conflict with the click handler in {@see OO.ui.SelectWidget}
|
|
|
|
e.stopPropagation();
|
2021-08-09 16:35:53 +00:00
|
|
|
};
|
|
|
|
|
2021-08-16 14:06:39 +00:00
|
|
|
/**
|
2021-08-16 16:17:14 +00:00
|
|
|
* @inheritDoc OO.ui.OptionWidget
|
2021-08-16 14:06:39 +00:00
|
|
|
*/
|
2021-08-16 16:17:14 +00:00
|
|
|
ve.ui.MWTransclusionOutlineParameterWidget.prototype.setSelected = function ( state ) {
|
|
|
|
// Never uncheck a required parameter
|
|
|
|
state = state || this.checkbox.isDisabled();
|
2021-08-09 16:35:53 +00:00
|
|
|
|
2021-08-16 16:17:14 +00:00
|
|
|
this.checkbox.setSelected( state, true );
|
|
|
|
ve.ui.MWTransclusionOutlineParameterWidget.super.prototype.setSelected.call( this, state );
|
2021-05-17 15:43:49 +00:00
|
|
|
|
2021-08-16 16:17:14 +00:00
|
|
|
return this;
|
2021-05-17 15:43:49 +00:00
|
|
|
};
|