mediawiki-extensions-Visual.../modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlinePartWidget.js
Thiemo Kreuz 544bd5688c Allow selecting top-level parts in the new sidebar
This is mostly, if not exclusively visual, at the moment. The
actual state is still managed by the old sidebar.

I made the element OptionWidgets for convenience. This gives us
all the functionality we need (primarily setSelected and
isSelected), without to much clutter. However, I didn't made
the container a SelectWidget. This comes with to much stuff we
don't need at this level, e.g. cursor key navigation.

Bug: T285323
Bug: T289043
Change-Id: I20dbd2ba23ceaa9125947b25e037c0bb3c91a471
2021-08-27 18:22:37 +02:00

67 lines
1.9 KiB
JavaScript

/**
* Common base class for top-level items (a.k.a. "parts") in the template editor sidebar. Subclasses
* should exist for all subclasses of {@see ve.dm.MWTransclusionPartModel}:
* - {@see ve.dm.MWTemplateModel}
* - {@see ve.dm.MWTemplatePlaceholderModel}
* - {@see ve.dm.MWTransclusionContentModel}
*
* This is inspired by and meant to replace {@see OO.ui.DecoratedOptionWidget} in the context of the
* template dialog. Also see {@see OO.ui.ButtonWidget} for inspiration.
*
* @abstract
* @class
* @extends OO.ui.Widget
*
* @constructor
* @param {ve.dm.MWTransclusionPartModel} part
* @param {Object} config
* @cfg {string} [icon='']
* @cfg {string} label
*/
ve.ui.MWTransclusionOutlinePartWidget = function VeUiMWTransclusionOutlinePartWidget( part, config ) {
// Parent constructor
ve.ui.MWTransclusionOutlinePartWidget.super.call( this, ve.extendObject( config, {
data: part.getId()
} ) );
this.header = new ve.ui.MWTransclusionOutlineButtonWidget( config )
.connect( this, { click: [ 'emit', 'selectPart', part.getId() ] } );
this.$element
.addClass( 've-ui-mwTransclusionOutlinePartWidget' )
.append( this.header.$element );
};
/* Inheritance */
OO.inheritClass( ve.ui.MWTransclusionOutlinePartWidget, OO.ui.Widget );
/* Events */
/**
* @event focusPart
* @param {string} partId Unique id of the part, e.g. something "part_1" or "part_1/param1".
*/
/* Methods */
/**
* Convenience method, modelled after {@see OO.ui.OptionWidget}, but this isn't one.
*
* @return {boolean}
*/
ve.ui.MWTransclusionOutlinePartWidget.prototype.isSelected = function () {
return this.header.isSelected();
};
/**
* Convenience method, modelled after {@see OO.ui.OptionWidget}, but this isn't one.
*
* @param {boolean} state
*/
ve.ui.MWTransclusionOutlinePartWidget.prototype.setSelected = function ( state ) {
this.header
.setSelected( state )
.setFlags( { progressive: state } );
};