Merge "RCFilters: Convert saved queries from filters to parameters"
[lhc/web/wiklou.git] / resources / src / mediawiki.rcfilters / dm / mw.rcfilters.dm.FiltersViewModel.js
index a8ee06b..5013c08 100644 (file)
                return result;
        };
 
+       /**
+        * Get the parameter names that represent filters that are excluded
+        * from saved queries.
+        *
+        * @return {string[]} Parameter names
+        */
+       mw.rcfilters.dm.FiltersViewModel.prototype.getExcludedParams = function () {
+               var result = [];
+
+               $.each( this.groups, function ( name, model ) {
+                       if ( model.isExcludedFromSavedQueries() ) {
+                               if ( model.isPerGroupRequestParameter() ) {
+                                       result.push( name );
+                               } else {
+                                       // Each filter is its own param
+                                       result = result.concat( model.getItems().map( function ( filterItem ) {
+                                               return filterItem.getParamName();
+                                       } ) );
+                               }
+                       }
+               } );
+
+               return result;
+       };
+
        /**
         * Analyze the groups and their filters and output an object representing
         * the state of the parameters they represent.
                return result;
        };
 
+       /**
+        * Get an array of currently applied highlight colors
+        *
+        * @return {string[]} Currently applied highlight colors
+        */
+       mw.rcfilters.dm.FiltersViewModel.prototype.getCurrentlyUsedHighlightColors = function () {
+               var result = [];
+
+               this.getHighlightedItems().forEach( function ( filterItem ) {
+                       var color = filterItem.getHighlightColor();
+
+                       if ( result.indexOf( color ) === -1 ) {
+                               result.push( color );
+                       }
+               } );
+
+               return result;
+       };
+
        /**
         * Sanitize value group of a string_option groups type
         * Remove duplicates and make sure to only use valid
                } );
        };
 
-       /**
-        * Check whether the default values of the filters are all false.
-        *
-        * @return {boolean} Default filters are all false
-        */
-       mw.rcfilters.dm.FiltersViewModel.prototype.areDefaultFiltersEmpty = function () {
-               var defaultFilters;
-
-               if ( this.defaultFiltersEmpty !== null ) {
-                       // We only need to do this test once,
-                       // because defaults are set once per session
-                       defaultFilters = this.getFiltersFromParameters( this.getDefaultParams() );
-                       this.defaultFiltersEmpty = Object.keys( defaultFilters ).every( function ( filterName ) {
-                               return !defaultFilters[ filterName ];
-                       } );
-               }
-
-               return this.defaultFiltersEmpty;
-       };
-
        /**
         * Get the item that matches the given name
         *
                enable = enable === undefined ? !this.highlightEnabled : enable;
 
                if ( this.highlightEnabled !== enable ) {
-                       this.highlightEnabled = enable;
-
+                       // HACK make sure highlights are disabled globally while we toggle on the items,
+                       // otherwise we'll call clearHighlight() and applyHighlight() many many times
+                       this.highlightEnabled = false;
                        this.getItems().forEach( function ( filterItem ) {
-                               filterItem.toggleHighlight( this.highlightEnabled );
-                       }.bind( this ) );
+                               filterItem.toggleHighlight( enable );
+                       } );
 
+                       this.highlightEnabled = enable;
                        this.emit( 'highlightChange', this.highlightEnabled );
                }
        };