3 * List displaying all filter groups
5 * @extends OO.ui.Widget
6 * @mixins OO.ui.mixin.PendingElement
9 * @param {mw.rcfilters.Controller} controller Controller
10 * @param {mw.rcfilters.dm.FiltersViewModel} model View model
11 * @param {Object} [config] Configuration object
12 * @cfg {Object} [filters] A definition of the filter groups in this list
13 * @cfg {jQuery} [$overlay] A jQuery object serving as overlay for popups
15 mw
.rcfilters
.ui
.FilterWrapperWidget
= function MwRcfiltersUiFilterWrapperWidget( controller
, model
, config
) {
16 var $footer
= $( '<div>' );
17 config
= config
|| {};
20 mw
.rcfilters
.ui
.FilterWrapperWidget
.parent
.call( this, config
);
22 OO
.ui
.mixin
.PendingElement
.call( this, config
);
24 this.controller
= controller
;
26 this.$overlay
= config
.$overlay
|| this.$element
;
28 this.filterPopup
= new mw
.rcfilters
.ui
.FiltersListWidget(
32 label
: mw
.msg( 'rcfilters-filterlist-title' ),
33 $overlay
: this.$overlay
38 new OO
.ui
.ButtonWidget( {
41 flags
: [ 'progressive' ],
42 label
: mw
.msg( 'rcfilters-filterlist-feedbacklink' ),
43 href
: 'https://www.mediawiki.org/wiki/Help_talk:Edit_Review_Improvements/RC_filters'
47 this.textInput
= new OO
.ui
.TextInputWidget( {
48 classes
: [ 'mw-rcfilters-ui-filterWrapperWidget-search' ],
50 placeholder
: mw
.msg( 'rcfilters-search-placeholder' )
53 this.capsule
= new mw
.rcfilters
.ui
.FilterCapsuleMultiselectWidget( controller
, this.model
, this.textInput
, {
54 $overlay
: this.$overlay
,
56 $content
: this.filterPopup
.$element
,
58 classes
: [ 'mw-rcfilters-ui-filterWrapperWidget-popup' ],
64 this.model
.connect( this, {
65 initialize
: 'onModelInitialize',
66 itemUpdate
: 'onModelItemUpdate'
68 this.textInput
.connect( this, {
69 change
: 'onTextInputChange'
71 this.capsule
.connect( this, { capsuleItemClick
: 'onCapsuleItemClick' } );
72 this.capsule
.popup
.connect( this, { toggle
: 'onCapsulePopupToggle' } );
76 .addClass( 'mw-rcfilters-ui-filterWrapperWidget' )
77 .append( this.capsule
.$element
, this.textInput
.$element
);
82 OO
.inheritClass( mw
.rcfilters
.ui
.FilterWrapperWidget
, OO
.ui
.Widget
);
83 OO
.mixinClass( mw
.rcfilters
.ui
.FilterWrapperWidget
, OO
.ui
.mixin
.PendingElement
);
86 * Respond to capsule item click and make the popup scroll down to the requested item
88 * @param {mw.rcfilters.ui.CapsuleItemWidget} item Clicked item
90 mw
.rcfilters
.ui
.FilterWrapperWidget
.prototype.onCapsuleItemClick = function ( item
) {
91 var filterName
= item
.getData(),
92 // Find the item in the popup
93 filterWidget
= this.filterPopup
.getItemWidget( filterName
);
96 this.filterPopup
.select( filterName
);
97 this.capsule
.select( item
);
99 this.scrollToTop( filterWidget
.$element
);
103 * Respond to popup toggle event. Reset selection in the list when the popup is closed.
105 * @param {boolean} isVisible Popup is visible
107 mw
.rcfilters
.ui
.FilterWrapperWidget
.prototype.onCapsulePopupToggle = function ( isVisible
) {
109 this.filterPopup
.resetSelection();
110 this.capsule
.resetSelection();
112 this.scrollToTop( this.capsule
.$element
, 10 );
117 * Respond to text input change
119 * @param {string} newValue Current value
121 mw
.rcfilters
.ui
.FilterWrapperWidget
.prototype.onTextInputChange = function ( newValue
) {
122 this.filterPopup
.resetSelection();
124 // Filter the results
125 this.filterPopup
.filter( this.model
.findMatches( newValue
) );
126 this.capsule
.popup
.clip();
130 * Respond to model update event and set up the available filters to choose
133 mw
.rcfilters
.ui
.FilterWrapperWidget
.prototype.onModelInitialize = function () {
136 // Add defaults to capsule. We have to do this
137 // after we added to the capsule menu, since that's
138 // how the capsule multiselect widget knows which
140 this.model
.getItems().forEach( function ( filterItem
) {
141 if ( filterItem
.isSelected() ) {
142 wrapper
.capsule
.addItemByName( filterItem
.getName() );
148 * Respond to item update and reset the selection. This will make it so that
149 * any actual interaction with the system resets the selection state of any item.
151 mw
.rcfilters
.ui
.FilterWrapperWidget
.prototype.onModelItemUpdate = function () {
152 this.filterPopup
.resetSelection();
156 * Scroll the element to top within its container
159 * @param {jQuery} $element Element to position
160 * @param {number} [marginFromTop] When scrolling the entire widget to the top, leave this
161 * much space (in pixels) above the widget.
163 mw
.rcfilters
.ui
.FilterWrapperWidget
.prototype.scrollToTop = function ( $element
, marginFromTop
) {
164 var container
= OO
.ui
.Element
.static.getClosestScrollableContainer( $element
[ 0 ], 'y' ),
165 pos
= OO
.ui
.Element
.static.getRelativePosition( $element
, $( container
) );
168 $( container
).animate( {
169 scrollTop
: $( container
).scrollTop() + pos
.top
+ ( marginFromTop
|| 0 )