Merge "rcfeed: Ensure formatter (and other params) is passed to RCFeedEngine"
[lhc/web/wiklou.git] / resources / src / mediawiki.rcfilters / dm / mw.rcfilters.dm.FilterGroup.js
1 ( function ( mw ) {
2 /**
3 * View model for a filter group
4 *
5 * @mixins OO.EventEmitter
6 * @mixins OO.EmitterList
7 *
8 * @constructor
9 * @param {Object} [config] Configuration options
10 * @cfg {string} [type='send_unselected_if_any'] Group type
11 * @cfg {string} [title] Group title
12 * @cfg {string} [separator='|'] Value separator for 'string_options' groups
13 * @cfg {string} [exclusionType='default'] Group exclusion type
14 * @cfg {boolean} [active] Group is active
15 */
16 mw.rcfilters.dm.FilterGroup = function MwRcfiltersDmFilterGroup( config ) {
17 config = config || {};
18
19 // Mixin constructor
20 OO.EventEmitter.call( this );
21 OO.EmitterList.call( this );
22
23 this.type = config.type || 'send_unselected_if_any';
24 this.title = config.title;
25 this.separator = config.separator || '|';
26 this.exclusionType = config.exclusionType || 'default';
27 this.active = !!config.active;
28 };
29
30 /* Initialization */
31 OO.initClass( mw.rcfilters.dm.FilterGroup );
32 OO.mixinClass( mw.rcfilters.dm.FilterGroup, OO.EventEmitter );
33 OO.mixinClass( mw.rcfilters.dm.FilterGroup, OO.EmitterList );
34
35 /* Events */
36
37 /**
38 * @event update
39 *
40 * Group state has been updated
41 */
42
43 /* Methods */
44
45 /**
46 * Check the active status of the group and set it accordingly.
47 *
48 * @fires update
49 */
50 mw.rcfilters.dm.FilterGroup.prototype.checkActive = function () {
51 var active,
52 count = 0;
53
54 // Recheck group activity
55 this.getItems().forEach( function ( filterItem ) {
56 count += Number( filterItem.isSelected() );
57 } );
58
59 active = (
60 count > 0 &&
61 count < this.getItemCount()
62 );
63
64 if ( this.active !== active ) {
65 this.active = active;
66 this.emit( 'update' );
67 }
68 };
69
70 /**
71 * Get group active state
72 *
73 * @return {boolean} Active state
74 */
75 mw.rcfilters.dm.FilterGroup.prototype.isActive = function () {
76 return this.active;
77 };
78
79 /**
80 * Get group type
81 *
82 * @return {string} Group type
83 */
84 mw.rcfilters.dm.FilterGroup.prototype.getType = function () {
85 return this.type;
86 };
87
88 /**
89 * Get group's title
90 *
91 * @return {string} Title
92 */
93 mw.rcfilters.dm.FilterGroup.prototype.getTitle = function () {
94 return this.title;
95 };
96
97 /**
98 * Get group's values separator
99 *
100 * @return {string} Values separator
101 */
102 mw.rcfilters.dm.FilterGroup.prototype.getSeparator = function () {
103 return this.separator;
104 };
105
106 /**
107 * Get group exclusion type
108 *
109 * @return {string} Exclusion type
110 */
111 mw.rcfilters.dm.FilterGroup.prototype.getExclusionType = function () {
112 return this.exclusionType;
113 };
114 }( mediaWiki ) );