2 * A widget for the footer for the default view, allowing to switch views.
4 * @class mw.rcfilters.ui.ViewSwitchWidget
6 * @extends OO.ui.Widget
8 * @param {mw.rcfilters.Controller} controller Controller
9 * @param {mw.rcfilters.dm.FiltersViewModel} model View model
10 * @param {Object} [config] Configuration object
12 const ViewSwitchWidget = function MwRcfiltersUiViewSwitchWidget( controller, model, config ) {
13 config = config || {};
16 ViewSwitchWidget.super.call( this, config );
18 this.controller = controller;
21 this.buttons = new OO.ui.ButtonGroupWidget( {
23 new OO.ui.ButtonWidget( {
26 label: mw.msg( 'namespaces' )
28 new OO.ui.ButtonWidget( {
31 label: mw.msg( 'rcfilters-view-tags' )
36 this.buttons.aggregate( { click: 'buttonClick' } );
39 this.model.connect( this, { update: 'onModelUpdate' } );
40 this.buttons.connect( this, { buttonClick: 'onButtonClick' } );
43 .addClass( 'mw-rcfilters-ui-viewSwitchWidget' )
45 new OO.ui.LabelWidget( {
46 label: mw.msg( 'rcfilters-advancedfilters' )
49 .addClass( 'mw-rcfilters-ui-viewSwitchWidget-buttons' )
50 .append( this.buttons.$element )
56 OO.inheritClass( ViewSwitchWidget, OO.ui.Widget );
59 * Respond to model update event
61 ViewSwitchWidget.prototype.onModelUpdate = function () {
62 const currentView = this.model.getCurrentView();
64 this.buttons.getItems().forEach( ( buttonWidget ) => {
65 buttonWidget.setActive( buttonWidget.getData() === currentView );
70 * Respond to button switch click
72 * @param {OO.ui.ButtonWidget} buttonWidget Clicked button
74 ViewSwitchWidget.prototype.onButtonClick = function ( buttonWidget ) {
75 this.controller.switchView( buttonWidget.getData() );
78 module.exports = ViewSwitchWidget;