Merge "Align "What's this" vertically"
[lhc/web/wiklou.git] / resources / src / mediawiki.rcfilters / ui / mw.rcfilters.ui.LiveUpdateButtonWidget.js
1 ( function ( mw ) {
2 /**
3 * Widget for toggling live updates
4 *
5 * @extends OO.ui.ToggleButtonWidget
6 *
7 * @constructor
8 * @param {mw.rcfilters.Controller} controller
9 * @param {mw.rcfilters.dm.ChangesListViewModel} changesListModel
10 * @param {Object} [config] Configuration object
11 */
12 mw.rcfilters.ui.LiveUpdateButtonWidget = function MwRcfiltersUiLiveUpdateButtonWidget( controller, changesListModel, config ) {
13 config = config || {};
14
15 // Parent
16 mw.rcfilters.ui.LiveUpdateButtonWidget.parent.call( this, $.extend( {
17 label: mw.message( 'rcfilters-liveupdates-button' ).text()
18 }, config ) );
19
20 this.controller = controller;
21 this.model = changesListModel;
22
23 // Events
24 this.connect( this, { click: 'onClick' } );
25 this.model.connect( this, { liveUpdateChange: 'onLiveUpdateChange' } );
26
27 this.$element.addClass( 'mw-rcfilters-ui-liveUpdateButtonWidget' );
28
29 this.setState( false );
30 };
31
32 /* Initialization */
33
34 OO.inheritClass( mw.rcfilters.ui.LiveUpdateButtonWidget, OO.ui.ToggleButtonWidget );
35
36 /* Methods */
37
38 /**
39 * Respond to the button being clicked
40 */
41 mw.rcfilters.ui.LiveUpdateButtonWidget.prototype.onClick = function () {
42 this.controller.toggleLiveUpdate();
43 };
44
45 /**
46 * Set the button's state and change its appearance
47 *
48 * @param {boolean} enable Whether the 'live update' feature is now on/off
49 */
50 mw.rcfilters.ui.LiveUpdateButtonWidget.prototype.setState = function ( enable ) {
51 this.setValue( enable );
52 this.setIcon( enable ? 'stop' : 'play' );
53 this.setTitle( mw.message(
54 enable ?
55 'rcfilters-liveupdates-button-title-on' :
56 'rcfilters-liveupdates-button-title-off'
57 ).text() );
58 };
59
60 /**
61 * Respond to the 'live update' feature being turned on/off
62 *
63 * @param {boolean} enable Whether the 'live update' feature is now on/off
64 */
65 mw.rcfilters.ui.LiveUpdateButtonWidget.prototype.onLiveUpdateChange = function ( enable ) {
66 this.setState( enable );
67 };
68
69 }( mediaWiki ) );