Merge "Add parameter to API modules to apply change tags to log entries"
[lhc/web/wiklou.git] / resources / src / mediawiki.rcfilters / dm / mw.rcfilters.dm.FilterItem.js
1 ( function ( mw ) {
2 /**
3 * Filter item model
4 *
5 * @mixins OO.EventEmitter
6 *
7 * @constructor
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} [selected] Filter is selected
14 */
15 mw.rcfilters.dm.FilterItem = function MwRcfiltersDmFilterItem( name, config ) {
16 config = config || {};
17
18 // Mixin constructor
19 OO.EventEmitter.call( this );
20
21 this.name = name;
22 this.group = config.group || '';
23 this.label = config.label || this.name;
24 this.description = config.description;
25
26 this.selected = !!config.selected;
27 };
28
29 /* Initialization */
30
31 OO.initClass( mw.rcfilters.dm.FilterItem );
32 OO.mixinClass( mw.rcfilters.dm.FilterItem, OO.EventEmitter );
33
34 /* Events */
35
36 /**
37 * @event update
38 *
39 * The state of this filter has changed
40 */
41
42 /* Methods */
43
44 /**
45 * Get the name of this filter
46 *
47 * @return {string} Filter name
48 */
49 mw.rcfilters.dm.FilterItem.prototype.getName = function () {
50 return this.name;
51 };
52
53 /**
54 * Get the group name this filter belongs to
55 *
56 * @return {string} Filter group name
57 */
58 mw.rcfilters.dm.FilterItem.prototype.getGroup = function () {
59 return this.group;
60 };
61
62 /**
63 * Get the label of this filter
64 *
65 * @return {string} Filter label
66 */
67 mw.rcfilters.dm.FilterItem.prototype.getLabel = function () {
68 return this.label;
69 };
70
71 /**
72 * Get the description of this filter
73 *
74 * @return {string} Filter description
75 */
76 mw.rcfilters.dm.FilterItem.prototype.getDescription = function () {
77 return this.description;
78 };
79
80 /**
81 * Get the selected state of this filter
82 *
83 * @return {boolean} Filter is selected
84 */
85 mw.rcfilters.dm.FilterItem.prototype.isSelected = function () {
86 return this.selected;
87 };
88
89 /**
90 * Toggle the selected state of the item
91 *
92 * @param {boolean} [isSelected] Filter is selected
93 * @fires update
94 */
95 mw.rcfilters.dm.FilterItem.prototype.toggleSelected = function ( isSelected ) {
96 isSelected = isSelected === undefined ? !this.selected : isSelected;
97
98 if ( this.selected !== isSelected ) {
99 this.selected = isSelected;
100 this.emit( 'update' );
101 }
102 };
103 }( mediaWiki ) );