- /**
- * Get an object representing the base state of parameters
- * and highlights.
- *
- * This is meant to make sure that the saved queries that are
- * in memory are always the same structure as what we would get
- * by calling the current model's "getSelectedState" and by checking
- * highlight items.
- *
- * In cases where a user saved a query when the system had a certain
- * set of params, and then a filter was added to the system, we want
- * to make sure that the stored queries can still be comparable to
- * the current state, which means that we need the base state for
- * two operations:
- *
- * - Saved queries are stored in "minimal" view (only changed params
- * are stored); When we initialize the system, we merge each minimal
- * query with the base state (using 'getMinimalParamList') so all
- * saved queries have the exact same structure as what we would get
- * by checking the getSelectedState of the filter.
- * - When we save the queries, we minimize the object to only represent
- * whatever has actually changed, rather than store the entire
- * object. To check what actually is different so we can store it,
- * we need to obtain a base state to compare against, this is
- * what #getMinimalParamList does
- *
- * @return {Object} Base parameter state
- */
- mw.rcfilters.dm.SavedQueriesModel.prototype.getBaseParamState = function () {
- var allParams,
- highlightedItems = {};
-
- if ( !this.baseParamState ) {
- allParams = this.filtersModel.getParametersFromFilters( {} );
-
- // Prepare highlights
- this.filtersModel.getItemsSupportingHighlights().forEach( function ( item ) {
- highlightedItems[ item.getName() + '_color' ] = null;
- } );
-
- this.baseParamState = {
- params: $.extend( true, { highlight: '0' }, allParams ),
- highlights: highlightedItems
- };
- }
-
- return this.baseParamState;
- };
-
- /**
- * Get an object that holds only the parameters and highlights that have
- * values different than the base value.
- *
- * This is the reverse of the normalization we do initially on loading and
- * initializing the saved queries model.
- *
- * @param {Object} valuesObject Object representing the state of both
- * filters and highlights in its normalized version, to be minimized.
- * @return {Object} Minimal filters and highlights list
- */
- mw.rcfilters.dm.SavedQueriesModel.prototype.getMinimalParamList = function ( valuesObject ) {
- var result = { params: {}, highlights: {} },
- baseState = this.getBaseParamState();
-
- // XOR results
- $.each( valuesObject.params, function ( name, value ) {
- if ( baseState.params !== undefined && baseState.params[ name ] !== value ) {
- result.params[ name ] = value;
- }
- } );
-
- $.each( valuesObject.highlights, function ( name, value ) {
- if ( baseState.highlights !== undefined && baseState.highlights[ name ] !== value ) {
- result.highlights[ name ] = value;
- }
- } );
-
- return result;
- };
-