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
|
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-06-18 09:48:33 +00:00
|
|
|
ve.ui.MWTemplateOutlineParameterCheckboxLayout = function VeUiMWTemplateOutlineParameterCheckboxLayout( config ) {
|
2021-05-17 15:43:49 +00:00
|
|
|
config = config || {};
|
2021-07-13 09:00:57 +00:00
|
|
|
config = ve.extendObject( { align: 'inline' }, config );
|
2021-05-17 15:43:49 +00:00
|
|
|
|
2021-08-09 16:31:30 +00:00
|
|
|
var checkbox = new OO.ui.CheckboxInputWidget( {
|
2021-05-17 15:43:49 +00:00
|
|
|
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' ]?
|
2021-08-09 16:35:53 +00:00
|
|
|
.connect( this, { change: 'onCheckboxChange' } );
|
|
|
|
checkbox.$input.on( 'keydown', this.onCheckboxKeyDown.bind( this ) );
|
2021-05-17 15:43:49 +00:00
|
|
|
|
|
|
|
// Parent constructor
|
2021-08-09 16:31:30 +00:00
|
|
|
ve.ui.MWTemplateOutlineParameterCheckboxLayout.super.call( this, checkbox, config );
|
2021-05-17 15:43:49 +00:00
|
|
|
|
2021-08-09 16:35:53 +00:00
|
|
|
// Mixin constructors
|
|
|
|
if ( checkbox.isDisabled() ) {
|
|
|
|
OO.ui.mixin.TabIndexedElement.call( this, config );
|
|
|
|
}
|
|
|
|
|
2021-05-17 15:43:49 +00:00
|
|
|
// Initialization
|
2021-08-09 16:35:53 +00:00
|
|
|
this.$element
|
|
|
|
.addClass( 've-ui-mwTransclusionOutlineItem' )
|
|
|
|
.on( 'click', this.onClick.bind( this ) )
|
|
|
|
.on( 'keydown', this.onKeyDown.bind( this ) );
|
2021-05-17 15:43:49 +00:00
|
|
|
|
|
|
|
// Override base behaviors
|
|
|
|
// Unwire native label->input linkage, and replace with our custom click handler.
|
2021-08-09 16:35:53 +00:00
|
|
|
this.$label.attr( 'for', null );
|
|
|
|
this.$header.on( 'click', this.onLabelClick.bind( this ) );
|
2021-05-17 15:43:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2021-06-18 09:48:33 +00:00
|
|
|
OO.inheritClass( ve.ui.MWTemplateOutlineParameterCheckboxLayout, OO.ui.FieldLayout );
|
2021-08-09 16:35:53 +00:00
|
|
|
OO.mixinClass( ve.ui.MWTemplateOutlineParameterCheckboxLayout, OO.ui.mixin.TabIndexedElement );
|
2021-05-17 15:43:49 +00:00
|
|
|
|
2021-06-29 19:45:09 +00:00
|
|
|
/* Events */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event change
|
2021-07-13 19:01:30 +00:00
|
|
|
* @param {string} paramName
|
2021-06-29 19:45:09 +00:00
|
|
|
* @param {boolean} checked New checkbox state
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event select
|
2021-07-13 19:01:30 +00:00
|
|
|
* @param {string} paramName
|
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
|
|
|
// FIXME: This is a hack. Needs to be a subclass of Widget instead.
|
|
|
|
ve.ui.MWTemplateOutlineParameterCheckboxLayout.prototype.isDisabled = function () {
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @fires select
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateOutlineParameterCheckboxLayout.prototype.onClick = function () {
|
|
|
|
this.emit( 'select', this.getData() );
|
|
|
|
};
|
|
|
|
|
|
|
|
ve.ui.MWTemplateOutlineParameterCheckboxLayout.prototype.onKeyDown = function ( e ) {
|
|
|
|
if ( e.keyCode === OO.ui.Keys.ENTER ) {
|
|
|
|
this.emit( 'select', this.getData() );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ve.ui.MWTemplateOutlineParameterCheckboxLayout.prototype.onCheckboxKeyDown = function ( e ) {
|
|
|
|
if ( e.keyCode === OO.ui.Keys.ENTER ) {
|
|
|
|
this.fieldWidget.setSelected( true );
|
|
|
|
this.emit( 'select', this.getData() );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-06-29 19:45:09 +00:00
|
|
|
/**
|
|
|
|
* Handles a checkbox input widget change event {@see OO.ui.CheckboxInputWidget}.
|
|
|
|
*
|
|
|
|
* @param {boolean} value
|
|
|
|
* @fires change
|
|
|
|
*/
|
2021-08-09 16:35:53 +00:00
|
|
|
ve.ui.MWTemplateOutlineParameterCheckboxLayout.prototype.onCheckboxChange = function ( value ) {
|
2021-06-18 15:23:35 +00:00
|
|
|
this.emit( 'change', this.getData(), value );
|
2021-05-17 15:43:49 +00:00
|
|
|
};
|
|
|
|
|
2021-06-18 09:48:33 +00:00
|
|
|
ve.ui.MWTemplateOutlineParameterCheckboxLayout.prototype.onLabelClick = function () {
|
2021-08-09 16:35:53 +00:00
|
|
|
this.fieldWidget.setSelected( true );
|
2021-06-18 15:23:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ve.ui.MWTemplateOutlineParameterCheckboxLayout.prototype.setSelected = function ( state, internal ) {
|
2021-08-09 16:31:30 +00:00
|
|
|
this.fieldWidget.setSelected( state, internal );
|
2021-05-17 15:43:49 +00:00
|
|
|
};
|