5 * @mixins OO.EventEmitter
8 * @param {string} name Filter name
9 * @param {mw.rcfilters.dm.FilterGroup} groupModel Filter group model
10 * @param {Object} config Configuration object
11 * @cfg {string} [group] The group this item belongs to
12 * @cfg {string} [label] The label for the filter
13 * @cfg {string} [description] The description of the filter
14 * @cfg {boolean} [active=true] The filter is active and affecting the result
15 * @cfg {string[]} [excludes=[]] A list of filter names this filter, if
16 * selected, makes inactive.
17 * @cfg {boolean} [selected] The item is selected
18 * @cfg {string[]} [subset] Defining the names of filters that are a subset of this filter
19 * @cfg {string[]} [conflictsWith] Defining the names of filters that conflict with this item
21 mw
.rcfilters
.dm
.FilterItem
= function MwRcfiltersDmFilterItem( name
, groupModel
, config
) {
22 config
= config
|| {};
25 OO
.EventEmitter
.call( this );
28 this.groupModel
= groupModel
;
30 this.label
= config
.label
|| this.name
;
31 this.description
= config
.description
;
32 this.selected
= !!config
.selected
;
34 // Interaction definitions
35 this.subset
= config
.subset
|| [];
36 this.conflicts
= config
.conflicts
|| [];
40 this.included
= false;
41 this.conflicted
= false;
42 this.fullyCovered
= false;
47 OO
.initClass( mw
.rcfilters
.dm
.FilterItem
);
48 OO
.mixinClass( mw
.rcfilters
.dm
.FilterItem
, OO
.EventEmitter
);
55 * The state of this filter has changed
61 * Get the name of this filter
63 * @return {string} Filter name
65 mw
.rcfilters
.dm
.FilterItem
.prototype.getName = function () {
70 * Get the model of the group this filter belongs to
72 * @return {mw.rcfilters.dm.FilterGroup} Filter group model
74 mw
.rcfilters
.dm
.FilterItem
.prototype.getGroupModel = function () {
75 return this.groupModel
;
79 * Get the group name this filter belongs to
81 * @return {string} Filter group name
83 mw
.rcfilters
.dm
.FilterItem
.prototype.getGroupName = function () {
84 return this.groupModel
.getName();
88 * Get the label of this filter
90 * @return {string} Filter label
92 mw
.rcfilters
.dm
.FilterItem
.prototype.getLabel = function () {
97 * Get the description of this filter
99 * @return {string} Filter description
101 mw
.rcfilters
.dm
.FilterItem
.prototype.getDescription = function () {
102 return this.description
;
106 * Get the default value of this filter
108 * @return {boolean} Filter default
110 mw
.rcfilters
.dm
.FilterItem
.prototype.getDefault = function () {
116 * This is a list of filter names that are defined to be included
117 * when this filter is selected.
119 * @return {string[]} Filter subset
121 mw
.rcfilters
.dm
.FilterItem
.prototype.getSubset = function () {
126 * Get filter superset
127 * This is a generated list of filters that define this filter
128 * to be included when either of them is selected.
130 * @return {string[]} Filter superset
132 mw
.rcfilters
.dm
.FilterItem
.prototype.getSuperset = function () {
133 return this.superset
;
137 * Get the selected state of this filter
139 * @return {boolean} Filter is selected
141 mw
.rcfilters
.dm
.FilterItem
.prototype.isSelected = function () {
142 return this.selected
;
146 * Check whether the filter is currently in a conflict state
148 * @return {boolean} Filter is in conflict state
150 mw
.rcfilters
.dm
.FilterItem
.prototype.isConflicted = function () {
151 return this.conflicted
;
155 * Check whether the filter is currently in an already included subset
157 * @return {boolean} Filter is in an already-included subset
159 mw
.rcfilters
.dm
.FilterItem
.prototype.isIncluded = function () {
160 return this.included
;
164 * Check whether the filter is currently fully covered
166 * @return {boolean} Filter is in fully-covered state
168 mw
.rcfilters
.dm
.FilterItem
.prototype.isFullyCovered = function () {
169 return this.fullyCovered
;
173 * Get filter conflicts
175 * @return {string[]} Filter conflicts
177 mw
.rcfilters
.dm
.FilterItem
.prototype.getConflicts = function () {
178 return this.conflicts
;
182 * Set filter conflicts
184 * @param {string[]} conflicts Filter conflicts
186 mw
.rcfilters
.dm
.FilterItem
.prototype.setConflicts = function ( conflicts
) {
187 this.conflicts
= conflicts
|| [];
191 * Set filter superset
193 * @param {string[]} superset Filter superset
195 mw
.rcfilters
.dm
.FilterItem
.prototype.setSuperset = function ( superset
) {
196 this.superset
= superset
|| [];
200 * Check whether a filter exists in the subset list for this filter
202 * @param {string} filterName Filter name
203 * @return {boolean} Filter name is in the subset list
205 mw
.rcfilters
.dm
.FilterItem
.prototype.existsInSubset = function ( filterName
) {
206 return this.subset
.indexOf( filterName
) > -1;
210 * Check whether this item has a potential conflict with the given item
212 * This checks whether the given item is in the list of conflicts of
213 * the current item, but makes no judgment about whether the conflict
214 * is currently at play (either one of the items may not be selected)
216 * @param {mw.rcfilters.dm.FilterItem} filterItem Filter item
217 * @return {boolean} This item has a conflict with the given item
219 mw
.rcfilters
.dm
.FilterItem
.prototype.existsInConflicts = function ( filterItem
) {
220 return this.conflicts
.indexOf( filterItem
.getName() ) > -1;
224 * Set the state of this filter as being conflicted
225 * (This means any filters in its conflicts are selected)
227 * @param {boolean} [conflicted] Filter is in conflict state
230 mw
.rcfilters
.dm
.FilterItem
.prototype.toggleConflicted = function ( conflicted
) {
231 conflicted
= conflicted
=== undefined ? !this.conflicted
: conflicted
;
233 if ( this.conflicted
!== conflicted
) {
234 this.conflicted
= conflicted
;
235 this.emit( 'update' );
240 * Set the state of this filter as being already included
241 * (This means any filters in its superset are selected)
243 * @param {boolean} [included] Filter is included as part of a subset
246 mw
.rcfilters
.dm
.FilterItem
.prototype.toggleIncluded = function ( included
) {
247 included
= included
=== undefined ? !this.included
: included
;
249 if ( this.included
!== included
) {
250 this.included
= included
;
251 this.emit( 'update' );
256 * Toggle the selected state of the item
258 * @param {boolean} [isSelected] Filter is selected
261 mw
.rcfilters
.dm
.FilterItem
.prototype.toggleSelected = function ( isSelected
) {
262 isSelected
= isSelected
=== undefined ? !this.selected
: isSelected
;
264 if ( this.selected
!== isSelected
) {
265 this.selected
= isSelected
;
266 this.emit( 'update' );
271 * Toggle the fully covered state of the item
273 * @param {boolean} [isFullyCovered] Filter is fully covered
276 mw
.rcfilters
.dm
.FilterItem
.prototype.toggleFullyCovered = function ( isFullyCovered
) {
277 isFullyCovered
= isFullyCovered
=== undefined ? !this.fullycovered
: isFullyCovered
;
279 if ( this.fullyCovered
!== isFullyCovered
) {
280 this.fullyCovered
= isFullyCovered
;
281 this.emit( 'update' );