2 * A widget representing a menu section for filter groups.
4 * @class mw.rcfilters.ui.FilterMenuSectionOptionWidget
6 * @extends OO.ui.MenuSectionOptionWidget
8 * @param {mw.rcfilters.Controller} controller RCFilters controller
9 * @param {mw.rcfilters.dm.FilterGroup} model Filter group model
10 * @param {Object} config Configuration object
11 * @param {jQuery} [config.$overlay] Overlay
13 const FilterMenuSectionOptionWidget = function MwRcfiltersUiFilterMenuSectionOptionWidget( controller, model, config ) {
14 const $header = $( '<div>' )
15 .addClass( 'mw-rcfilters-ui-filterMenuSectionOptionWidget-header' ),
16 $popupContent = $( '<div>' )
17 .addClass( 'mw-rcfilters-ui-filterMenuSectionOptionWidget-whatsThisButton-popup-content' );
19 config = config || {};
21 this.controller = controller;
23 this.$overlay = config.$overlay || this.$element;
26 FilterMenuSectionOptionWidget.super.call( this, Object.assign( {
27 label: this.model.getTitle(),
29 .addClass( 'mw-rcfilters-ui-filterMenuSectionOptionWidget-header-title' )
32 $header.append( this.$label );
34 if ( this.model.hasWhatsThis() ) {
35 const whatsThisMessages = this.model.getWhatsThis();
38 if ( whatsThisMessages.header ) {
40 ( new OO.ui.LabelWidget( {
41 // eslint-disable-next-line mediawiki/msg-doc
42 label: mw.msg( whatsThisMessages.header ),
43 classes: [ 'mw-rcfilters-ui-filterMenuSectionOptionWidget-whatsThisButton-popup-content-header' ]
47 if ( whatsThisMessages.body ) {
49 ( new OO.ui.LabelWidget( {
50 // eslint-disable-next-line mediawiki/msg-doc
51 label: mw.msg( whatsThisMessages.body ),
52 classes: [ 'mw-rcfilters-ui-filterMenuSectionOptionWidget-whatsThisButton-popup-content-body' ]
56 if ( whatsThisMessages.linkText && whatsThisMessages.url ) {
58 ( new OO.ui.ButtonWidget( {
60 flags: [ 'progressive' ],
61 href: whatsThisMessages.url,
62 // eslint-disable-next-line mediawiki/msg-doc
63 label: mw.msg( whatsThisMessages.linkText ),
64 classes: [ 'mw-rcfilters-ui-filterMenuSectionOptionWidget-whatsThisButton-popup-content-link' ]
70 this.whatsThisButton = new OO.ui.PopupButtonWidget( {
72 label: mw.msg( 'rcfilters-filterlist-whatsthis' ),
73 $overlay: this.$overlay,
74 classes: [ 'mw-rcfilters-ui-filterMenuSectionOptionWidget-whatsThisButton' ],
75 flags: [ 'progressive' ],
80 $content: $popupContent,
81 classes: [ 'mw-rcfilters-ui-filterMenuSectionOptionWidget-whatsThisButton-popup' ]
86 .append( this.whatsThisButton.$element );
90 this.model.connect( this, { update: 'updateUiBasedOnState' } );
93 // eslint-disable-next-line mediawiki/class-doc
95 .addClass( 'mw-rcfilters-ui-filterMenuSectionOptionWidget' )
96 .addClass( 'mw-rcfilters-ui-filterMenuSectionOptionWidget-name-' + this.model.getName() )
98 this.updateUiBasedOnState();
103 OO.inheritClass( FilterMenuSectionOptionWidget, OO.ui.MenuSectionOptionWidget );
108 * Respond to model update event
110 FilterMenuSectionOptionWidget.prototype.updateUiBasedOnState = function () {
111 this.$element.toggleClass(
112 'mw-rcfilters-ui-filterMenuSectionOptionWidget-active',
113 this.model.isActive()
115 this.toggle( this.model.isVisible() );
121 * @return {string} Group name
123 FilterMenuSectionOptionWidget.prototype.getName = function () {
124 return this.model.getName();
127 module.exports = FilterMenuSectionOptionWidget;