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
20 * @cfg {string} [cssClass] The class identifying the results that match this filter
22 mw
.rcfilters
.dm
.FilterItem
= function MwRcfiltersDmFilterItem( name
, groupModel
, config
) {
23 config
= config
|| {};
26 OO
.EventEmitter
.call( this );
29 this.groupModel
= groupModel
;
31 this.label
= config
.label
|| this.name
;
32 this.description
= config
.description
;
33 this.selected
= !!config
.selected
;
35 // Interaction definitions
36 this.subset
= config
.subset
|| [];
37 this.conflicts
= config
.conflicts
|| [];
41 this.included
= false;
42 this.conflicted
= false;
43 this.fullyCovered
= false;
46 this.cssClass
= config
.cssClass
;
47 this.highlightColor
= null;
48 this.highlightEnabled
= false;
53 OO
.initClass( mw
.rcfilters
.dm
.FilterItem
);
54 OO
.mixinClass( mw
.rcfilters
.dm
.FilterItem
, OO
.EventEmitter
);
61 * The state of this filter has changed
67 * Return the representation of the state of this item.
69 * @return {Object} State of the object
71 mw
.rcfilters
.dm
.FilterItem
.prototype.getState = function () {
73 selected
: this.isSelected(),
74 included
: this.isIncluded(),
75 conflicted
: this.isConflicted(),
76 fullyCovered
: this.isFullyCovered()
81 * Get the name of this filter
83 * @return {string} Filter name
85 mw
.rcfilters
.dm
.FilterItem
.prototype.getName = function () {
90 * Get the model of the group this filter belongs to
92 * @return {mw.rcfilters.dm.FilterGroup} Filter group model
94 mw
.rcfilters
.dm
.FilterItem
.prototype.getGroupModel = function () {
95 return this.groupModel
;
99 * Get the group name this filter belongs to
101 * @return {string} Filter group name
103 mw
.rcfilters
.dm
.FilterItem
.prototype.getGroupName = function () {
104 return this.groupModel
.getName();
108 * Get the label of this filter
110 * @return {string} Filter label
112 mw
.rcfilters
.dm
.FilterItem
.prototype.getLabel = function () {
117 * Get the description of this filter
119 * @return {string} Filter description
121 mw
.rcfilters
.dm
.FilterItem
.prototype.getDescription = function () {
122 return this.description
;
126 * Get the default value of this filter
128 * @return {boolean} Filter default
130 mw
.rcfilters
.dm
.FilterItem
.prototype.getDefault = function () {
136 * This is a list of filter names that are defined to be included
137 * when this filter is selected.
139 * @return {string[]} Filter subset
141 mw
.rcfilters
.dm
.FilterItem
.prototype.getSubset = function () {
146 * Get filter superset
147 * This is a generated list of filters that define this filter
148 * to be included when either of them is selected.
150 * @return {string[]} Filter superset
152 mw
.rcfilters
.dm
.FilterItem
.prototype.getSuperset = function () {
153 return this.superset
;
157 * Get the selected state of this filter
159 * @return {boolean} Filter is selected
161 mw
.rcfilters
.dm
.FilterItem
.prototype.isSelected = function () {
162 return this.selected
;
166 * Check whether the filter is currently in a conflict state
168 * @return {boolean} Filter is in conflict state
170 mw
.rcfilters
.dm
.FilterItem
.prototype.isConflicted = function () {
171 return this.conflicted
;
175 * Check whether the filter is currently in an already included subset
177 * @return {boolean} Filter is in an already-included subset
179 mw
.rcfilters
.dm
.FilterItem
.prototype.isIncluded = function () {
180 return this.included
;
184 * Check whether the filter is currently fully covered
186 * @return {boolean} Filter is in fully-covered state
188 mw
.rcfilters
.dm
.FilterItem
.prototype.isFullyCovered = function () {
189 return this.fullyCovered
;
193 * Get filter conflicts
195 * @return {string[]} Filter conflicts
197 mw
.rcfilters
.dm
.FilterItem
.prototype.getConflicts = function () {
198 return this.conflicts
;
202 * Set filter conflicts
204 * @param {string[]} conflicts Filter conflicts
206 mw
.rcfilters
.dm
.FilterItem
.prototype.setConflicts = function ( conflicts
) {
207 this.conflicts
= conflicts
|| [];
211 * Set filter superset
213 * @param {string[]} superset Filter superset
215 mw
.rcfilters
.dm
.FilterItem
.prototype.setSuperset = function ( superset
) {
216 this.superset
= superset
|| [];
220 * Check whether a filter exists in the subset list for this filter
222 * @param {string} filterName Filter name
223 * @return {boolean} Filter name is in the subset list
225 mw
.rcfilters
.dm
.FilterItem
.prototype.existsInSubset = function ( filterName
) {
226 return this.subset
.indexOf( filterName
) > -1;
230 * Check whether this item has a potential conflict with the given item
232 * This checks whether the given item is in the list of conflicts of
233 * the current item, but makes no judgment about whether the conflict
234 * is currently at play (either one of the items may not be selected)
236 * @param {mw.rcfilters.dm.FilterItem} filterItem Filter item
237 * @return {boolean} This item has a conflict with the given item
239 mw
.rcfilters
.dm
.FilterItem
.prototype.existsInConflicts = function ( filterItem
) {
240 return this.conflicts
.indexOf( filterItem
.getName() ) > -1;
244 * Set the state of this filter as being conflicted
245 * (This means any filters in its conflicts are selected)
247 * @param {boolean} [conflicted] Filter is in conflict state
250 mw
.rcfilters
.dm
.FilterItem
.prototype.toggleConflicted = function ( conflicted
) {
251 conflicted
= conflicted
=== undefined ? !this.conflicted
: conflicted
;
253 if ( this.conflicted
!== conflicted
) {
254 this.conflicted
= conflicted
;
255 this.emit( 'update' );
260 * Set the state of this filter as being already included
261 * (This means any filters in its superset are selected)
263 * @param {boolean} [included] Filter is included as part of a subset
266 mw
.rcfilters
.dm
.FilterItem
.prototype.toggleIncluded = function ( included
) {
267 included
= included
=== undefined ? !this.included
: included
;
269 if ( this.included
!== included
) {
270 this.included
= included
;
271 this.emit( 'update' );
276 * Toggle the selected state of the item
278 * @param {boolean} [isSelected] Filter is selected
281 mw
.rcfilters
.dm
.FilterItem
.prototype.toggleSelected = function ( isSelected
) {
282 isSelected
= isSelected
=== undefined ? !this.selected
: isSelected
;
284 if ( this.selected
!== isSelected
) {
285 this.selected
= isSelected
;
286 this.emit( 'update' );
291 * Toggle the fully covered state of the item
293 * @param {boolean} [isFullyCovered] Filter is fully covered
296 mw
.rcfilters
.dm
.FilterItem
.prototype.toggleFullyCovered = function ( isFullyCovered
) {
297 isFullyCovered
= isFullyCovered
=== undefined ? !this.fullycovered
: isFullyCovered
;
299 if ( this.fullyCovered
!== isFullyCovered
) {
300 this.fullyCovered
= isFullyCovered
;
301 this.emit( 'update' );
306 * Set the highlight color
308 * @param {string|null} highlightColor
310 mw
.rcfilters
.dm
.FilterItem
.prototype.setHighlightColor = function ( highlightColor
) {
311 if ( this.highlightColor
!== highlightColor
) {
312 this.highlightColor
= highlightColor
;
313 this.emit( 'update' );
318 * Clear the highlight color
320 mw
.rcfilters
.dm
.FilterItem
.prototype.clearHighlightColor = function () {
321 this.setHighlightColor( null );
325 * Get the highlight color, or null if none is configured
327 * @return {string|null}
329 mw
.rcfilters
.dm
.FilterItem
.prototype.getHighlightColor = function () {
330 return this.highlightColor
;
334 * Get the CSS class that matches changes that fit this filter
335 * or null if none is configured
337 * @return {string|null}
339 mw
.rcfilters
.dm
.FilterItem
.prototype.getCssClass = function () {
340 return this.cssClass
;
344 * Toggle the highlight feature on and off for this filter.
345 * It only works if highlight is supported for this filter.
347 * @param {boolean} enable Highlight should be enabled
349 mw
.rcfilters
.dm
.FilterItem
.prototype.toggleHighlight = function ( enable
) {
350 enable
= enable
=== undefined ? !this.highlightEnabled
: enable
;
352 if ( !this.isHighlightSupported() ) {
356 if ( enable
=== this.highlightEnabled
) {
360 this.highlightEnabled
= enable
;
361 this.emit( 'update' );
365 * Check if the highlight feature is currently enabled for this filter
369 mw
.rcfilters
.dm
.FilterItem
.prototype.isHighlightEnabled = function () {
370 return !!this.highlightEnabled
;
374 * Check if the highlight feature is supported for this filter
378 mw
.rcfilters
.dm
.FilterItem
.prototype.isHighlightSupported = function () {
379 return !!this.getCssClass();
383 * Check if the filter is currently highlighted
387 mw
.rcfilters
.dm
.FilterItem
.prototype.isHighlighted = function () {
388 return this.isHighlightEnabled() && !!this.getHighlightColor();