2 * Widget for toggling live updates.
4 * @class mw.rcfilters.ui.LiveUpdateButtonWidget
6 * @extends OO.ui.ToggleButtonWidget
8 * @param {mw.rcfilters.Controller} controller
9 * @param {mw.rcfilters.dm.ChangesListViewModel} changesListModel
10 * @param {Object} [config] Configuration object
12 const LiveUpdateButtonWidget = function MwRcfiltersUiLiveUpdateButtonWidget( controller, changesListModel, config ) {
13 config = config || {};
16 LiveUpdateButtonWidget.super.call( this, Object.assign( {
17 label: mw.msg( 'rcfilters-liveupdates-button' )
20 this.controller = controller;
21 this.model = changesListModel;
24 this.connect( this, { click: 'onClick' } );
25 this.model.connect( this, { liveUpdateChange: 'onLiveUpdateChange' } );
27 this.$element.addClass( 'mw-rcfilters-ui-liveUpdateButtonWidget' );
29 this.setState( false );
34 OO.inheritClass( LiveUpdateButtonWidget, OO.ui.ToggleButtonWidget );
39 * Respond to the button being clicked
41 LiveUpdateButtonWidget.prototype.onClick = function () {
42 this.controller.toggleLiveUpdate();
46 * Set the button's state and change its appearance
48 * @param {boolean} enable Whether the 'live update' feature is now on/off
50 LiveUpdateButtonWidget.prototype.setState = function ( enable ) {
51 this.setValue( enable );
52 this.setIcon( enable ? 'stop' : 'play' );
53 this.setTitle( mw.msg(
55 'rcfilters-liveupdates-button-title-on' :
56 'rcfilters-liveupdates-button-title-off'
61 * Respond to the 'live update' feature being turned on/off
63 * @param {boolean} enable Whether the 'live update' feature is now on/off
65 LiveUpdateButtonWidget.prototype.onLiveUpdateChange = function ( enable ) {
66 this.setState( enable );
69 module.exports = LiveUpdateButtonWidget;