Merge "RCFilters: Add 'views' concept and a namespace view to RCFilters"
[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 {Object} [config] Configuration object
13 * @cfg {Object} [filters] A definition of the filter groups in this list
14 * @cfg {jQuery} [$overlay] A jQuery object serving as overlay for popups
15 */
16 mw.rcfilters.ui.FilterWrapperWidget = function MwRcfiltersUiFilterWrapperWidget( controller, model, savedQueriesModel, config ) {
17 config = config || {};
18
19 // Parent
20 mw.rcfilters.ui.FilterWrapperWidget.parent.call( this, config );
21 // Mixin constructors
22 OO.ui.mixin.PendingElement.call( this, config );
23
24 this.controller = controller;
25 this.model = model;
26 this.queriesModel = savedQueriesModel;
27 this.$overlay = config.$overlay || this.$element;
28
29 this.filterTagWidget = new mw.rcfilters.ui.FilterTagMultiselectWidget(
30 this.controller,
31 this.model,
32 this.queriesModel,
33 { $overlay: this.$overlay }
34 );
35
36 this.namespaceButton = new OO.ui.ButtonWidget( {
37 label: mw.msg( 'namespaces' ),
38 icon: 'article',
39 classes: [ 'mw-rcfilters-ui-filterWrapperWidget-namespaceToggle' ]
40 } );
41 this.namespaceButton.setActive( this.model.getCurrentView() === 'namespaces' );
42
43 // Events
44 this.model.connect( this, { update: 'onModelUpdate' } );
45 this.namespaceButton.connect( this, { click: 'onNamespaceToggleClick' } );
46
47 // Initialize
48 this.$element
49 .addClass( 'mw-rcfilters-ui-filterWrapperWidget' );
50
51 if ( mw.config.get( 'wgStructuredChangeFiltersEnableSaving' ) ) {
52 this.savedLinksListWidget = new mw.rcfilters.ui.SavedLinksListWidget(
53 this.controller,
54 this.queriesModel,
55 { $overlay: this.$overlay }
56 );
57
58 this.$element.append(
59 this.savedLinksListWidget.$element
60 );
61
62 }
63
64 this.$element.append(
65 this.filterTagWidget.$element,
66 this.namespaceButton.$element
67 );
68 this.namespaceButton.toggle( !!mw.config.get( 'wgStructuredChangeFiltersEnableExperimentalViews' ) );
69 };
70
71 /* Initialization */
72
73 OO.inheritClass( mw.rcfilters.ui.FilterWrapperWidget, OO.ui.Widget );
74 OO.mixinClass( mw.rcfilters.ui.FilterWrapperWidget, OO.ui.mixin.PendingElement );
75
76 /* Methods */
77
78 /**
79 * Respond to model update event
80 */
81 mw.rcfilters.ui.FilterWrapperWidget.prototype.onModelUpdate = function () {
82 // Synchronize the state of the toggle button with the current view
83 this.namespaceButton.setActive( this.model.getCurrentView() === 'namespaces' );
84 };
85
86 /**
87 * Respond to namespace toggle button click
88 */
89 mw.rcfilters.ui.FilterWrapperWidget.prototype.onNamespaceToggleClick = function () {
90 this.controller.switchView( 'namespaces' );
91 this.filterTagWidget.focus();
92 };
93 }( mediaWiki ) );