Localisation updates from https://translatewiki.net.
[mediawiki.git] / resources / src / mediawiki.rcfilters / ui / FilterMenuOptionWidget.js
blob505cda8e69b5262de1f0032ade37884abe50f910
1 const ItemMenuOptionWidget = require( './ItemMenuOptionWidget.js' );
3 /**
4  * A widget representing a single toggle filter.
5  *
6  * @class mw.rcfilters.ui.FilterMenuOptionWidget
7  * @ignore
8  * @extends mw.rcfilters.ui.ItemMenuOptionWidget
9  *
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
16  */
17 const FilterMenuOptionWidget = function MwRcfiltersUiFilterMenuOptionWidget(
18         controller, filtersViewModel, invertModel, itemModel, highlightPopup, config
19 ) {
20         config = config || {};
22         this.controller = controller;
23         this.invertModel = invertModel;
24         this.model = itemModel;
26         // Parent
27         FilterMenuOptionWidget.super.call( this, controller, filtersViewModel, this.invertModel, itemModel, highlightPopup, config );
29         // Event
30         this.model.getGroupModel().connect( this, { update: 'onGroupModelUpdate' } );
32         this.$element
33                 .addClass( 'mw-rcfilters-ui-filterMenuOptionWidget' );
36 /* Initialization */
37 OO.inheritClass( FilterMenuOptionWidget, ItemMenuOptionWidget );
39 /* Static properties */
41 // We do our own scrolling to top
42 FilterMenuOptionWidget.static.scrollIntoViewOnSelect = false;
44 /* Methods */
46 /**
47  * @inheritdoc
48  */
49 FilterMenuOptionWidget.prototype.updateUiBasedOnState = function () {
50         // Parent
51         FilterMenuOptionWidget.super.prototype.updateUiBasedOnState.call( this );
53         this.setCurrentMuteState();
56 /**
57  * Respond to item group model update event
58  */
59 FilterMenuOptionWidget.prototype.onGroupModelUpdate = function () {
60         this.setCurrentMuteState();
63 /**
64  * Set the current muted view of the widget based on its state
65  */
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
70                 this.setFlags( {
71                         muted: this.model.isSelected()
72                 } );
73         } else {
74                 this.setFlags( {
75                         muted: (
76                                 this.model.isConflicted() ||
77                                 (
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()
84                                 )
85                         )
86                 } );
87         }
90 module.exports = FilterMenuOptionWidget;