Merge "Align "What's this" vertically"
[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.FilterItem} model Filter item model
10 * @param {Object} config Configuration object
11 */
12 mw.rcfilters.ui.FilterMenuOptionWidget = function MwRcfiltersUiFilterMenuOptionWidget( controller, model, config ) {
13 config = config || {};
14
15 this.controller = controller;
16 this.model = model;
17
18 // Parent
19 mw.rcfilters.ui.FilterMenuOptionWidget.parent.call( this, controller, model, config );
20
21 // Event
22 this.model.getGroupModel().connect( this, { update: 'onGroupModelUpdate' } );
23
24 this.$element
25 .addClass( 'mw-rcfilters-ui-filterMenuOptionWidget' );
26 };
27
28 /* Initialization */
29 OO.inheritClass( mw.rcfilters.ui.FilterMenuOptionWidget, mw.rcfilters.ui.ItemMenuOptionWidget );
30
31 /* Static properties */
32
33 // We do our own scrolling to top
34 mw.rcfilters.ui.FilterMenuOptionWidget.static.scrollIntoViewOnSelect = false;
35
36 /* Methods */
37
38 /**
39 * @inheritdoc
40 */
41 mw.rcfilters.ui.FilterMenuOptionWidget.prototype.onModelUpdate = function () {
42 // Parent
43 mw.rcfilters.ui.FilterMenuOptionWidget.parent.prototype.onModelUpdate.call( this );
44
45 this.setCurrentMuteState();
46 };
47
48 /**
49 * Respond to item group model update event
50 */
51 mw.rcfilters.ui.FilterMenuOptionWidget.prototype.onGroupModelUpdate = function () {
52 this.setCurrentMuteState();
53 };
54
55 /**
56 * Set the current muted view of the widget based on its state
57 */
58 mw.rcfilters.ui.FilterMenuOptionWidget.prototype.setCurrentMuteState = function () {
59 if (
60 this.model.getGroupModel().getView() === 'namespaces' &&
61 this.model.isInverted()
62 ) {
63 // This is an inverted behavior than the other rules, specifically
64 // for inverted namespaces
65 this.setFlags( {
66 muted: this.model.isSelected()
67 } );
68 } else {
69 this.setFlags( {
70 muted: (
71 this.model.isConflicted() ||
72 (
73 // Item is also muted when any of the items in its group is active
74 this.model.getGroupModel().isActive() &&
75 // But it isn't selected
76 !this.model.isSelected() &&
77 // And also not included
78 !this.model.isIncluded()
79 )
80 )
81 } );
82 }
83 };
84 }( mediaWiki ) );