3 * List displaying all filter groups
5 * @extends OO.ui.Widget
6 * @mixins OO.ui.mixin.GroupWidget
7 * @mixins OO.ui.mixin.LabelElement
10 * @param {mw.rcfilters.Controller} controller Controller
11 * @param {mw.rcfilters.dm.FiltersViewModel} model View model
12 * @param {Object} config Configuration object
14 mw
.rcfilters
.ui
.FiltersListWidget
= function MwRcfiltersUiFiltersListWidget( controller
, model
, config
) {
15 config
= config
|| {};
18 mw
.rcfilters
.ui
.FiltersListWidget
.parent
.call( this, config
);
20 OO
.ui
.mixin
.GroupWidget
.call( this, config
);
21 OO
.ui
.mixin
.LabelElement
.call( this, $.extend( {}, config
, {
23 .addClass( 'mw-rcfilters-ui-filtersListWidget-title' )
26 this.controller
= controller
;
28 this.$overlay
= config
.$overlay
|| this.$element
;
30 this.highlightButton
= new OO
.ui
.ButtonWidget( {
31 label
: mw
.message( 'rcfilters-highlightbutton-title' ).text(),
32 classes
: [ 'mw-rcfilters-ui-filtersListWidget-hightlightButton' ]
35 this.$label
.append( this.highlightButton
.$element
);
37 this.noResultsLabel
= new OO
.ui
.LabelWidget( {
38 label
: mw
.msg( 'rcfilters-filterlist-noresults' ),
39 classes
: [ 'mw-rcfilters-ui-filtersListWidget-noresults' ]
43 this.highlightButton
.connect( this, { click
: 'onHighlightButtonClick' } );
44 this.model
.connect( this, {
45 initialize
: 'onModelInitialize',
46 highlightChange
: 'onHighlightChange'
50 this.showNoResultsMessage( false );
52 .addClass( 'mw-rcfilters-ui-filtersListWidget' )
56 .addClass( 'mw-rcfilters-ui-filtersListWidget-group' ),
57 this.noResultsLabel
.$element
63 OO
.inheritClass( mw
.rcfilters
.ui
.FiltersListWidget
, OO
.ui
.Widget
);
64 OO
.mixinClass( mw
.rcfilters
.ui
.FiltersListWidget
, OO
.ui
.mixin
.GroupWidget
);
65 OO
.mixinClass( mw
.rcfilters
.ui
.FiltersListWidget
, OO
.ui
.mixin
.LabelElement
);
70 * Respond to initialize event from the model
72 mw
.rcfilters
.ui
.FiltersListWidget
.prototype.onModelInitialize = function () {
79 Object
.keys( this.model
.getFilterGroups() ).map( function ( groupName
) {
80 return new mw
.rcfilters
.ui
.FilterGroupWidget(
82 widget
.model
.getGroup( groupName
),
84 $overlay
: widget
.$overlay
91 mw
.rcfilters
.ui
.FiltersListWidget
.prototype.onHighlightChange = function ( highlightEnabled
) {
92 this.highlightButton
.setActive( highlightEnabled
);
96 * Respond to highlight button click
98 mw
.rcfilters
.ui
.FiltersListWidget
.prototype.onHighlightButtonClick = function () {
99 this.controller
.toggleHighlight();
103 * Switch between showing the 'no results' message for filtering results or the result list.
105 * @param {boolean} showNoResults Show no results message
107 mw
.rcfilters
.ui
.FiltersListWidget
.prototype.showNoResultsMessage = function ( showNoResults
) {
108 this.noResultsLabel
.toggle( !!showNoResults
);
109 this.$group
.toggleClass( 'oo-ui-element-hidden', !!showNoResults
);
113 * Show only the items matching with the models in the given list
115 * @param {Object} groupItems An object of items to show
116 * arranged by their group names
118 mw
.rcfilters
.ui
.FiltersListWidget
.prototype.filter = function ( groupItems
) {
119 var i
, j
, groupName
, itemWidgets
,
120 groupWidgets
= this.getItems(),
121 hasItemWithName = function ( itemArr
, name
) {
122 return !!itemArr
.filter( function ( item
) {
123 return item
.getName() === name
;
127 if ( $.isEmptyObject( groupItems
) ) {
128 // No results. Hide everything, show only 'no results'
130 this.showNoResultsMessage( true );
134 this.showNoResultsMessage( false );
135 for ( i
= 0; i
< groupWidgets
.length
; i
++ ) {
136 groupName
= groupWidgets
[ i
].getName();
138 // If this group widget is in the filtered results,
139 // show it - otherwise, hide it
140 groupWidgets
[ i
].toggle( !!groupItems
[ groupName
] );
142 if ( !groupItems
[ groupName
] ) {
143 // Continue to next group
147 // We have items to show
148 itemWidgets
= groupWidgets
[ i
].getItems();
149 for ( j
= 0; j
< itemWidgets
.length
; j
++ ) {
150 // Only show items that are in the filtered list
151 itemWidgets
[ j
].toggle(
152 hasItemWithName( groupItems
[ groupName
], itemWidgets
[ j
].getName() )
157 }( mediaWiki
, jQuery
) );