2 * Menu header for the RCFilters filters menu.
4 * @class mw.rcfilters.ui.FilterMenuHeaderWidget
6 * @extends OO.ui.Widget
8 * @param {mw.rcfilters.Controller} controller Controller
9 * @param {mw.rcfilters.dm.FiltersViewModel} model View model
10 * @param {Object} config Configuration object
11 * @param {jQuery} [config.$overlay] A jQuery object serving as overlay for popups
13 const FilterMenuHeaderWidget = function MwRcfiltersUiFilterMenuHeaderWidget( controller, model, config ) {
14 config = config || {};
16 this.controller = controller;
18 this.$overlay = config.$overlay || this.$element;
21 FilterMenuHeaderWidget.super.call( this, config );
22 OO.ui.mixin.LabelElement.call( this, Object.assign( {
23 label: mw.msg( 'rcfilters-filterlist-title' ),
25 .addClass( 'mw-rcfilters-ui-filterMenuHeaderWidget-title' )
28 // "Back" to default view button
29 this.backButton = new OO.ui.ButtonWidget( {
32 title: mw.msg( 'rcfilters-view-return-to-default-tooltip' ),
33 classes: [ 'mw-rcfilters-ui-filterMenuHeaderWidget-backButton' ]
35 this.backButton.toggle( this.model.getCurrentView() !== 'default' );
37 // Help icon for Tagged edits
38 this.helpIcon = new OO.ui.ButtonWidget( {
41 title: mw.msg( 'rcfilters-view-tags-help-icon-tooltip' ),
42 classes: [ 'mw-rcfilters-ui-filterMenuHeaderWidget-helpIcon' ],
43 href: mw.util.getUrl( 'Special:Tags' ),
46 this.helpIcon.toggle( this.model.getCurrentView() === 'tags' );
49 this.highlightButton = new OO.ui.ToggleButtonWidget( {
51 label: mw.msg( 'rcfilters-highlightbutton-title' ),
52 classes: [ 'mw-rcfilters-ui-filterMenuHeaderWidget-hightlightButton' ]
56 this.invertTagsButton = new OO.ui.ToggleButtonWidget( {
58 classes: [ 'mw-rcfilters-ui-filterMenuHeaderWidget-invertTagsButton' ]
60 this.invertTagsButton.toggle( this.model.getCurrentView() === 'tags' );
61 this.invertNamespacesButton = new OO.ui.ToggleButtonWidget( {
63 classes: [ 'mw-rcfilters-ui-filterMenuHeaderWidget-invertNamespacesButton' ]
65 this.invertNamespacesButton.toggle( this.model.getCurrentView() === 'namespaces' );
68 this.backButton.connect( this, { click: 'onBackButtonClick' } );
70 .connect( this, { click: 'onHighlightButtonClick' } );
72 .connect( this, { click: 'onInvertTagsButtonClick' } );
73 this.invertNamespacesButton
74 .connect( this, { click: 'onInvertNamespacesButtonClick' } );
75 this.model.connect( this, {
76 highlightChange: 'onModelHighlightChange',
77 searchChange: 'onModelSearchChange',
78 initialize: 'onModelInitialize'
80 this.view = this.model.getCurrentView();
84 .addClass( 'mw-rcfilters-ui-filterMenuHeaderWidget' )
87 .addClass( 'mw-rcfilters-ui-table' )
88 .addClass( 'mw-rcfilters-ui-filterMenuHeaderWidget-header' )
91 .addClass( 'mw-rcfilters-ui-row' )
94 .addClass( 'mw-rcfilters-ui-cell' )
95 .addClass( 'mw-rcfilters-ui-filterMenuHeaderWidget-header-back' )
96 .append( this.backButton.$element ),
98 .addClass( 'mw-rcfilters-ui-cell' )
99 .addClass( 'mw-rcfilters-ui-filterMenuHeaderWidget-header-title' )
100 .append( this.$label, this.helpIcon.$element ),
102 .addClass( 'mw-rcfilters-ui-cell' )
103 .addClass( 'mw-rcfilters-ui-filterMenuHeaderWidget-header-invert' )
104 .append( this.invertTagsButton.$element ),
106 .addClass( 'mw-rcfilters-ui-cell' )
107 .addClass( 'mw-rcfilters-ui-filterMenuHeaderWidget-header-invert' )
108 .append( this.invertNamespacesButton.$element ),
110 .addClass( 'mw-rcfilters-ui-cell' )
111 .addClass( 'mw-rcfilters-ui-filterMenuHeaderWidget-header-highlight' )
112 .append( this.highlightButton.$element )
120 OO.inheritClass( FilterMenuHeaderWidget, OO.ui.Widget );
121 OO.mixinClass( FilterMenuHeaderWidget, OO.ui.mixin.LabelElement );
126 * Respond to model initialization event
128 * Note: need to wait for initialization before getting the invertModel
129 * and registering its update event. Creating all the models before the UI
130 * would help with that.
132 FilterMenuHeaderWidget.prototype.onModelInitialize = function () {
133 this.invertNamespacesModel = this.model.getNamespacesInvertModel();
134 this.updateInvertNamespacesButton();
135 this.invertNamespacesModel.connect( this, { update: 'updateInvertNamespacesButton' } );
137 this.invertTagsModel = this.model.getTagsInvertModel();
138 this.updateInvertTagsButton();
139 this.invertTagsModel.connect( this, { update: 'updateInvertTagsButton' } );
143 * Respond to model update event
145 FilterMenuHeaderWidget.prototype.onModelSearchChange = function () {
146 const currentView = this.model.getCurrentView();
148 if ( this.view !== currentView ) {
149 this.setLabel( this.model.getViewTitle( currentView ) );
151 this.invertTagsButton.toggle( currentView === 'tags' );
152 this.invertNamespacesButton.toggle( currentView === 'namespaces' );
153 this.backButton.toggle( currentView !== 'default' );
154 this.helpIcon.toggle( currentView === 'tags' );
155 this.view = currentView;
160 * Respond to model highlight change event
162 * @param {boolean} highlightEnabled Highlight is enabled
164 FilterMenuHeaderWidget.prototype.onModelHighlightChange = function ( highlightEnabled ) {
165 this.highlightButton.setActive( highlightEnabled );
169 * Update the state of the tags invert button
171 FilterMenuHeaderWidget.prototype.updateInvertTagsButton = function () {
172 this.invertTagsButton.setActive( this.invertTagsModel.isSelected() );
173 this.invertTagsButton.setLabel(
174 this.invertTagsModel.isSelected() ?
175 mw.msg( 'rcfilters-exclude-button-on' ) :
176 mw.msg( 'rcfilters-exclude-button-off' )
181 * Update the state of the namespaces invert button
183 FilterMenuHeaderWidget.prototype.updateInvertNamespacesButton = function () {
184 this.invertNamespacesButton.setActive( this.invertNamespacesModel.isSelected() );
185 this.invertNamespacesButton.setLabel(
186 this.invertNamespacesModel.isSelected() ?
187 mw.msg( 'rcfilters-exclude-button-on' ) :
188 mw.msg( 'rcfilters-exclude-button-off' )
192 FilterMenuHeaderWidget.prototype.onBackButtonClick = function () {
193 this.controller.switchView( 'default' );
197 * Respond to highlight button click
199 FilterMenuHeaderWidget.prototype.onHighlightButtonClick = function () {
200 this.controller.toggleHighlight();
204 * Respond to invert tags button click
206 FilterMenuHeaderWidget.prototype.onInvertTagsButtonClick = function () {
207 this.controller.toggleInvertedTags();
211 * Respond to invert namespaces button click
213 FilterMenuHeaderWidget.prototype.onInvertNamespacesButtonClick = function () {
214 this.controller.toggleInvertedNamespaces();
217 module.exports = FilterMenuHeaderWidget;