1 const SavedLinksListWidget = require( './SavedLinksListWidget.js' ),
2 FilterWrapperWidget = require( './FilterWrapperWidget.js' ),
3 ChangesListWrapperWidget = require( './ChangesListWrapperWidget.js' ),
4 RcTopSectionWidget = require( './RcTopSectionWidget.js' ),
5 RclTopSectionWidget = require( './RclTopSectionWidget.js' ),
6 WatchlistTopSectionWidget = require( './WatchlistTopSectionWidget.js' ),
7 FormWrapperWidget = require( './FormWrapperWidget.js' );
10 * Wrapper for changes list content.
12 * @class mw.rcfilters.ui.MainWrapperWidget
14 * @extends OO.ui.Widget
16 * @param {mw.rcfilters.Controller} controller Controller
17 * @param {mw.rcfilters.dm.FiltersViewModel} model View model
18 * @param {mw.rcfilters.dm.SavedQueriesModel} savedQueriesModel Saved queries model
19 * @param {mw.rcfilters.dm.ChangesListViewModel} changesListModel
20 * @param {Object} config Configuration object
21 * @param {jQuery} config.$topSection Top section container
22 * @param {jQuery} config.$filtersContainer
23 * @param {jQuery} config.$changesListContainer
24 * @param {jQuery} config.$formContainer
25 * @param {boolean} [config.collapsed] Filter area is collapsed
26 * @param {jQuery} [config.$wrapper] A jQuery object for the wrapper of the general
27 * system. If not given, falls back to this widget's $element
29 const MainWrapperWidget = function MwRcfiltersUiMainWrapperWidget(
30 controller, model, savedQueriesModel, changesListModel, config
32 config = Object.assign( {}, config );
35 MainWrapperWidget.super.call( this, config );
37 this.controller = controller;
39 this.changesListModel = changesListModel;
40 this.$topSection = config.$topSection;
41 this.$filtersContainer = config.$filtersContainer;
42 this.$changesListContainer = config.$changesListContainer;
43 this.$formContainer = config.$formContainer;
44 this.$overlay = $( '<div>' ).addClass( 'mw-rcfilters-ui-overlay' );
45 this.$wrapper = config.$wrapper || this.$element;
47 this.savedLinksListWidget = new SavedLinksListWidget(
48 controller, savedQueriesModel, { $overlay: this.$overlay }
51 this.filtersWidget = new FilterWrapperWidget(
57 $overlay: this.$overlay,
58 $wrapper: this.$wrapper,
59 collapsed: config.collapsed
63 this.changesListWidget = new ChangesListWrapperWidget(
64 model, changesListModel, controller, this.$changesListContainer );
68 // Toggle changes list overlay when filters menu opens/closes. We use overlay on changes list
69 // to prevent users from accidentally clicking on links in results, while menu is opened.
70 // Overlay on changes list is not the same as this.$overlay
71 this.filtersWidget.connect( this, { menuToggle: this.onFilterMenuToggle.bind( this ) } );
74 this.$filtersContainer.append( this.filtersWidget.$element );
75 $( document.body ).addClass( 'mw-rcfilters-ui-initialized' );
76 $( OO.ui.getTeleportTarget() ).append( this.$overlay );
81 OO.inheritClass( MainWrapperWidget, OO.ui.Widget );
86 * Set the content of the top section, depending on the type of special page.
88 * @param {string} specialPage
90 MainWrapperWidget.prototype.setTopSection = function ( specialPage ) {
93 if ( specialPage === 'Recentchanges' ) {
94 topSection = new RcTopSectionWidget(
95 this.savedLinksListWidget, this.$topSection
97 this.filtersWidget.setTopSection( topSection.$element );
100 if ( specialPage === 'Recentchangeslinked' ) {
101 topSection = new RclTopSectionWidget(
102 this.savedLinksListWidget, this.controller,
103 this.model.getGroup( 'toOrFrom' ).getItemByParamName( 'showlinkedto' ),
104 this.model.getGroup( 'page' ).getItemByParamName( 'target' )
107 this.filtersWidget.setTopSection( topSection.$element );
110 if ( specialPage === 'Watchlist' ) {
111 topSection = new WatchlistTopSectionWidget(
112 this.controller, this.changesListModel, this.savedLinksListWidget, this.$topSection
115 this.filtersWidget.setTopSection( topSection.$element );
120 * Filter menu toggle event listener
122 * @param {boolean} isVisible
124 MainWrapperWidget.prototype.onFilterMenuToggle = function ( isVisible ) {
125 this.changesListWidget.toggleOverlay( isVisible );
129 * Initialize FormWrapperWidget
132 * @return {mw.rcfilters.ui.FormWrapperWidget} Form wrapper widget
134 MainWrapperWidget.prototype.initFormWidget = function () {
135 return new FormWrapperWidget(
136 this.model, this.changesListModel, this.controller, this.$formContainer );
139 module.exports = MainWrapperWidget;