1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
( function ( mw ) {
/**
* A widget for the footer for the default view, allowing to switch views
*
* @extends OO.ui.Widget
*
* @constructor
* @param {mw.rcfilters.Controller} controller Controller
* @param {mw.rcfilters.dm.FiltersViewModel} model View model
* @param {Object} [config] Configuration object
*/
mw.rcfilters.ui.ViewSwitchWidget = function MwRcfiltersUiViewSwitchWidget( controller, model, config ) {
config = config || {};
// Parent
mw.rcfilters.ui.ViewSwitchWidget.parent.call( this, config );
this.controller = controller;
this.model = model;
this.buttons = new mw.rcfilters.ui.GroupWidget( {
events: {
click: 'buttonClick'
},
items: [
new OO.ui.ButtonWidget( {
data: 'namespaces',
icon: 'article',
label: mw.msg( 'namespaces' )
} ),
new OO.ui.ButtonWidget( {
data: 'tags',
icon: 'tag',
label: mw.msg( 'rcfilters-view-tags' )
} )
]
} );
// Events
this.model.connect( this, { update: 'onModelUpdate' } );
this.buttons.connect( this, { buttonClick: 'onButtonClick' } );
this.$element
.addClass( 'mw-rcfilters-ui-viewSwitchWidget' )
.append(
new OO.ui.LabelWidget( {
label: mw.msg( 'rcfilters-advancedfilters' )
} ).$element,
$( '<div>' )
.addClass( 'mw-rcfilters-ui-viewSwitchWidget-buttons' )
.append( this.buttons.$element )
);
};
/* Initialize */
OO.inheritClass( mw.rcfilters.ui.ViewSwitchWidget, OO.ui.Widget );
/**
* Respond to model update event
*/
mw.rcfilters.ui.ViewSwitchWidget.prototype.onModelUpdate = function () {
var currentView = this.model.getCurrentView();
this.buttons.getItems().forEach( function ( buttonWidget ) {
buttonWidget.setActive( buttonWidget.getData() === currentView );
} );
};
/**
* Respond to button switch click
*
* @param {OO.ui.ButtonWidget} buttonWidget Clicked button
*/
mw.rcfilters.ui.ViewSwitchWidget.prototype.onButtonClick = function ( buttonWidget ) {
this.controller.switchView( buttonWidget.getData() );
};
}( mediaWiki ) );
|