Merge "phpunit: Fix OutputPage::__construct warning in SkinTemplateTest"
[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} [name] Group name
11 * @cfg {string} [type='send_unselected_if_any'] Group type
12 * @cfg {string} [title] Group title
13 * @cfg {string} [separator='|'] Value separator for 'string_options' groups
14 * @cfg {string} [exclusionType='default'] Group exclusion type
15 * @cfg {boolean} [active] Group is active
16 */
17 mw.rcfilters.dm.FilterGroup = function MwRcfiltersDmFilterGroup( config ) {
18 config = config || {};
19
20 // Mixin constructor
21 OO.EventEmitter.call( this );
22 OO.EmitterList.call( this );
23
24 this.name = config.name;
25 this.type = config.type || 'send_unselected_if_any';
26 this.title = config.title;
27 this.separator = config.separator || '|';
28 this.exclusionType = config.exclusionType || 'default';
29 this.active = !!config.active;
30 };
31
32 /* Initialization */
33 OO.initClass( mw.rcfilters.dm.FilterGroup );
34 OO.mixinClass( mw.rcfilters.dm.FilterGroup, OO.EventEmitter );
35 OO.mixinClass( mw.rcfilters.dm.FilterGroup, OO.EmitterList );
36
37 /* Events */
38
39 /**
40 * @event update
41 *
42 * Group state has been updated
43 */
44
45 /* Methods */
46
47 /**
48 * Check the active status of the group and set it accordingly.
49 *
50 * @fires update
51 */
52 mw.rcfilters.dm.FilterGroup.prototype.checkActive = function () {
53 var active,
54 count = 0;
55
56 // Recheck group activity
57 this.getItems().forEach( function ( filterItem ) {
58 count += Number( filterItem.isSelected() );
59 } );
60
61 active = (
62 count > 0 &&
63 count < this.getItemCount()
64 );
65
66 if ( this.active !== active ) {
67 this.active = active;
68 this.emit( 'update' );
69 }
70 };
71
72 /**
73 * Get group active state
74 *
75 * @return {boolean} Active state
76 */
77 mw.rcfilters.dm.FilterGroup.prototype.isActive = function () {
78 return this.active;
79 };
80
81 /**
82 * Get group name
83 *
84 * @return {string} Group name
85 */
86 mw.rcfilters.dm.FilterGroup.prototype.getName = function () {
87 return this.name;
88 };
89
90 /**
91 * Get group type
92 *
93 * @return {string} Group type
94 */
95 mw.rcfilters.dm.FilterGroup.prototype.getType = function () {
96 return this.type;
97 };
98
99 /**
100 * Get group's title
101 *
102 * @return {string} Title
103 */
104 mw.rcfilters.dm.FilterGroup.prototype.getTitle = function () {
105 return this.title;
106 };
107
108 /**
109 * Get group's values separator
110 *
111 * @return {string} Values separator
112 */
113 mw.rcfilters.dm.FilterGroup.prototype.getSeparator = function () {
114 return this.separator;
115 };
116
117 /**
118 * Get group exclusion type
119 *
120 * @return {string} Exclusion type
121 */
122 mw.rcfilters.dm.FilterGroup.prototype.getExclusionType = function () {
123 return this.exclusionType;
124 };
125 }( mediaWiki ) );