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