1 const FilterTagMultiselectWidget = require( './FilterTagMultiselectWidget.js' ),
2 LiveUpdateButtonWidget = require( './LiveUpdateButtonWidget.js' ),
3 ChangesLimitAndDateButtonWidget = require( './ChangesLimitAndDateButtonWidget.js' );
6 * List displaying all filter groups.
8 * @class mw.rcfilters.ui.FilterWrapperWidget
10 * @extends OO.ui.Widget
11 * @mixes OO.ui.mixin.PendingElement
13 * @param {mw.rcfilters.Controller} controller Controller
14 * @param {mw.rcfilters.dm.FiltersViewModel} model View model
15 * @param {mw.rcfilters.dm.SavedQueriesModel} savedQueriesModel Saved queries model
16 * @param {mw.rcfilters.dm.ChangesListViewModel} changesListModel
17 * @param {Object} [config] Configuration object
18 * @param {Object} [config.filters] A definition of the filter groups in this list
19 * @param {jQuery} [config.$overlay] A jQuery object serving as overlay for popups
20 * @param {jQuery} [config.$wrapper] A jQuery object for the wrapper of the general
21 * system. If not given, falls back to this widget's $element
22 * @param {boolean} [config.collapsed] Filter area is collapsed
24 const FilterWrapperWidget = function MwRcfiltersUiFilterWrapperWidget(
25 controller, model, savedQueriesModel, changesListModel, config
27 config = config || {};
30 FilterWrapperWidget.super.call( this, config );
32 OO.ui.mixin.PendingElement.call( this, config );
34 this.controller = controller;
36 this.queriesModel = savedQueriesModel;
37 this.changesListModel = changesListModel;
38 this.$overlay = config.$overlay || this.$element;
39 this.$wrapper = config.$wrapper || this.$element;
41 this.filterTagWidget = new FilterTagMultiselectWidget(
46 $overlay: this.$overlay,
47 collapsed: config.collapsed,
48 $wrapper: this.$wrapper,
49 isMobile: OO.ui.isMobile()
53 this.liveUpdateButton = new LiveUpdateButtonWidget(
58 this.numChangesAndDateWidget = new ChangesLimitAndDateButtonWidget(
62 $overlay: this.$overlay
66 this.showNewChangesLink = new OO.ui.ButtonWidget( {
69 flags: [ 'progressive' ],
70 classes: [ 'mw-rcfilters-ui-filterWrapperWidget-showNewChanges' ]
74 this.filterTagWidget.menu.connect( this, { toggle: [ 'emit', 'menuToggle' ] } );
75 this.changesListModel.connect( this, { newChangesExist: 'onNewChangesExist' } );
76 this.showNewChangesLink.connect( this, { click: 'onShowNewChangesClick' } );
77 this.showNewChangesLink.toggle( false );
80 this.$top = $( '<div>' )
81 .addClass( 'mw-rcfilters-ui-filterWrapperWidget-top' );
83 const $bottom = $( '<div>' )
84 .addClass( 'mw-rcfilters-ui-filterWrapperWidget-bottom' )
85 .addClass( OO.ui.isMobile() ? 'mw-rcfilters-ui-filterWrapperWidget-bottom-mobile' : '' )
87 this.showNewChangesLink.$element,
88 this.numChangesAndDateWidget.$element
91 if ( this.controller.pollingRate ) {
92 $bottom.prepend( this.liveUpdateButton.$element );
96 .addClass( 'mw-rcfilters-ui-filterWrapperWidget' )
99 this.filterTagWidget.$element,
106 OO.inheritClass( FilterWrapperWidget, OO.ui.Widget );
107 OO.mixinClass( FilterWrapperWidget, OO.ui.mixin.PendingElement );
112 * Set the content of the top section
114 * @param {jQuery} $topSectionElement
116 FilterWrapperWidget.prototype.setTopSection = function ( $topSectionElement ) {
117 this.$top.append( $topSectionElement );
121 * Respond to the user clicking the 'show new changes' button
123 FilterWrapperWidget.prototype.onShowNewChangesClick = function () {
124 this.controller.showNewChanges();
128 * Respond to changes list model newChangesExist
130 * @param {boolean} newChangesExist Whether new changes exist
132 FilterWrapperWidget.prototype.onNewChangesExist = function ( newChangesExist ) {
133 if ( newChangesExist ) {
134 this.showNewChangesLink.setLabel(
136 'rcfilters-show-new-changes',
137 this.changesListModel.getNextFromFormatted()
141 this.showNewChangesLink.toggle( newChangesExist );
144 module.exports = FilterWrapperWidget;