3 * Widget to select to view changes that link TO or FROM the target page
4 * on Special:RecentChangesLinked (AKA Related Changes)
6 * @class mw.rcfilters.ui.RclToOrFromWidget
7 * @extends OO.ui.DropdownWidget
10 * @param {mw.rcfilters.Controller} controller
11 * @param {mw.rcfilters.dm.FilterItem} showLinkedToModel model this widget is bound to
12 * @param {Object} [config] Configuration object
14 var RclToOrFromWidget
= function MwRcfiltersUiRclToOrFromWidget(
15 controller
, showLinkedToModel
, config
17 config
= config
|| {};
19 this.showLinkedFrom
= new OO
.ui
.MenuOptionWidget( {
20 data
: 'from', // default (showlinkedto=0)
21 label
: new OO
.ui
.HtmlSnippet( mw
.msg( 'rcfilters-filter-showlinkedfrom-option-label' ) )
23 this.showLinkedTo
= new OO
.ui
.MenuOptionWidget( {
24 data
: 'to', // showlinkedto=1
25 label
: new OO
.ui
.HtmlSnippet( mw
.msg( 'rcfilters-filter-showlinkedto-option-label' ) )
29 RclToOrFromWidget
.parent
.call( this, $.extend( {
30 classes
: [ 'mw-rcfilters-ui-rclToOrFromWidget' ],
31 menu
: { items
: [ this.showLinkedFrom
, this.showLinkedTo
] }
34 this.controller
= controller
;
35 this.model
= showLinkedToModel
;
37 this.getMenu().connect( this, { choose
: 'onUserChooseItem' } );
38 this.model
.connect( this, { update
: 'onModelUpdate' } );
40 // force an initial update of the component based on the state
46 OO
.inheritClass( RclToOrFromWidget
, OO
.ui
.DropdownWidget
);
51 * Respond to the user choosing an item in the menu
53 * @param {OO.ui.MenuOptionWidget} chosenItem
55 RclToOrFromWidget
.prototype.onUserChooseItem = function ( chosenItem
) {
56 this.controller
.setShowLinkedTo( chosenItem
.getData() === 'to' );
60 * Respond to model update
62 RclToOrFromWidget
.prototype.onModelUpdate = function () {
63 this.getMenu().selectItem(
64 this.model
.isSelected() ?
68 this.setLabel( mw
.msg(
69 this.model
.isSelected() ?
70 'rcfilters-filter-showlinkedto-label' :
71 'rcfilters-filter-showlinkedfrom-label'
75 module
.exports
= RclToOrFromWidget
;