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} [title] Group title
13 * @cfg {string} [separator='|'] Value separator for 'string_options' groups
14 * @cfg {boolean} [active] Group is active
15 * @cfg {boolean} [fullCoverage] This filters in this group collectively cover all results
17 mw
.rcfilters
.dm
.FilterGroup
= function MwRcfiltersDmFilterGroup( name
, config
) {
18 config
= config
|| {};
21 OO
.EventEmitter
.call( this );
22 OO
.EmitterList
.call( this );
25 this.type
= config
.type
|| 'send_unselected_if_any';
26 this.title
= config
.title
;
27 this.separator
= config
.separator
|| '|';
29 this.active
= !!config
.active
;
30 this.fullCoverage
= !!config
.fullCoverage
;
32 this.aggregate( { update
: 'filterItemUpdate' } );
33 this.connect( this, { filterItemUpdate
: 'onFilterItemUpdate' } );
37 OO
.initClass( mw
.rcfilters
.dm
.FilterGroup
);
38 OO
.mixinClass( mw
.rcfilters
.dm
.FilterGroup
, OO
.EventEmitter
);
39 OO
.mixinClass( mw
.rcfilters
.dm
.FilterGroup
, OO
.EmitterList
);
46 * Group state has been updated
52 * Respond to filterItem update event
56 mw
.rcfilters
.dm
.FilterGroup
.prototype.onFilterItemUpdate = function () {
58 var active
= this.areAnySelected();
60 if ( this.active
!== active
) {
62 this.emit( 'update' );
67 * Get group active state
69 * @return {boolean} Active state
71 mw
.rcfilters
.dm
.FilterGroup
.prototype.isActive = function () {
78 * @return {string} Group name
80 mw
.rcfilters
.dm
.FilterGroup
.prototype.getName = function () {
85 * Check whether there are any items selected
87 * @return {boolean} Any items in the group are selected
89 mw
.rcfilters
.dm
.FilterGroup
.prototype.areAnySelected = function () {
90 return this.getItems().some( function ( filterItem
) {
91 return filterItem
.isSelected();
96 * Check whether all items selected
98 * @return {boolean} All items are selected
100 mw
.rcfilters
.dm
.FilterGroup
.prototype.areAllSelected = function () {
101 return this.getItems().every( function ( filterItem
) {
102 return filterItem
.isSelected();
107 * Get all selected items in this group
109 * @param {mw.rcfilters.dm.FilterItem} [excludeItem] Item to exclude from the list
110 * @return {mw.rcfilters.dm.FilterItem[]} Selected items
112 mw
.rcfilters
.dm
.FilterGroup
.prototype.getSelectedItems = function ( excludeItem
) {
113 var excludeName
= ( excludeItem
&& excludeItem
.getName() ) || '';
115 return this.getItems().filter( function ( item
) {
116 return item
.getName() !== excludeName
&& item
.isSelected();
121 * Check whether all selected items are in conflict with the given item
123 * @param {mw.rcfilters.dm.FilterItem} filterItem Filter item to test
124 * @return {boolean} All selected items are in conflict with this item
126 mw
.rcfilters
.dm
.FilterGroup
.prototype.areAllSelectedInConflictWith = function ( filterItem
) {
127 var selectedItems
= this.getSelectedItems( filterItem
);
129 return selectedItems
.length
> 0 && selectedItems
.every( function ( selectedFilter
) {
130 return selectedFilter
.existsInConflicts( filterItem
);
135 * Check whether any of the selected items are in conflict with the given item
137 * @param {mw.rcfilters.dm.FilterItem} filterItem Filter item to test
138 * @return {boolean} Any of the selected items are in conflict with this item
140 mw
.rcfilters
.dm
.FilterGroup
.prototype.areAnySelectedInConflictWith = function ( filterItem
) {
141 var selectedItems
= this.getSelectedItems( filterItem
);
143 return selectedItems
.length
> 0 && selectedItems
.some( function ( selectedFilter
) {
144 return selectedFilter
.existsInConflicts( filterItem
);
151 * @return {string} Group type
153 mw
.rcfilters
.dm
.FilterGroup
.prototype.getType = function () {
160 * @return {string} Title
162 mw
.rcfilters
.dm
.FilterGroup
.prototype.getTitle = function () {
167 * Get group's values separator
169 * @return {string} Values separator
171 mw
.rcfilters
.dm
.FilterGroup
.prototype.getSeparator = function () {
172 return this.separator
;
176 * Check whether the group is defined as full coverage
178 * @return {boolean} Group is full coverage
180 mw
.rcfilters
.dm
.FilterGroup
.prototype.isFullCoverage = function () {
181 return this.fullCoverage
;