Merge "resourceloader: Simplify StringSet fallback"
[lhc/web/wiklou.git] / resources / src / mediawiki.rcfilters / ui / mw.rcfilters.ui.LiveUpdateButtonWidget.js
index 8bab981..926ff4a 100644 (file)
@@ -1,4 +1,4 @@
-( function ( mw ) {
+( function () {
        /**
         * Widget for toggling live updates
         *
@@ -6,23 +6,27 @@
         *
         * @constructor
         * @param {mw.rcfilters.Controller} controller
-        * @param {Object} config Configuration object
+        * @param {mw.rcfilters.dm.ChangesListViewModel} changesListModel
+        * @param {Object} [config] Configuration object
         */
-       mw.rcfilters.ui.LiveUpdateButtonWidget = function MwRcfiltersUiLiveUpdateButtonWidget( controller, config ) {
+       mw.rcfilters.ui.LiveUpdateButtonWidget = function MwRcfiltersUiLiveUpdateButtonWidget( controller, changesListModel, config ) {
                config = config || {};
 
                // Parent
                mw.rcfilters.ui.LiveUpdateButtonWidget.parent.call( this, $.extend( {
-                       icon: 'play',
                        label: mw.message( 'rcfilters-liveupdates-button' ).text()
-               } ), config );
+               }, config ) );
 
                this.controller = controller;
+               this.model = changesListModel;
 
                // Events
-               this.connect( this, { change: 'onChange' } );
+               this.connect( this, { click: 'onClick' } );
+               this.model.connect( this, { liveUpdateChange: 'onLiveUpdateChange' } );
 
                this.$element.addClass( 'mw-rcfilters-ui-liveUpdateButtonWidget' );
+
+               this.setState( false );
        };
 
        /* Initialization */
        /* Methods */
 
        /**
-        * Respond to the button being toggled.
-        * @param {boolean} enable Whether the button is now pressed/enabled
+        * Respond to the button being clicked
+        */
+       mw.rcfilters.ui.LiveUpdateButtonWidget.prototype.onClick = function () {
+               this.controller.toggleLiveUpdate();
+       };
+
+       /**
+        * Set the button's state and change its appearance
+        *
+        * @param {boolean} enable Whether the 'live update' feature is now on/off
+        */
+       mw.rcfilters.ui.LiveUpdateButtonWidget.prototype.setState = function ( enable ) {
+               this.setValue( enable );
+               this.setIcon( enable ? 'stop' : 'play' );
+               this.setTitle( mw.message(
+                       enable ?
+                               'rcfilters-liveupdates-button-title-on' :
+                               'rcfilters-liveupdates-button-title-off'
+               ).text() );
+       };
+
+       /**
+        * Respond to the 'live update' feature being turned on/off
+        *
+        * @param {boolean} enable Whether the 'live update' feature is now on/off
         */
-       mw.rcfilters.ui.LiveUpdateButtonWidget.prototype.onChange = function ( enable ) {
-               this.controller.toggleLiveUpdate( enable );
+       mw.rcfilters.ui.LiveUpdateButtonWidget.prototype.onLiveUpdateChange = function ( enable ) {
+               this.setState( enable );
        };
 
-}( mediaWiki ) );
+}() );