mediawiki-extensions-Visual.../modules/ve-mw/ui/widgets/ve.ui.MWTemplateOutlineParameterCheckboxLayout.js
WMDE-Fisch 407ff95597 Rename OutlineParameterCheckboxWidget to OutlineParameterCheckboxLayout
This not really just a checkbox widget anymore it inherits from
FieldLayout and became something more in that direction.

Let's use a mixture of these things to make it a bit clearer.

See also comment in Ie81b84be288553343017c4aaf8691c4e266995f5

Change-Id: Iff1746a8e5e94b56eb6c27465405aaf6b74c2310
2021-06-21 09:08:54 +02:00

59 lines
1.6 KiB
JavaScript

/*!
* VisualEditor user interface MWTemplateOutlineParameterCheckboxLayout class.
*
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* Container for checkbox and label
*
* @class
* @extends OO.ui.FieldLayout
*
* @constructor
* @param {Object} [config] Configuration options
*/
ve.ui.MWTemplateOutlineParameterCheckboxLayout = function VeUiMWTemplateOutlineParameterCheckboxLayout( config ) {
config = config || {};
config = $.extend( { align: 'inline' }, config );
var checkbox = new OO.ui.CheckboxInputWidget( {
title: config.required ? ve.msg( 'visualeditor-dialog-transclusion-required-parameter' ) : null,
disabled: config.required,
selected: config.selected || config.required
} )
// FIXME: pass-through binding like [ 'emit', 'toggle' ]?
.connect( this, {
change: 'onEdit'
} );
// Parent constructor
ve.ui.MWTemplateOutlineParameterCheckboxLayout.super.call( this, checkbox, config );
// Initialization
this.$element.addClass( 've-ui-templateOutlineItem' );
// Override base behaviors
// Unwire native label->input linkage, and replace with our custom click handler.
this.$label
.attr( 'for', null );
this.$header
.on( 'click', this.onLabelClick.bind( this ) );
};
/* Inheritance */
OO.inheritClass( ve.ui.MWTemplateOutlineParameterCheckboxLayout, OO.ui.FieldLayout );
/* Methods */
ve.ui.MWTemplateOutlineParameterCheckboxLayout.prototype.onEdit = function ( value ) {
this.emit( 'change', value );
};
ve.ui.MWTemplateOutlineParameterCheckboxLayout.prototype.onLabelClick = function () {
if ( !this.fieldWidget.isSelected() ) {
this.fieldWidget.setSelected( true );
}
this.emit( 'select' );
};