Merge "RCFilters: refactor highlight state"
[lhc/web/wiklou.git] / resources / src / mediawiki.rcfilters / ui / mw.rcfilters.ui.FilterMenuOptionWidget.js
index d235c39..926502d 100644 (file)
@@ -6,17 +6,22 @@
         *
         * @constructor
         * @param {mw.rcfilters.Controller} controller RCFilters controller
-        * @param {mw.rcfilters.dm.FilterItem} model Filter item model
+        * @param {mw.rcfilters.dm.FiltersViewModel} filtersViewModel
+        * @param {mw.rcfilters.dm.FilterItem} invertModel
+        * @param {mw.rcfilters.dm.FilterItem} itemModel Filter item model
         * @param {Object} config Configuration object
         */
-       mw.rcfilters.ui.FilterMenuOptionWidget = function MwRcfiltersUiFilterMenuOptionWidget( controller, model, config ) {
+       mw.rcfilters.ui.FilterMenuOptionWidget = function MwRcfiltersUiFilterMenuOptionWidget(
+               controller, filtersViewModel, invertModel, itemModel, config
+       ) {
                config = config || {};
 
                this.controller = controller;
-               this.model = model;
+               this.invertModel = invertModel;
+               this.model = itemModel;
 
                // Parent
-               mw.rcfilters.ui.FilterMenuOptionWidget.parent.call( this, controller, model, config );
+               mw.rcfilters.ui.FilterMenuOptionWidget.parent.call( this, controller, filtersViewModel, this.invertModel, itemModel, config );
 
                // Event
                this.model.getGroupModel().connect( this, { update: 'onGroupModelUpdate' } );
@@ -38,9 +43,9 @@
        /**
         * @inheritdoc
         */
-       mw.rcfilters.ui.FilterMenuOptionWidget.prototype.onModelUpdate = function () {
+       mw.rcfilters.ui.FilterMenuOptionWidget.prototype.updateUiBasedOnState = function () {
                // Parent
-               mw.rcfilters.ui.FilterMenuOptionWidget.parent.prototype.onModelUpdate.call( this );
+               mw.rcfilters.ui.FilterMenuOptionWidget.parent.prototype.updateUiBasedOnState.call( this );
 
                this.setCurrentMuteState();
        };
         * Set the current muted view of the widget based on its state
         */
        mw.rcfilters.ui.FilterMenuOptionWidget.prototype.setCurrentMuteState = function () {
-               this.setFlags( {
-                       muted: (
-                               this.model.isConflicted() ||
-                               (
-                                       // Item is also muted when any of the items in its group is active
-                                       this.model.getGroupModel().isActive() &&
-                                       // But it isn't selected
-                                       !this.model.isSelected() &&
-                                       // And also not included
-                                       !this.model.isIncluded()
+               if (
+                       this.model.getGroupModel().getView() === 'namespaces' &&
+                       this.invertModel.isSelected()
+               ) {
+                       // This is an inverted behavior than the other rules, specifically
+                       // for inverted namespaces
+                       this.setFlags( {
+                               muted: this.model.isSelected()
+                       } );
+               } else {
+                       this.setFlags( {
+                               muted: (
+                                       this.model.isConflicted() ||
+                                       (
+                                               // Item is also muted when any of the items in its group is active
+                                               this.model.getGroupModel().isActive() &&
+                                               // But it isn't selected
+                                               !this.model.isSelected() &&
+                                               // And also not included
+                                               !this.model.isIncluded()
+                                       )
                                )
-                       )
-               } );
+                       } );
+               }
        };
 }( mediaWiki ) );