3 * View model for a filter group
5 * @mixins OO.EventEmitter
6 * @mixins OO.EmitterList
9 * @param {string} name Group name
10 * @param {Object} [config] Configuration options
11 * @cfg {string} [type='send_unselected_if_any'] Group type
12 * @cfg {string} [view='default'] Name of the display group this group
14 * @cfg {boolean} [sticky] This group is 'sticky'. It is synchronized
15 * with a preference, does not participate in Saved Queries, and is
16 * not shown in the active filters area.
17 * @cfg {string} [title] Group title
18 * @cfg {boolean} [hidden] This group is hidden from the regular menu views
19 * and the active filters area.
20 * @cfg {boolean} [allowArbitrary] Allows for an arbitrary value to be added to the
21 * group from the URL, even if it wasn't initially set up.
22 * @cfg {number} [range] An object defining minimum and maximum values for numeric
23 * groups. { min: x, max: y }
24 * @cfg {number} [minValue] Minimum value for numeric groups
25 * @cfg {string} [separator='|'] Value separator for 'string_options' groups
26 * @cfg {boolean} [active] Group is active
27 * @cfg {boolean} [fullCoverage] This filters in this group collectively cover all results
28 * @cfg {Object} [conflicts] Defines the conflicts for this filter group
29 * @cfg {string|Object} [labelPrefixKey] An i18n key defining the prefix label for this
30 * group. If the prefix has 'invert' state, the parameter is expected to be an object
31 * with 'default' and 'inverted' as keys.
32 * @cfg {Object} [whatsThis] Defines the messages that should appear for the 'what's this' popup
33 * @cfg {string} [whatsThis.header] The header of the whatsThis popup message
34 * @cfg {string} [whatsThis.body] The body of the whatsThis popup message
35 * @cfg {string} [whatsThis.url] The url for the link in the whatsThis popup message
36 * @cfg {string} [whatsThis.linkMessage] The text for the link in the whatsThis popup message
38 mw
.rcfilters
.dm
.FilterGroup
= function MwRcfiltersDmFilterGroup( name
, config
) {
39 config
= config
|| {};
42 OO
.EventEmitter
.call( this );
43 OO
.EmitterList
.call( this );
46 this.type
= config
.type
|| 'send_unselected_if_any';
47 this.view
= config
.view
|| 'default';
48 this.sticky
= !!config
.sticky
;
49 this.title
= config
.title
|| name
;
50 this.hidden
= !!config
.hidden
;
51 this.allowArbitrary
= !!config
.allowArbitrary
;
52 this.numericRange
= config
.range
;
53 this.separator
= config
.separator
|| '|';
54 this.labelPrefixKey
= config
.labelPrefixKey
;
56 this.currSelected
= null;
57 this.active
= !!config
.active
;
58 this.fullCoverage
= !!config
.fullCoverage
;
60 this.whatsThis
= config
.whatsThis
|| {};
62 this.conflicts
= config
.conflicts
|| {};
63 this.defaultParams
= {};
64 this.defaultFilters
= {};
66 this.aggregate( { update
: 'filterItemUpdate' } );
67 this.connect( this, { filterItemUpdate
: 'onFilterItemUpdate' } );
71 OO
.initClass( mw
.rcfilters
.dm
.FilterGroup
);
72 OO
.mixinClass( mw
.rcfilters
.dm
.FilterGroup
, OO
.EventEmitter
);
73 OO
.mixinClass( mw
.rcfilters
.dm
.FilterGroup
, OO
.EmitterList
);
80 * Group state has been updated
86 * Initialize the group and create its filter items
88 * @param {Object} filterDefinition Filter definition for this group
89 * @param {string|Object} [groupDefault] Definition of the group default
91 mw
.rcfilters
.dm
.FilterGroup
.prototype.initializeFilters = function ( filterDefinition
, groupDefault
) {
97 filterDefinition
.forEach( function ( filter
) {
98 // Instantiate an item
100 filterItem
= new mw
.rcfilters
.dm
.FilterItem( filter
.name
, model
, {
101 group
: model
.getName(),
102 label
: filter
.label
|| filter
.name
,
103 description
: filter
.description
|| '',
104 labelPrefixKey
: model
.labelPrefixKey
,
105 cssClass
: filter
.cssClass
,
106 identifiers
: filter
.identifiers
,
107 defaultHighlightColor
: filter
.defaultHighlightColor
110 if ( filter
.subset
) {
111 filter
.subset
= filter
.subset
.map( function ( el
) {
117 filter
.subset
.forEach( function ( subsetFilterName
) { // eslint-disable-line no-loop-func
118 // Subsets (unlike conflicts) are always inside the same group
119 // We can re-map the names of the filters we are getting from
120 // the subsets with the group prefix
121 var subsetName
= model
.getPrefixedName( subsetFilterName
);
122 // For convenience, we should store each filter's "supersets" -- these are
123 // the filters that have that item in their subset list. This will just
124 // make it easier to go through whether the item has any other items
125 // that affect it (and are selected) at any given time
126 supersetMap
[ subsetName
] = supersetMap
[ subsetName
] || [];
127 mw
.rcfilters
.utils
.addArrayElementsUnique(
128 supersetMap
[ subsetName
],
132 // Translate subset param name to add the group name, so we
133 // get consistent naming. We know that subsets are only within
135 subsetNames
.push( subsetName
);
138 // Set translated subset
139 filterItem
.setSubset( subsetNames
);
142 items
.push( filterItem
);
144 // Store default parameter state; in this case, default is defined per filter
146 model
.getType() === 'send_unselected_if_any' ||
147 model
.getType() === 'boolean'
149 // Store the default parameter state
150 // For this group type, parameter values are direct
151 // We need to convert from a boolean to a string ('1' and '0')
152 model
.defaultParams
[ filter
.name
] = String( Number( filter
.default || 0 ) );
157 this.addItems( items
);
159 // Now that we have all items, we can apply the superset map
160 this.getItems().forEach( function ( filterItem
) {
161 filterItem
.setSuperset( supersetMap
[ filterItem
.getName() ] );
164 // Store default parameter state; in this case, default is defined per the
165 // entire group, given by groupDefault method parameter
166 if ( this.getType() === 'string_options' ) {
167 // Store the default parameter group state
168 // For this group, the parameter is group name and value is the names
170 this.defaultParams
[ this.getName() ] = mw
.rcfilters
.utils
.normalizeParamOptions(
173 groupDefault
.split( this.getSeparator() ) :
176 this.getItems().map( function ( item
) {
177 return item
.getParamName();
179 ).join( this.getSeparator() );
180 } else if ( this.getType() === 'single_option' ) {
181 defaultParam
= groupDefault
!== undefined ?
182 groupDefault
: this.getItems()[ 0 ].getParamName();
184 // For this group, the parameter is the group name,
185 // and a single item can be selected: default or first item
186 this.defaultParams
[ this.getName() ] = defaultParam
;
189 // add highlights to defaultParams
190 this.getItems().forEach( function ( filterItem
) {
191 if ( filterItem
.isHighlighted() ) {
192 this.defaultParams
[ filterItem
.getName() + '_color' ] = filterItem
.getHighlightColor();
196 // Store default filter state based on default params
197 this.defaultFilters
= this.getFilterRepresentation( this.getDefaultParams() );
199 // Check for filters that should be initially selected by their default value
200 if ( this.isSticky() ) {
201 $.each( this.defaultFilters
, function ( filterName
, filterValue
) {
202 model
.getItemByName( filterName
).toggleSelected( filterValue
);
206 // Verify that single_option group has at least one item selected
208 this.getType() === 'single_option' &&
209 this.getSelectedItems().length
=== 0
211 defaultParam
= groupDefault
!== undefined ?
212 groupDefault
: this.getItems()[ 0 ].getParamName();
214 // Single option means there must be a single option
215 // selected, so we have to either select the default
216 // or select the first option
217 this.selectItemByParamName( defaultParam
);
222 * Respond to filterItem update event
224 * @param {mw.rcfilters.dm.FilterItem} item Updated filter item
227 mw
.rcfilters
.dm
.FilterGroup
.prototype.onFilterItemUpdate = function ( item
) {
230 active
= this.areAnySelected(),
233 if ( this.getType() === 'single_option' ) {
234 // This group must have one item selected always
235 // and must never have more than one item selected at a time
236 if ( this.getSelectedItems().length
=== 0 ) {
237 // Nothing is selected anymore
238 // Select the default or the first item
239 this.currSelected
= this.getItemByParamName( this.defaultParams
[ this.getName() ] ) ||
240 this.getItems()[ 0 ];
241 this.currSelected
.toggleSelected( true );
243 } else if ( this.getSelectedItems().length
> 1 ) {
244 // There is more than one item selected
245 // This should only happen if the item given
246 // is the one that is selected, so unselect
247 // all items that is not it
248 this.getSelectedItems().forEach( function ( itemModel
) {
249 // Note that in case the given item is actually
250 // not selected, this loop will end up unselecting
251 // all items, which would trigger the case above
252 // when the last item is unselected anyways
253 var selected
= itemModel
.getName() === item
.getName() &&
256 itemModel
.toggleSelected( selected
);
258 model
.currSelected
= itemModel
;
267 this.active
!== active
||
268 this.currSelected
!== item
270 if ( this.isSticky() ) {
271 // If this group is sticky, then change the default according to the
272 // current selection.
273 this.defaultParams
= this.getParamRepresentation( this.getSelectedState() );
276 this.active
= active
;
277 this.currSelected
= item
;
279 this.emit( 'update' );
284 * Get group active state
286 * @return {boolean} Active state
288 mw
.rcfilters
.dm
.FilterGroup
.prototype.isActive = function () {
293 * Get group hidden state
295 * @return {boolean} Hidden state
297 mw
.rcfilters
.dm
.FilterGroup
.prototype.isHidden = function () {
302 * Get group allow arbitrary state
304 * @return {boolean} Group allows an arbitrary value from the URL
306 mw
.rcfilters
.dm
.FilterGroup
.prototype.isAllowArbitrary = function () {
307 return this.allowArbitrary
;
311 * Get group maximum value for numeric groups
313 * @return {number|null} Group max value
315 mw
.rcfilters
.dm
.FilterGroup
.prototype.getMaxValue = function () {
316 return this.numericRange
&& this.numericRange
.max
!== undefined ?
317 this.numericRange
.max
: null;
321 * Get group minimum value for numeric groups
323 * @return {number|null} Group max value
325 mw
.rcfilters
.dm
.FilterGroup
.prototype.getMinValue = function () {
326 return this.numericRange
&& this.numericRange
.min
!== undefined ?
327 this.numericRange
.min
: null;
333 * @return {string} Group name
335 mw
.rcfilters
.dm
.FilterGroup
.prototype.getName = function () {
340 * Get the default param state of this group
342 * @return {Object} Default param state
344 mw
.rcfilters
.dm
.FilterGroup
.prototype.getDefaultParams = function () {
345 return this.defaultParams
;
349 * Get the default filter state of this group
351 * @return {Object} Default filter state
353 mw
.rcfilters
.dm
.FilterGroup
.prototype.getDefaultFilters = function () {
354 return this.defaultFilters
;
358 * This is for a single_option and string_options group types
359 * it returns the value of the default
361 * @return {string} Value of the default
363 mw
.rcfilters
.dm
.FilterGroup
.prototype.getDefaulParamValue = function () {
364 return this.defaultParams
[ this.getName() ];
367 * Get the messags defining the 'whats this' popup for this group
369 * @return {Object} What's this messages
371 mw
.rcfilters
.dm
.FilterGroup
.prototype.getWhatsThis = function () {
372 return this.whatsThis
;
376 * Check whether this group has a 'what's this' message
378 * @return {boolean} This group has a what's this message
380 mw
.rcfilters
.dm
.FilterGroup
.prototype.hasWhatsThis = function () {
381 return !!this.whatsThis
.body
;
385 * Get the conflicts associated with the entire group.
386 * Conflict object is set up by filter name keys and conflict
387 * definition. For example:
391 * filter: filterName,
397 * filter: filterName2,
402 * @return {Object} Conflict definition
404 mw
.rcfilters
.dm
.FilterGroup
.prototype.getConflicts = function () {
405 return this.conflicts
;
409 * Set conflicts for this group. See #getConflicts for the expected
410 * structure of the definition.
412 * @param {Object} conflicts Conflicts for this group
414 mw
.rcfilters
.dm
.FilterGroup
.prototype.setConflicts = function ( conflicts
) {
415 this.conflicts
= conflicts
;
419 * Set conflicts for each filter item in the group based on the
422 * @param {Object} conflicts Object representing the conflict map,
423 * keyed by the item name, where its value is an object for all its conflicts
425 mw
.rcfilters
.dm
.FilterGroup
.prototype.setFilterConflicts = function ( conflicts
) {
426 this.getItems().forEach( function ( filterItem
) {
427 if ( conflicts
[ filterItem
.getName() ] ) {
428 filterItem
.setConflicts( conflicts
[ filterItem
.getName() ] );
434 * Check whether this item has a potential conflict with the given item
436 * This checks whether the given item is in the list of conflicts of
437 * the current item, but makes no judgment about whether the conflict
438 * is currently at play (either one of the items may not be selected)
440 * @param {mw.rcfilters.dm.FilterItem} filterItem Filter item
441 * @return {boolean} This item has a conflict with the given item
443 mw
.rcfilters
.dm
.FilterGroup
.prototype.existsInConflicts = function ( filterItem
) {
444 return Object
.prototype.hasOwnProperty
.call( this.getConflicts(), filterItem
.getName() );
448 * Check whether there are any items selected
450 * @return {boolean} Any items in the group are selected
452 mw
.rcfilters
.dm
.FilterGroup
.prototype.areAnySelected = function () {
453 return this.getItems().some( function ( filterItem
) {
454 return filterItem
.isSelected();
459 * Check whether all items selected
461 * @return {boolean} All items are selected
463 mw
.rcfilters
.dm
.FilterGroup
.prototype.areAllSelected = function () {
467 this.getItems().forEach( function ( filterItem
) {
468 if ( filterItem
.isSelected() ) {
469 selected
.push( filterItem
);
471 unselected
.push( filterItem
);
475 if ( unselected
.length
=== 0 ) {
479 // check if every unselected is a subset of a selected
480 return unselected
.every( function ( unselectedFilterItem
) {
481 return selected
.some( function ( selectedFilterItem
) {
482 return selectedFilterItem
.existsInSubset( unselectedFilterItem
.getName() );
488 * Get all selected items in this group
490 * @param {mw.rcfilters.dm.FilterItem} [excludeItem] Item to exclude from the list
491 * @return {mw.rcfilters.dm.FilterItem[]} Selected items
493 mw
.rcfilters
.dm
.FilterGroup
.prototype.getSelectedItems = function ( excludeItem
) {
494 var excludeName
= ( excludeItem
&& excludeItem
.getName() ) || '';
496 return this.getItems().filter( function ( item
) {
497 return item
.getName() !== excludeName
&& item
.isSelected();
502 * Check whether all selected items are in conflict with the given item
504 * @param {mw.rcfilters.dm.FilterItem} filterItem Filter item to test
505 * @return {boolean} All selected items are in conflict with this item
507 mw
.rcfilters
.dm
.FilterGroup
.prototype.areAllSelectedInConflictWith = function ( filterItem
) {
508 var selectedItems
= this.getSelectedItems( filterItem
);
510 return selectedItems
.length
> 0 &&
512 // The group as a whole is in conflict with this item
513 this.existsInConflicts( filterItem
) ||
514 // All selected items are in conflict individually
515 selectedItems
.every( function ( selectedFilter
) {
516 return selectedFilter
.existsInConflicts( filterItem
);
522 * Check whether any of the selected items are in conflict with the given item
524 * @param {mw.rcfilters.dm.FilterItem} filterItem Filter item to test
525 * @return {boolean} Any of the selected items are in conflict with this item
527 mw
.rcfilters
.dm
.FilterGroup
.prototype.areAnySelectedInConflictWith = function ( filterItem
) {
528 var selectedItems
= this.getSelectedItems( filterItem
);
530 return selectedItems
.length
> 0 && (
531 // The group as a whole is in conflict with this item
532 this.existsInConflicts( filterItem
) ||
533 // Any selected items are in conflict individually
534 selectedItems
.some( function ( selectedFilter
) {
535 return selectedFilter
.existsInConflicts( filterItem
);
541 * Get the parameter representation from this group
543 * @param {Object} [filterRepresentation] An object defining the state
544 * of the filters in this group, keyed by their name and current selected
546 * @return {Object} Parameter representation
548 mw
.rcfilters
.dm
.FilterGroup
.prototype.getParamRepresentation = function ( filterRepresentation
) {
550 areAnySelected
= false,
551 buildFromCurrentState
= !filterRepresentation
,
552 defaultFilters
= this.getDefaultFilters(),
555 filterParamNames
= {},
556 getSelectedParameter = function ( filters
) {
560 // Find if any are selected
561 $.each( filters
, function ( name
, value
) {
563 selected
.push( name
);
567 item
= model
.getItemByName( selected
[ 0 ] );
568 return ( item
&& item
.getParamName() ) || '';
571 filterRepresentation
= filterRepresentation
|| {};
573 // Create or complete the filterRepresentation definition
574 this.getItems().forEach( function ( item
) {
575 // Map filter names to their parameter names
576 filterParamNames
[ item
.getName() ] = item
.getParamName();
578 if ( buildFromCurrentState
) {
579 // This means we have not been given a filter representation
580 // so we are building one based on current state
581 filterRepresentation
[ item
.getName() ] = item
.isSelected();
582 } else if ( filterRepresentation
[ item
.getName() ] === undefined ) {
583 // We are given a filter representation, but we have to make
584 // sure that we fill in the missing filters if there are any
585 // we will assume they are all falsey
586 if ( model
.isSticky() ) {
587 filterRepresentation
[ item
.getName() ] = !!defaultFilters
[ item
.getName() ];
589 filterRepresentation
[ item
.getName() ] = false;
593 if ( filterRepresentation
[ item
.getName() ] ) {
594 areAnySelected
= true;
600 this.getType() === 'send_unselected_if_any' ||
601 this.getType() === 'boolean'
603 // First, check if any of the items are selected at all.
604 // If none is selected, we're treating it as if they are
607 // Go over the items and define the correct values
608 $.each( filterRepresentation
, function ( name
, value
) {
609 // We must store all parameter values as strings '0' or '1'
610 if ( model
.getType() === 'send_unselected_if_any' ) {
611 result
[ filterParamNames
[ name
] ] = areAnySelected
?
612 String( Number( !value
) ) :
614 } else if ( model
.getType() === 'boolean' ) {
615 // Representation is straight-forward and direct from
616 // the parameter value to the filter state
617 result
[ filterParamNames
[ name
] ] = String( Number( !!value
) );
620 } else if ( this.getType() === 'string_options' ) {
623 $.each( filterRepresentation
, function ( name
, value
) {
626 values
.push( filterParamNames
[ name
] );
630 result
[ this.getName() ] = ( values
.length
=== Object
.keys( filterRepresentation
).length
) ?
631 'all' : values
.join( this.getSeparator() );
632 } else if ( this.getType() === 'single_option' ) {
633 result
[ this.getName() ] = getSelectedParameter( filterRepresentation
);
640 * Get the filter representation this group would provide
641 * based on given parameter states.
643 * @param {Object} [paramRepresentation] An object defining a parameter
644 * state to translate the filter state from. If not given, an object
645 * representing all filters as falsey is returned; same as if the parameter
646 * given were an empty object, or had some of the filters missing.
647 * @return {Object} Filter representation
649 mw
.rcfilters
.dm
.FilterGroup
.prototype.getFilterRepresentation = function ( paramRepresentation
) {
650 var areAnySelected
, paramValues
, item
, currentValue
,
651 oneWasSelected
= false,
652 defaultParams
= this.getDefaultParams(),
653 expandedParams
= $.extend( true, {}, paramRepresentation
),
655 paramToFilterMap
= {},
658 if ( this.isSticky() ) {
659 // If the group is sticky, check if all parameters are represented
660 // and for those that aren't represented, add them with their default
662 paramRepresentation
= $.extend( true, {}, this.getDefaultParams(), paramRepresentation
);
665 paramRepresentation
= paramRepresentation
|| {};
667 this.getType() === 'send_unselected_if_any' ||
668 this.getType() === 'boolean'
670 // Go over param representation; map and check for selections
671 this.getItems().forEach( function ( filterItem
) {
672 var paramName
= filterItem
.getParamName();
674 expandedParams
[ paramName
] = paramRepresentation
[ paramName
] || '0';
675 paramToFilterMap
[ paramName
] = filterItem
;
677 if ( Number( paramRepresentation
[ filterItem
.getParamName() ] ) ) {
678 areAnySelected
= true;
682 $.each( expandedParams
, function ( paramName
, paramValue
) {
683 var filterItem
= paramToFilterMap
[ paramName
];
685 if ( model
.getType() === 'send_unselected_if_any' ) {
686 // Flip the definition between the parameter
687 // state and the filter state
688 // This is what the 'toggleSelected' value of the filter is
689 result
[ filterItem
.getName() ] = areAnySelected
?
690 !Number( paramValue
) :
691 // Otherwise, there are no selected items in the
692 // group, which means the state is false
694 } else if ( model
.getType() === 'boolean' ) {
695 // Straight-forward definition of state
696 result
[ filterItem
.getName() ] = !!Number( paramRepresentation
[ filterItem
.getParamName() ] );
699 } else if ( this.getType() === 'string_options' ) {
700 currentValue
= paramRepresentation
[ this.getName() ] || '';
702 // Normalize the given parameter values
703 paramValues
= mw
.rcfilters
.utils
.normalizeParamOptions(
709 this.getItems().map( function ( filterItem
) {
710 return filterItem
.getParamName();
713 // Translate the parameter values into a filter selection state
714 this.getItems().forEach( function ( filterItem
) {
715 // All true (either because all values are written or the term 'all' is written)
716 // is the same as all filters set to true
717 result
[ filterItem
.getName() ] = (
718 // If it is the word 'all'
719 paramValues
.length
=== 1 && paramValues
[ 0 ] === 'all' ||
720 // All values are written
721 paramValues
.length
=== model
.getItemCount()
724 // Otherwise, the filter is selected only if it appears in the parameter values
725 paramValues
.indexOf( filterItem
.getParamName() ) > -1;
727 } else if ( this.getType() === 'single_option' ) {
728 // There is parameter that fits a single filter and if not, get the default
729 this.getItems().forEach( function ( filterItem
) {
730 var selected
= filterItem
.getParamName() === paramRepresentation
[ model
.getName() ];
732 result
[ filterItem
.getName() ] = selected
;
733 oneWasSelected
= oneWasSelected
|| selected
;
737 // Go over result and make sure all filters are represented.
738 // If any filters are missing, they will get a falsey value
739 this.getItems().forEach( function ( filterItem
) {
740 if ( result
[ filterItem
.getName() ] === undefined ) {
741 result
[ filterItem
.getName() ] = false;
745 // Make sure that at least one option is selected in
746 // single_option groups, no matter what path was taken
747 // If none was selected by the given definition, then
748 // we need to select the one in the base state -- either
749 // the default given, or the first item
751 this.getType() === 'single_option' &&
754 item
= this.getItems()[ 0 ];
755 if ( defaultParams
[ this.getName() ] ) {
756 item
= this.getItemByParamName( defaultParams
[ this.getName() ] );
759 result
[ item
.getName() ] = true;
766 * Get current selected state of all filter items in this group
768 * @return {Object} Selected state
770 mw
.rcfilters
.dm
.FilterGroup
.prototype.getSelectedState = function () {
773 this.getItems().forEach( function ( filterItem
) {
774 state
[ filterItem
.getName() ] = filterItem
.isSelected();
781 * Get item by its filter name
783 * @param {string} filterName Filter name
784 * @return {mw.rcfilters.dm.FilterItem} Filter item
786 mw
.rcfilters
.dm
.FilterGroup
.prototype.getItemByName = function ( filterName
) {
787 return this.getItems().filter( function ( item
) {
788 return item
.getName() === filterName
;
793 * Select an item by its parameter name
795 * @param {string} paramName Filter parameter name
797 mw
.rcfilters
.dm
.FilterGroup
.prototype.selectItemByParamName = function ( paramName
) {
798 this.getItems().forEach( function ( item
) {
799 item
.toggleSelected( item
.getParamName() === String( paramName
) );
804 * Get item by its parameter name
806 * @param {string} paramName Parameter name
807 * @return {mw.rcfilters.dm.FilterItem} Filter item
809 mw
.rcfilters
.dm
.FilterGroup
.prototype.getItemByParamName = function ( paramName
) {
810 return this.getItems().filter( function ( item
) {
811 return item
.getParamName() === String( paramName
);
818 * @return {string} Group type
820 mw
.rcfilters
.dm
.FilterGroup
.prototype.getType = function () {
825 * Check whether this group is represented by a single parameter
826 * or whether each item is its own parameter
828 * @return {boolean} This group is a single parameter
830 mw
.rcfilters
.dm
.FilterGroup
.prototype.isPerGroupRequestParameter = function () {
832 this.getType() === 'string_options' ||
833 this.getType() === 'single_option'
840 * @return {string} Display group
842 mw
.rcfilters
.dm
.FilterGroup
.prototype.getView = function () {
847 * Get the prefix used for the filter names inside this group.
849 * @param {string} [name] Filter name to prefix
850 * @return {string} Group prefix
852 mw
.rcfilters
.dm
.FilterGroup
.prototype.getNamePrefix = function () {
853 return this.getName() + '__';
857 * Get a filter name with the prefix used for the filter names inside this group.
859 * @param {string} name Filter name to prefix
860 * @return {string} Group prefix
862 mw
.rcfilters
.dm
.FilterGroup
.prototype.getPrefixedName = function ( name
) {
863 return this.getNamePrefix() + name
;
869 * @return {string} Title
871 mw
.rcfilters
.dm
.FilterGroup
.prototype.getTitle = function () {
876 * Get group's values separator
878 * @return {string} Values separator
880 mw
.rcfilters
.dm
.FilterGroup
.prototype.getSeparator = function () {
881 return this.separator
;
885 * Check whether the group is defined as full coverage
887 * @return {boolean} Group is full coverage
889 mw
.rcfilters
.dm
.FilterGroup
.prototype.isFullCoverage = function () {
890 return this.fullCoverage
;
894 * Check whether the group is defined as sticky default
896 * @return {boolean} Group is sticky default
898 mw
.rcfilters
.dm
.FilterGroup
.prototype.isSticky = function () {
903 * Normalize a value given to this group. This is mostly for correcting
904 * arbitrary values for 'single option' groups, given by the user settings
905 * or the URL that can go outside the limits that are allowed.
907 * @param {string} value Given value
908 * @return {string} Corrected value
910 mw
.rcfilters
.dm
.FilterGroup
.prototype.normalizeArbitraryValue = function ( value
) {
912 this.getType() === 'single_option' &&
913 this.isAllowArbitrary()
916 this.getMaxValue() !== null &&
917 value
> this.getMaxValue()
919 // Change the value to the actual max value
920 return String( this.getMaxValue() );
922 this.getMinValue() !== null &&
923 value
< this.getMinValue()
925 // Change the value to the actual min value
926 return String( this.getMinValue() );