2021-05-17 15:43:49 +00:00
|
|
|
/*!
|
2021-06-18 09:48:33 +00:00
|
|
|
* VisualEditor user interface MWTemplateOutlineParameterCheckboxLayout class.
|
2021-05-17 15:43:49 +00:00
|
|
|
*
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Container for checkbox and label
|
|
|
|
*
|
|
|
|
* @class
|
2021-06-18 09:48:33 +00:00
|
|
|
* @extends OO.ui.FieldLayout
|
2021-05-17 15:43:49 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} [config] Configuration options
|
|
|
|
*/
|
2021-06-18 09:48:33 +00:00
|
|
|
ve.ui.MWTemplateOutlineParameterCheckboxLayout = function VeUiMWTemplateOutlineParameterCheckboxLayout( config ) {
|
2021-05-17 15:43:49 +00:00
|
|
|
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
|
2021-06-18 09:48:33 +00:00
|
|
|
ve.ui.MWTemplateOutlineParameterCheckboxLayout.super.call( this, checkbox, config );
|
2021-05-17 15:43:49 +00:00
|
|
|
|
|
|
|
// 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 */
|
|
|
|
|
2021-06-18 09:48:33 +00:00
|
|
|
OO.inheritClass( ve.ui.MWTemplateOutlineParameterCheckboxLayout, OO.ui.FieldLayout );
|
2021-05-17 15:43:49 +00:00
|
|
|
|
|
|
|
/* Methods */
|
2021-06-18 09:48:33 +00:00
|
|
|
ve.ui.MWTemplateOutlineParameterCheckboxLayout.prototype.onEdit = function ( value ) {
|
2021-05-17 15:43:49 +00:00
|
|
|
this.emit( 'change', value );
|
|
|
|
};
|
|
|
|
|
2021-06-18 09:48:33 +00:00
|
|
|
ve.ui.MWTemplateOutlineParameterCheckboxLayout.prototype.onLabelClick = function () {
|
2021-05-17 15:43:49 +00:00
|
|
|
if ( !this.fieldWidget.isSelected() ) {
|
|
|
|
this.fieldWidget.setSelected( true );
|
|
|
|
}
|
|
|
|
this.emit( 'select' );
|
|
|
|
};
|