Merge "Make RecentChangesUpdateJob::updateActiveUsers more robust"
[lhc/web/wiklou.git] / resources / src / mediawiki.rcfilters / ui / mw.rcfilters.ui.ChangesListWrapperWidget.js
1 ( function ( mw ) {
2 /**
3 * List of changes
4 *
5 * @extends OO.ui.Widget
6 * @mixins OO.ui.mixin.PendingElement
7 *
8 * @constructor
9 * @param {mw.rcfilters.dm.ChangesListViewModel} model View model
10 * @param {jQuery} $changesListRoot Root element of the changes list to attach to
11 * @param {Object} config Configuration object
12 */
13 mw.rcfilters.ui.ChangesListWrapperWidget = function MwRcfiltersUiChangesListWrapperWidget( model, $changesListRoot, config ) {
14 config = config || {};
15
16 // Parent
17 mw.rcfilters.ui.ChangesListWrapperWidget.parent.call( this, $.extend( {}, config, {
18 $element: $changesListRoot
19 } ) );
20 // Mixin constructors
21 OO.ui.mixin.PendingElement.call( this, config );
22
23 this.model = model;
24
25 // Events
26 this.model.connect( this, {
27 invalidate: 'onModelInvalidate',
28 update: 'onModelUpdate'
29 } );
30 };
31
32 /* Initialization */
33
34 OO.inheritClass( mw.rcfilters.ui.ChangesListWrapperWidget, OO.ui.Widget );
35 OO.mixinClass( mw.rcfilters.ui.ChangesListWrapperWidget, OO.ui.mixin.PendingElement );
36
37 /**
38 * Respond to model invalidate
39 */
40 mw.rcfilters.ui.ChangesListWrapperWidget.prototype.onModelInvalidate = function () {
41 this.pushPending();
42 };
43
44 /**
45 * Respond to model update
46 *
47 * @param {jQuery|string} changesListContent The content of the updated changes list
48 */
49 mw.rcfilters.ui.ChangesListWrapperWidget.prototype.onModelUpdate = function ( changesListContent ) {
50 var isEmpty = changesListContent === 'NO_RESULTS';
51 this.$element.toggleClass( 'mw-changeslist', !isEmpty );
52 this.$element.toggleClass( 'mw-changeslist-empty', isEmpty );
53 this.$element.empty().append(
54 isEmpty ?
55 document.createTextNode( mw.message( 'recentchanges-noresult' ).text() ) :
56 changesListContent
57 );
58 this.popPending();
59 };
60 }( mediaWiki ) );