Merge "registration: Only allow one extension to set a specific config setting"
[lhc/web/wiklou.git] / resources / src / mediawiki.rcfilters / ui / mw.rcfilters.ui.FilterMenuOptionWidget.js
1 ( function ( mw ) {
2 /**
3 * A widget representing a single toggle filter
4 *
5 * @extends mw.rcfilters.ui.ItemMenuOptionWidget
6 *
7 * @constructor
8 * @param {mw.rcfilters.Controller} controller RCFilters controller
9 * @param {mw.rcfilters.dm.FiltersViewModel} filtersViewModel
10 * @param {mw.rcfilters.dm.FilterItem} invertModel
11 * @param {mw.rcfilters.dm.FilterItem} itemModel Filter item model
12 * @param {Object} config Configuration object
13 */
14 mw.rcfilters.ui.FilterMenuOptionWidget = function MwRcfiltersUiFilterMenuOptionWidget(
15 controller, filtersViewModel, invertModel, itemModel, config
16 ) {
17 config = config || {};
18
19 this.controller = controller;
20 this.invertModel = invertModel;
21 this.model = itemModel;
22
23 // Parent
24 mw.rcfilters.ui.FilterMenuOptionWidget.parent.call( this, controller, filtersViewModel, this.invertModel, itemModel, config );
25
26 // Event
27 this.model.getGroupModel().connect( this, { update: 'onGroupModelUpdate' } );
28
29 this.$element
30 .addClass( 'mw-rcfilters-ui-filterMenuOptionWidget' );
31 };
32
33 /* Initialization */
34 OO.inheritClass( mw.rcfilters.ui.FilterMenuOptionWidget, mw.rcfilters.ui.ItemMenuOptionWidget );
35
36 /* Static properties */
37
38 // We do our own scrolling to top
39 mw.rcfilters.ui.FilterMenuOptionWidget.static.scrollIntoViewOnSelect = false;
40
41 /* Methods */
42
43 /**
44 * @inheritdoc
45 */
46 mw.rcfilters.ui.FilterMenuOptionWidget.prototype.updateUiBasedOnState = function () {
47 // Parent
48 mw.rcfilters.ui.FilterMenuOptionWidget.parent.prototype.updateUiBasedOnState.call( this );
49
50 this.setCurrentMuteState();
51 };
52
53 /**
54 * Respond to item group model update event
55 */
56 mw.rcfilters.ui.FilterMenuOptionWidget.prototype.onGroupModelUpdate = function () {
57 this.setCurrentMuteState();
58 };
59
60 /**
61 * Set the current muted view of the widget based on its state
62 */
63 mw.rcfilters.ui.FilterMenuOptionWidget.prototype.setCurrentMuteState = function () {
64 if (
65 this.model.getGroupModel().getView() === 'namespaces' &&
66 this.invertModel.isSelected()
67 ) {
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 }
88 };
89 }( mediaWiki ) );