X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=resources%2Fsrc%2Fmediawiki.rcfilters%2Fui%2Fmw.rcfilters.ui.FilterTagMultiselectWidget.js;h=953df5b802b25d12ac3d3161ae7c307d011f7892;hb=8a4883126919485de0e4910859d6d58a96039c94;hp=4e33be0252977da1f2876d5d6f29bf779919bb78;hpb=4bd87fba840a3fa2ba8c6dbcfa7f005f6708c0fa;p=lhc%2Fweb%2Fwiklou.git diff --git a/resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.FilterTagMultiselectWidget.js b/resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.FilterTagMultiselectWidget.js index 4e33be0252..953df5b802 100644 --- a/resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.FilterTagMultiselectWidget.js +++ b/resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.FilterTagMultiselectWidget.js @@ -41,6 +41,8 @@ allowReordering: false, $overlay: this.$overlay, menu: { + // Our filtering is done through the model + filterFromInput: false, hideWhenOutOfView: false, hideOnChoose: false, width: 650, @@ -88,7 +90,10 @@ if ( !mw.user.isAnon() ) { this.saveQueryButton = new mw.rcfilters.ui.SaveFiltersPopupButtonWidget( this.controller, - this.queriesModel + this.queriesModel, + { + $overlay: this.$overlay + } ); this.saveQueryButton.$element.on( 'mousedown', function ( e ) { e.stopPropagation(); } ); @@ -118,6 +123,7 @@ this.model.connect( this, { initialize: 'onModelInitialize', update: 'onModelUpdate', + searchChange: 'onModelSearchChange', itemUpdate: 'onModelItemUpdate', highlightChange: 'onModelHighlightChange' } ); @@ -234,20 +240,24 @@ this.focus(); }; + /** + * Respond to model search change event + * + * @param {string} value Search value + */ + mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.onModelSearchChange = function ( value ) { + this.input.setValue( value ); + }; + /** * Respond to input change event * * @param {string} value Value of the input */ mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.onInputChange = function ( value ) { - var view; - - value = value.trim(); - - view = this.model.getViewByTrigger( value.substr( 0, 1 ) ); - - this.controller.switchView( view ); + this.controller.setSearch( value ); }; + /** * Respond to query button click */ @@ -289,7 +299,7 @@ mw.hook( 'RcFilters.popup.open' ).fire(); - if ( !this.getMenu().getSelectedItem() ) { + if ( !this.getMenu().findSelectedItem() ) { // If there are no selected items, scroll menu to top // This has to be in a setTimeout so the menu has time // to be positioned and fixed @@ -301,13 +311,8 @@ // Clear selection this.selectTag( null ); - // Clear input if the only thing in the input is the prefix - if ( - this.input.getValue().trim() === this.model.getViewTrigger( this.model.getCurrentView() ) - ) { - // Clear the input - this.input.setValue( '' ); - } + // Clear the search + this.controller.setSearch( '' ); // Log filter grouping this.controller.trackFilterGroupings( 'filtermenu' ); @@ -471,7 +476,7 @@ this.controller.toggleFilterSelect( item.model.getName() ); // Select the tag if it exists, or reset selection otherwise - this.selectTag( this.getItemFromData( item.model.getName() ) ); + this.selectTag( this.findItemFromData( item.model.getName() ) ); this.focus(); }; @@ -505,42 +510,19 @@ * @inheritdoc */ mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.onTagSelect = function ( tagItem ) { - var widget = this, - menuOption = this.menu.getItemFromModel( tagItem.getModel() ), - oldInputValue = this.input.getValue().trim(); + var menuOption = this.menu.getItemFromModel( tagItem.getModel() ); this.menu.setUserSelecting( true ); - - // Reset input - this.input.setValue( '' ); - - // Switch view - this.controller.switchView( tagItem.getView() ); - // Parent method mw.rcfilters.ui.FilterTagMultiselectWidget.parent.prototype.onTagSelect.call( this, tagItem ); - this.menu.selectItem( menuOption ); - this.selectTag( tagItem ); + // Switch view + this.controller.resetSearchForView( tagItem.getView() ); - // Scroll to the item - if ( this.model.removeViewTriggers( oldInputValue ) ) { - // We're binding a 'once' to the itemVisibilityChange event - // so this happens when the menu is ready after the items - // are visible again, in case this is done right after the - // user filtered the results - this.getMenu().once( - 'itemVisibilityChange', - function () { - widget.scrollToTop( menuOption.$element ); - widget.menu.setUserSelecting( false ); - } - ); - } else { - this.scrollToTop( menuOption.$element ); - this.menu.setUserSelecting( false ); - } + this.selectTag( tagItem ); + this.scrollToTop( menuOption.$element ); + this.menu.setUserSelecting( false ); }; /** @@ -576,7 +558,7 @@ * Respond to click event on the reset button */ mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.onResetButtonClick = function () { - if ( this.model.areCurrentFiltersEmpty() ) { + if ( this.model.areVisibleFiltersEmpty() ) { // Reset to default filters this.controller.resetToDefaults(); } else { @@ -590,7 +572,7 @@ */ mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.reevaluateResetRestoreState = function () { var defaultsAreEmpty = this.controller.areDefaultsEmpty(), - currFiltersAreEmpty = this.model.areCurrentFiltersEmpty(), + currFiltersAreEmpty = this.model.areVisibleFiltersEmpty(), hideResetButton = currFiltersAreEmpty && defaultsAreEmpty; this.resetButton.setIcon( @@ -615,9 +597,7 @@ return new mw.rcfilters.ui.MenuSelectWidget( this.controller, this.model, - $.extend( { - filterFromInput: true - }, menuConfig ) + menuConfig ); };