2 * Widget to select to view changes that link TO or FROM the target page
3 * on Special:RecentChangesLinked (AKA Related Changes).
5 * @class mw.rcfilters.ui.RclToOrFromWidget
7 * @extends OO.ui.DropdownWidget
9 * @param {mw.rcfilters.Controller} controller
10 * @param {mw.rcfilters.dm.FilterItem} showLinkedToModel model this widget is bound to
11 * @param {Object} [config] Configuration object
13 const RclToOrFromWidget = function MwRcfiltersUiRclToOrFromWidget(
14 controller, showLinkedToModel, config
16 config = config || {};
18 this.showLinkedFrom = new OO.ui.MenuOptionWidget( {
19 data: 'from', // default (showlinkedto=0)
20 label: new OO.ui.HtmlSnippet( mw.msg( 'rcfilters-filter-showlinkedfrom-option-label' ) )
22 this.showLinkedTo = new OO.ui.MenuOptionWidget( {
23 data: 'to', // showlinkedto=1
24 label: new OO.ui.HtmlSnippet( mw.msg( 'rcfilters-filter-showlinkedto-option-label' ) )
28 RclToOrFromWidget.super.call( this, Object.assign( {
29 classes: [ 'mw-rcfilters-ui-rclToOrFromWidget' ],
30 menu: { items: [ this.showLinkedFrom, this.showLinkedTo ] }
33 this.controller = controller;
34 this.model = showLinkedToModel;
36 this.getMenu().connect( this, { choose: 'onUserChooseItem' } );
37 this.model.connect( this, { update: 'onModelUpdate' } );
39 // force an initial update of the component based on the state
45 OO.inheritClass( RclToOrFromWidget, OO.ui.DropdownWidget );
50 * Respond to the user choosing an item in the menu
52 * @param {OO.ui.MenuOptionWidget} chosenItem
54 RclToOrFromWidget.prototype.onUserChooseItem = function ( chosenItem ) {
55 this.controller.setShowLinkedTo( chosenItem.getData() === 'to' );
59 * Respond to model update
61 RclToOrFromWidget.prototype.onModelUpdate = function () {
62 this.getMenu().selectItem(
63 this.model.isSelected() ?
67 this.setLabel( mw.msg(
68 this.model.isSelected() ?
69 'rcfilters-filter-showlinkedto-label' :
70 'rcfilters-filter-showlinkedfrom-label'
74 module.exports = RclToOrFromWidget;