blob: 4fce08c9826409435d481520707fba18e79aa62e (
plain)
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
|
( function ( mw ) {
/**
* Widget to select to view changes that link TO or FROM the target page
* on Special:RecentChangesLinked (AKA Related Changes)
*
* @extends OO.ui.DropdownWidget
*
* @constructor
* @param {mw.rcfilters.Controller} controller
* @param {mw.rcfilters.dm.FilterItem} showLinkedToModel model this widget is bound to
* @param {Object} [config] Configuration object
*/
mw.rcfilters.ui.RclToOrFromWidget = function MwRcfiltersUiRclToOrFromWidget(
controller, showLinkedToModel, config
) {
config = config || {};
this.showLinkedFrom = new OO.ui.MenuOptionWidget( {
data: 'from', // default (showlinkedto=0)
label: new OO.ui.HtmlSnippet( mw.msg( 'rcfilters-filter-showlinkedfrom-option-label' ) )
} );
this.showLinkedTo = new OO.ui.MenuOptionWidget( {
data: 'to', // showlinkedto=1
label: new OO.ui.HtmlSnippet( mw.msg( 'rcfilters-filter-showlinkedto-option-label' ) )
} );
// Parent
mw.rcfilters.ui.RclToOrFromWidget.parent.call( this, $.extend( {
classes: [ 'mw-rcfilters-ui-rclToOrFromWidget' ],
menu: { items: [ this.showLinkedFrom, this.showLinkedTo ] }
}, config ) );
this.controller = controller;
this.model = showLinkedToModel;
this.getMenu().connect( this, { choose: 'onUserChooseItem' } );
this.model.connect( this, { update: 'onModelUpdate' } );
// force an initial update of the component based on the state
this.onModelUpdate();
};
/* Initialization */
OO.inheritClass( mw.rcfilters.ui.RclToOrFromWidget, OO.ui.DropdownWidget );
/* Methods */
/**
* Respond to the user choosing an item in the menu
*
* @param {OO.ui.MenuOptionWidget} chosenItem
*/
mw.rcfilters.ui.RclToOrFromWidget.prototype.onUserChooseItem = function ( chosenItem ) {
this.controller.setShowLinkedTo( chosenItem.getData() === 'to' );
};
/**
* Respond to model update
*/
mw.rcfilters.ui.RclToOrFromWidget.prototype.onModelUpdate = function () {
this.getMenu().selectItem(
this.model.isSelected() ?
this.showLinkedTo :
this.showLinkedFrom
);
this.setLabel( mw.msg(
this.model.isSelected() ?
'rcfilters-filter-showlinkedto-label' :
'rcfilters-filter-showlinkedfrom-label'
) );
};
}( mediaWiki ) );
|