| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
const RclToOrFromWidget = function MwRcfiltersUiRclToOrFromWidget( |
| 14 |
controller, showLinkedToModel, config |
| 15 |
) { |
| 16 |
config = config || {}; |
| 17 |
|
| 18 |
this.showLinkedFrom = new OO.ui.MenuOptionWidget( { |
| 19 |
data: 'from', |
| 20 |
label: new OO.ui.HtmlSnippet( mw.message( 'rcfilters-filter-showlinkedfrom-option-label' ).parse() ) |
| 21 |
} ); |
| 22 |
this.showLinkedTo = new OO.ui.MenuOptionWidget( { |
| 23 |
data: 'to', |
| 24 |
label: new OO.ui.HtmlSnippet( mw.message( 'rcfilters-filter-showlinkedto-option-label' ).parse() ) |
| 25 |
} ); |
| 26 |
|
| 27 |
|
| 28 |
RclToOrFromWidget.super.call( this, Object.assign( { |
| 29 |
classes: [ 'mw-rcfilters-ui-rclToOrFromWidget' ], |
| 30 |
menu: { items: [ this.showLinkedFrom, this.showLinkedTo ] } |
| 31 |
}, config ) ); |
| 32 |
|
| 33 |
this.controller = controller; |
| 34 |
this.model = showLinkedToModel; |
| 35 |
|
| 36 |
this.getMenu().connect( this, { choose: 'onUserChooseItem' } ); |
| 37 |
this.model.connect( this, { update: 'onModelUpdate' } ); |
| 38 |
|
| 39 |
|
| 40 |
this.onModelUpdate(); |
| 41 |
}; |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
OO.inheritClass( RclToOrFromWidget, OO.ui.DropdownWidget ); |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
RclToOrFromWidget.prototype.onUserChooseItem = function ( chosenItem ) { |
| 55 |
this.controller.setShowLinkedTo( chosenItem.getData() === 'to' ); |
| 56 |
}; |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
RclToOrFromWidget.prototype.onModelUpdate = function () { |
| 62 |
this.getMenu().selectItem( |
| 63 |
this.model.isSelected() ? |
| 64 |
this.showLinkedTo : |
| 65 |
this.showLinkedFrom |
| 66 |
); |
| 67 |
this.setLabel( mw.msg( |
| 68 |
this.model.isSelected() ? |
| 69 |
'rcfilters-filter-showlinkedto-label' : |
| 70 |
'rcfilters-filter-showlinkedfrom-label' |
| 71 |
) ); |
| 72 |
}; |
| 73 |
|
| 74 |
module.exports = RclToOrFromWidget; |