* @cfg {string} [type='send_unselected_if_any'] Group type
* @cfg {string} [view='default'] Name of the display group this group
* is a part of.
- * @cfg {boolean} [isSticky] This group is using a 'sticky' default; meaning
- * that every time a value is changed, it becomes the new default
- * @cfg {boolean} [excludedFromSavedQueries] A specific requirement to exclude
- * this filter from saved queries. This is always true if the filter is 'sticky'
- * but can be used for non-sticky filters as an additional requirement. Similarly
- * to 'sticky' it works for the entire group as a whole.
+ * @cfg {boolean} [sticky] This group is 'sticky'. It is synchronized
+ * with a preference, does not participate in Saved Queries, and is
+ * not shown in the active filters area.
* @cfg {string} [title] Group title
* @cfg {boolean} [hidden] This group is hidden from the regular menu views
+ * and the active filters area.
* @cfg {boolean} [allowArbitrary] Allows for an arbitrary value to be added to the
* group from the URL, even if it wasn't initially set up.
* @cfg {number} [range] An object defining minimum and maximum values for numeric
this.name = name;
this.type = config.type || 'send_unselected_if_any';
this.view = config.view || 'default';
- this.sticky = !!config.isSticky;
- this.excludedFromSavedQueries = this.sticky || !!config.excludedFromSavedQueries;
+ this.sticky = !!config.sticky;
this.title = config.title || name;
this.hidden = !!config.hidden;
this.allowArbitrary = !!config.allowArbitrary;
description: filter.description || '',
labelPrefixKey: model.labelPrefixKey,
cssClass: filter.cssClass,
- identifiers: filter.identifiers
+ identifiers: filter.identifiers,
+ defaultHighlightColor: filter.defaultHighlightColor
} );
if ( filter.subset ) {
this.defaultParams[ this.getName() ] = defaultParam;
}
+ // add highlights to defaultParams
+ this.getItems().forEach( function ( filterItem ) {
+ if ( filterItem.isHighlighted() ) {
+ this.defaultParams[ filterItem.getName() + '_color' ] = filterItem.getHighlightColor();
+ }
+ }.bind( this ) );
+
// Store default filter state based on default params
this.defaultFilters = this.getFilterRepresentation( this.getDefaultParams() );
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
*
};
/**
- * Check whether the group value is excluded from saved queries
+ * 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.
*
- * @return {boolean} Group value is excluded from saved queries
+ * @param {string} value Given value
+ * @return {string} Corrected value
*/
- mw.rcfilters.dm.FilterGroup.prototype.isExcludedFromSavedQueries = function () {
- return this.excludedFromSavedQueries;
+ 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 ) );