Merge "WatchedItemStoreUnitTest return strings in db mocks"
[lhc/web/wiklou.git] / resources / src / mediawiki.rcfilters / ui / mw.rcfilters.ui.FilterWrapperWidget.js
1 ( function ( mw ) {
2 /**
3 * List displaying all filter groups
4 *
5 * @extends OO.ui.Widget
6 * @mixins OO.ui.mixin.PendingElement
7 *
8 * @constructor
9 * @param {mw.rcfilters.Controller} controller Controller
10 * @param {mw.rcfilters.dm.FiltersViewModel} model View model
11 * @param {mw.rcfilters.dm.SavedQueriesModel} savedQueriesModel Saved queries model
12 * @param {mw.rcfilters.dm.ChangesListViewModel} changesListModel
13 * @param {Object} [config] Configuration object
14 * @cfg {Object} [filters] A definition of the filter groups in this list
15 * @cfg {jQuery} [$overlay] A jQuery object serving as overlay for popups
16 */
17 mw.rcfilters.ui.FilterWrapperWidget = function MwRcfiltersUiFilterWrapperWidget(
18 controller, model, savedQueriesModel, changesListModel, config
19 ) {
20 var $bottom;
21 config = config || {};
22
23 // Parent
24 mw.rcfilters.ui.FilterWrapperWidget.parent.call( this, config );
25 // Mixin constructors
26 OO.ui.mixin.PendingElement.call( this, config );
27
28 this.controller = controller;
29 this.model = model;
30 this.queriesModel = savedQueriesModel;
31 this.changesListModel = changesListModel;
32 this.$overlay = config.$overlay || this.$element;
33
34 this.filterTagWidget = new mw.rcfilters.ui.FilterTagMultiselectWidget(
35 this.controller,
36 this.model,
37 this.queriesModel,
38 { $overlay: this.$overlay }
39 );
40
41 this.liveUpdateButton = new mw.rcfilters.ui.LiveUpdateButtonWidget(
42 this.controller,
43 this.changesListModel
44 );
45
46 this.numChangesWidget = new mw.rcfilters.ui.ChangesLimitAndDateButtonWidget(
47 this.controller,
48 this.model,
49 {
50 $overlay: this.$overlay
51 }
52 );
53
54 this.showNewChangesLink = new OO.ui.ButtonWidget( {
55 icon: 'reload',
56 framed: false,
57 label: mw.msg( 'rcfilters-show-new-changes' ),
58 flags: [ 'progressive' ]
59 } );
60
61 // Initialize
62 this.$top = $( '<div>' )
63 .addClass( 'mw-rcfilters-ui-filterWrapperWidget-top' );
64
65 $bottom = $( '<div>' )
66 .addClass( 'mw-rcfilters-ui-filterWrapperWidget-bottom' )
67 .append(
68 this.showNewChangesLink.$element,
69 this.numChangesWidget.$element
70 );
71
72 if ( mw.rcfilters.featureFlags.liveUpdate ) {
73 $bottom.prepend( this.liveUpdateButton.$element );
74 }
75
76 // Events
77 this.changesListModel.connect( this, { newChangesExist: 'onNewChangesExist' } );
78 this.showNewChangesLink.connect( this, { click: 'onShowNewChangesClick' } );
79 this.showNewChangesLink.toggle( false );
80
81 this.$element
82 .addClass( 'mw-rcfilters-ui-filterWrapperWidget' )
83 .append(
84 this.$top,
85 this.filterTagWidget.$element,
86 $bottom
87 );
88 };
89
90 /* Initialization */
91
92 OO.inheritClass( mw.rcfilters.ui.FilterWrapperWidget, OO.ui.Widget );
93 OO.mixinClass( mw.rcfilters.ui.FilterWrapperWidget, OO.ui.mixin.PendingElement );
94
95 /* Methods */
96
97 /**
98 * Set the content of the top section
99 *
100 * @param {jQuery} $topSectionElement
101 */
102 mw.rcfilters.ui.FilterWrapperWidget.prototype.setTopSection = function ( $topSectionElement ) {
103 this.$top.append( $topSectionElement );
104 };
105
106 /**
107 * Respond to the user clicking the 'show new changes' button
108 */
109 mw.rcfilters.ui.FilterWrapperWidget.prototype.onShowNewChangesClick = function () {
110 this.controller.showNewChanges();
111 };
112
113 /**
114 * Respond to changes list model newChangesExist
115 *
116 * @param {boolean} newChangesExist Whether new changes exist
117 */
118 mw.rcfilters.ui.FilterWrapperWidget.prototype.onNewChangesExist = function ( newChangesExist ) {
119 this.showNewChangesLink.toggle( newChangesExist );
120 };
121 }( mediaWiki ) );