X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=resources%2Fsrc%2Fmediawiki.rcfilters%2Fdm%2Fmw.rcfilters.dm.FilterGroup.js;h=b17355f5bab70ee303326ea7cf4ccd510b4f59fb;hb=31bc1e9c3546a97220cd7c550c57fad3d4f4304d;hp=4dc86f6f657dd872891b1f18d83da920db46377c;hpb=d19826aa35b206847a568a4b2c1c9ffaa615fca5;p=lhc%2Fweb%2Fwiklou.git diff --git a/resources/src/mediawiki.rcfilters/dm/mw.rcfilters.dm.FilterGroup.js b/resources/src/mediawiki.rcfilters/dm/mw.rcfilters.dm.FilterGroup.js index 4dc86f6f65..b17355f5ba 100644 --- a/resources/src/mediawiki.rcfilters/dm/mw.rcfilters.dm.FilterGroup.js +++ b/resources/src/mediawiki.rcfilters/dm/mw.rcfilters.dm.FilterGroup.js @@ -93,6 +93,7 @@ */ mw.rcfilters.dm.FilterGroup.prototype.initializeFilters = function ( filterDefinition, groupDefault ) { var defaultParam, + anyHighlighted, supersetMap = {}, model = this, items = []; @@ -106,7 +107,8 @@ description: filter.description || '', labelPrefixKey: model.labelPrefixKey, cssClass: filter.cssClass, - identifiers: filter.identifiers + identifiers: filter.identifiers, + defaultHighlightColor: filter.defaultHighlightColor } ); if ( filter.subset ) { @@ -188,6 +190,18 @@ this.defaultParams[ this.getName() ] = defaultParam; } + // add highlights to defaultParams + anyHighlighted = false; + this.getItems().forEach( function ( filterItem ) { + if ( filterItem.isHighlighted() ) { + anyHighlighted = true; + this.defaultParams[ filterItem.getName() + '_color' ] = filterItem.getHighlightColor(); + } + }.bind( this ) ); + if ( anyHighlighted ) { + this.defaultParams.highlight = '1'; + } + // Store default filter state based on default params this.defaultFilters = this.getFilterRepresentation( this.getDefaultParams() ); @@ -816,6 +830,19 @@ return this.type; }; + /** + * Check whether this group is represented by a single parameter + * or whether each item is its own parameter + * + * @return {boolean} This group is a single parameter + */ + mw.rcfilters.dm.FilterGroup.prototype.isPerGroupRequestParameter = function () { + return ( + this.getType() === 'string_options' || + this.getType() === 'single_option' + ); + }; + /** * Get display group * @@ -889,4 +916,35 @@ mw.rcfilters.dm.FilterGroup.prototype.isExcludedFromSavedQueries = function () { return this.excludedFromSavedQueries; }; + + /** + * Normalize a value given to this group. This is mostly for correcting + * arbitrary values for 'single option' groups, given by the user settings + * or the URL that can go outside the limits that are allowed. + * + * @param {string} value Given value + * @return {string} Corrected value + */ + mw.rcfilters.dm.FilterGroup.prototype.normalizeArbitraryValue = function ( value ) { + if ( + this.getType() === 'single_option' && + this.isAllowArbitrary() + ) { + if ( + this.getMaxValue() !== null && + value > this.getMaxValue() + ) { + // Change the value to the actual max value + return String( this.getMaxValue() ); + } else if ( + this.getMinValue() !== null && + value < this.getMinValue() + ) { + // Change the value to the actual min value + return String( this.getMinValue() ); + } + } + + return value; + }; }( mediaWiki ) );