summaryrefslogtreecommitdiff
path: root/www/wiki/resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.MainWrapperWidget.js
blob: 8002045dc8fa64f879912163c7f1d24673cf46e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
( function ( $, mw ) {
	/**
	 * Wrapper for changes list content
	 *
	 * @extends OO.ui.Widget
	 *
	 * @constructor
	 * @param {mw.rcfilters.Controller} controller Controller
	 * @param {mw.rcfilters.dm.FiltersViewModel} model View model
	 * @param {mw.rcfilters.dm.SavedQueriesModel} savedQueriesModel Saved queries model
	 * @param {mw.rcfilters.dm.ChangesListViewModel} changesListModel
	 * @param {Object} config Configuration object
	 * @cfg {jQuery} $topSection Top section container
	 * @cfg {jQuery} $filtersContainer
	 * @cfg {jQuery} $changesListContainer
	 * @cfg {jQuery} $formContainer
	 */
	mw.rcfilters.ui.MainWrapperWidget = function MwRcfiltersUiMainWrapperWidget(
		controller, model, savedQueriesModel, changesListModel, config
	) {
		config = $.extend( {}, config );

		// Parent
		mw.rcfilters.ui.MainWrapperWidget.parent.call( this, config );

		this.controller = controller;
		this.model = model;
		this.changesListModel = changesListModel;
		this.$topSection = config.$topSection;
		this.$filtersContainer = config.$filtersContainer;
		this.$changesListContainer = config.$changesListContainer;
		this.$formContainer = config.$formContainer;
		this.$overlay = $( '<div>' ).addClass( 'mw-rcfilters-ui-overlay' );

		this.savedLinksListWidget = new mw.rcfilters.ui.SavedLinksListWidget(
			controller, savedQueriesModel, { $overlay: this.$overlay }
		);

		this.filtersWidget = new mw.rcfilters.ui.FilterWrapperWidget(
			controller,
			model,
			savedQueriesModel,
			changesListModel,
			{
				$overlay: this.$overlay
			}
		);

		this.changesListWidget = new mw.rcfilters.ui.ChangesListWrapperWidget(
			model, changesListModel, controller, this.$changesListContainer );

		/* Events */

		// Toggle changes list overlay when filters menu opens/closes. We use overlay on changes list
		// to prevent users from accidentally clicking on links in results, while menu is opened.
		// Overlay on changes list is not the same as this.$overlay
		this.filtersWidget.connect( this, { menuToggle: this.onFilterMenuToggle.bind( this ) } );

		// Initialize
		this.$filtersContainer.append( this.filtersWidget.$element );
		$( 'body' )
			.append( this.$overlay )
			.addClass( 'mw-rcfilters-ui-initialized' );
	};

	/* Initialization */

	OO.inheritClass( mw.rcfilters.ui.MainWrapperWidget, OO.ui.Widget );

	/* Methods */

	/**
	 * Set the content of the top section, depending on the type of special page.
	 *
	 * @param {string} specialPage
	 */
	mw.rcfilters.ui.MainWrapperWidget.prototype.setTopSection = function ( specialPage ) {
		var topSection;

		if ( specialPage === 'Recentchanges' ) {
			topSection = new mw.rcfilters.ui.RcTopSectionWidget(
				this.savedLinksListWidget, this.$topSection
			);
			this.filtersWidget.setTopSection( topSection.$element );
		}

		if ( specialPage === 'Recentchangeslinked' ) {
			topSection = new mw.rcfilters.ui.RclTopSectionWidget(
				this.savedLinksListWidget, this.controller,
				this.model.getGroup( 'toOrFrom' ).getItemByParamName( 'showlinkedto' ),
				this.model.getGroup( 'page' ).getItemByParamName( 'target' )
			);

			this.filtersWidget.setTopSection( topSection.$element );
		}

		if ( specialPage === 'Watchlist' ) {
			topSection = new mw.rcfilters.ui.WatchlistTopSectionWidget(
				this.controller, this.changesListModel, this.savedLinksListWidget, this.$topSection
			);

			this.filtersWidget.setTopSection( topSection.$element );
		}
	};

	/**
	 * Filter menu toggle event listener
	 *
	 * @param {boolean} isVisible
	 */
	mw.rcfilters.ui.MainWrapperWidget.prototype.onFilterMenuToggle = function ( isVisible ) {
		this.changesListWidget.toggleOverlay( isVisible );
	};

	/**
	 * Initialize FormWrapperWidget
	 *
	 * @return {mw.rcfilters.ui.FormWrapperWidget} Form wrapper widget
	 */
	mw.rcfilters.ui.MainWrapperWidget.prototype.initFormWidget = function () {
		return new mw.rcfilters.ui.FormWrapperWidget(
			this.model, this.changesListModel, this.controller, this.$formContainer );
	};
}( jQuery, mediaWiki ) );