1 const ItemMenuOptionWidget = require( './ItemMenuOptionWidget.js' );
4 * A widget representing a single toggle filter.
6 * @class mw.rcfilters.ui.FilterMenuOptionWidget
8 * @extends mw.rcfilters.ui.ItemMenuOptionWidget
10 * @param {mw.rcfilters.Controller} controller RCFilters controller
11 * @param {mw.rcfilters.dm.FiltersViewModel} filtersViewModel
12 * @param {mw.rcfilters.dm.FilterItem|null} invertModel
13 * @param {mw.rcfilters.dm.FilterItem} itemModel Filter item model
14 * @param {mw.rcfilters.ui.HighlightPopupWidget} highlightPopup Shared highlight color picker popup
15 * @param {Object} config Configuration object
17 const FilterMenuOptionWidget = function MwRcfiltersUiFilterMenuOptionWidget(
18 controller, filtersViewModel, invertModel, itemModel, highlightPopup, config
20 config = config || {};
22 this.controller = controller;
23 this.invertModel = invertModel;
24 this.model = itemModel;
27 FilterMenuOptionWidget.super.call( this, controller, filtersViewModel, this.invertModel, itemModel, highlightPopup, config );
30 this.model.getGroupModel().connect( this, { update: 'onGroupModelUpdate' } );
33 .addClass( 'mw-rcfilters-ui-filterMenuOptionWidget' );
37 OO.inheritClass( FilterMenuOptionWidget, ItemMenuOptionWidget );
39 /* Static properties */
41 // We do our own scrolling to top
42 FilterMenuOptionWidget.static.scrollIntoViewOnSelect = false;
49 FilterMenuOptionWidget.prototype.updateUiBasedOnState = function () {
51 FilterMenuOptionWidget.super.prototype.updateUiBasedOnState.call( this );
53 this.setCurrentMuteState();
57 * Respond to item group model update event
59 FilterMenuOptionWidget.prototype.onGroupModelUpdate = function () {
60 this.setCurrentMuteState();
64 * Set the current muted view of the widget based on its state
66 FilterMenuOptionWidget.prototype.setCurrentMuteState = function () {
67 if ( this.invertModel && this.invertModel.isSelected() ) {
68 // This is an inverted behavior than the other rules, specifically
69 // for inverted namespaces
71 muted: this.model.isSelected()
76 this.model.isConflicted() ||
78 // Item is also muted when any of the items in its group is active
79 this.model.getGroupModel().isActive() &&
80 // But it isn't selected
81 !this.model.isSelected() &&
82 // And also not included
83 !this.model.isIncluded()
90 module.exports = FilterMenuOptionWidget;