1 var GroupWidget
= require( './GroupWidget.js' ),
5 * A widget for the footer for the default view, allowing to switch views
7 * @class mw.rcfilters.ui.ViewSwitchWidget
8 * @extends OO.ui.Widget
11 * @param {mw.rcfilters.Controller} controller Controller
12 * @param {mw.rcfilters.dm.FiltersViewModel} model View model
13 * @param {Object} [config] Configuration object
15 ViewSwitchWidget
= function MwRcfiltersUiViewSwitchWidget( controller
, model
, config
) {
16 config
= config
|| {};
19 ViewSwitchWidget
.parent
.call( this, config
);
21 this.controller
= controller
;
24 this.buttons
= new GroupWidget( {
29 new OO
.ui
.ButtonWidget( {
32 label
: mw
.msg( 'namespaces' )
34 new OO
.ui
.ButtonWidget( {
37 label
: mw
.msg( 'rcfilters-view-tags' )
43 this.model
.connect( this, { update
: 'onModelUpdate' } );
44 this.buttons
.connect( this, { buttonClick
: 'onButtonClick' } );
47 .addClass( 'mw-rcfilters-ui-viewSwitchWidget' )
49 new OO
.ui
.LabelWidget( {
50 label
: mw
.msg( 'rcfilters-advancedfilters' )
53 .addClass( 'mw-rcfilters-ui-viewSwitchWidget-buttons' )
54 .append( this.buttons
.$element
)
60 OO
.inheritClass( ViewSwitchWidget
, OO
.ui
.Widget
);
63 * Respond to model update event
65 ViewSwitchWidget
.prototype.onModelUpdate = function () {
66 var currentView
= this.model
.getCurrentView();
68 this.buttons
.getItems().forEach( function ( buttonWidget
) {
69 buttonWidget
.setActive( buttonWidget
.getData() === currentView
);
74 * Respond to button switch click
76 * @param {OO.ui.ButtonWidget} buttonWidget Clicked button
78 ViewSwitchWidget
.prototype.onButtonClick = function ( buttonWidget
) {
79 this.controller
.switchView( buttonWidget
.getData() );
82 module
.exports
= ViewSwitchWidget
;