5 * @mixins OO.EventEmitter
8 * @param {string} name Filter name
9 * @param {Object} config Configuration object
10 * @cfg {string} [group] The group this item belongs to
11 * @cfg {string} [label] The label for the filter
12 * @cfg {string} [description] The description of the filter
13 * @cfg {boolean} [active=true] The filter is active and affecting the result
14 * @cfg {string[]} [excludes=[]] A list of filter names this filter, if
15 * selected, makes inactive.
16 * @cfg {boolean} [default] The default state of this filter
18 mw
.rcfilters
.dm
.FilterItem
= function MwRcfiltersDmFilterItem( name
, config
) {
19 config
= config
|| {};
22 OO
.EventEmitter
.call( this );
25 this.group
= config
.group
|| '';
26 this.label
= config
.label
|| this.name
;
27 this.description
= config
.description
;
28 this.default = !!config
.default;
30 this.active
= config
.active
=== undefined ? true : !!config
.active
;
31 this.excludes
= config
.excludes
|| [];
32 this.selected
= this.default;
37 OO
.initClass( mw
.rcfilters
.dm
.FilterItem
);
38 OO
.mixinClass( mw
.rcfilters
.dm
.FilterItem
, OO
.EventEmitter
);
45 * The state of this filter has changed
51 * Get the name of this filter
53 * @return {string} Filter name
55 mw
.rcfilters
.dm
.FilterItem
.prototype.getName = function () {
60 * Get the group name this filter belongs to
62 * @return {string} Filter group name
64 mw
.rcfilters
.dm
.FilterItem
.prototype.getGroup = function () {
69 * Get the label of this filter
71 * @return {string} Filter label
73 mw
.rcfilters
.dm
.FilterItem
.prototype.getLabel = function () {
78 * Get the description of this filter
80 * @return {string} Filter description
82 mw
.rcfilters
.dm
.FilterItem
.prototype.getDescription = function () {
83 return this.description
;
87 * Get the default value of this filter
89 * @return {boolean} Filter default
91 mw
.rcfilters
.dm
.FilterItem
.prototype.getDefault = function () {
96 * Get the selected state of this filter
98 * @return {boolean} Filter is selected
100 mw
.rcfilters
.dm
.FilterItem
.prototype.isSelected = function () {
101 return this.selected
;
105 * Check if this filter is active
107 * @return {boolean} Filter is active
109 mw
.rcfilters
.dm
.FilterItem
.prototype.isActive = function () {
114 * Check if this filter has a list of excluded filters
116 * @return {boolean} Filter has a list of excluded filters
118 mw
.rcfilters
.dm
.FilterItem
.prototype.hasExcludedFilters = function () {
119 return !!this.excludes
.length
;
123 * Get this filter's list of excluded filters
125 * @return {string[]} Array of excluded filter names
127 mw
.rcfilters
.dm
.FilterItem
.prototype.getExcludedFilters = function () {
128 return this.excludes
;
132 * Toggle the active state of the item
134 * @param {boolean} [isActive] Filter is active
137 mw
.rcfilters
.dm
.FilterItem
.prototype.toggleActive = function ( isActive
) {
138 isActive
= isActive
=== undefined ? !this.active
: isActive
;
140 if ( this.active
!== isActive
) {
141 this.active
= isActive
;
142 this.emit( 'update' );
147 * Toggle the selected state of the item
149 * @param {boolean} [isSelected] Filter is selected
152 mw
.rcfilters
.dm
.FilterItem
.prototype.toggleSelected = function ( isSelected
) {
153 isSelected
= isSelected
=== undefined ? !this.selected
: isSelected
;
155 if ( this.selected
!== isSelected
) {
156 this.selected
= isSelected
;
157 this.emit( 'update' );