X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=resources%2Fsrc%2Fmediawiki.rcfilters%2Fui%2Fmw.rcfilters.ui.FilterTagMultiselectWidget.js;h=268138fbda1f8895ec475815710a7a2a95c4df11;hb=f7e1770fb832aa77bf4e16ce8cc815f2b24dd10d;hp=e14c1fa9e5d1b3eca298078271201e2b4968d2c3;hpb=38c21f512f75233d68af616e5d2e3b494df6b2ee;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 e14c1fa9e5..268138fbda 100644 --- a/resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.FilterTagMultiselectWidget.js +++ b/resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.FilterTagMultiselectWidget.js @@ -98,9 +98,11 @@ this.resetButton.$element.on( 'mousedown', function ( e ) { e.stopPropagation(); } ); this.model.connect( this, { initialize: 'onModelInitialize', + update: 'onModelUpdate', itemUpdate: 'onModelItemUpdate', highlightChange: 'onModelHighlightChange' } ); + this.input.connect( this, { change: 'onInputChange' } ); this.queriesModel.connect( this, { itemUpdate: 'onSavedQueriesItemUpdate' } ); // The filter list and button should appear side by side regardless of how @@ -150,7 +152,6 @@ this.$element .addClass( 'mw-rcfilters-ui-filterTagMultiselectWidget' ); - this.populateFromModel(); this.reevaluateResetRestoreState(); }; @@ -160,6 +161,16 @@ /* Methods */ + /** + * Respond to input change event + * + * @param {string} value Value of the input + */ + mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.onInputChange = function ( value ) { + var view = this.model.getViewByTrigger( value.substr( 0, 1 ) ); + + this.controller.switchView( view ); + }; /** * Respond to query button click */ @@ -201,6 +212,14 @@ } else { // Clear selection this.selectTag( null ); + + // Clear input if the only thing in the input is the prefix + if ( + this.input.getValue() === this.model.getViewTrigger( this.model.getCurrentView() ) + ) { + // Clear the input + this.input.setValue( '' ); + } } }; @@ -240,11 +259,38 @@ * Respond to model initialize event */ mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.onModelInitialize = function () { - this.populateFromModel(); - this.setSavedQueryVisibility(); }; + /** + * Respond to model update event + */ + mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.onModelUpdate = function () { + this.updateElementsForView(); + }; + + /** + * Update the elements in the widget to the current view + */ + mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.updateElementsForView = function () { + var view = this.model.getCurrentView(), + inputValue = this.input.getValue(), + inputView = this.model.getViewByTrigger( inputValue.substr( 0, 1 ) ); + + if ( inputView !== 'default' ) { + // We have a prefix already, remove it + inputValue = inputValue.substr( 1 ); + } + + if ( inputView !== view ) { + // Add the correct prefix + inputValue = this.model.getViewTrigger( view ) + inputValue; + } + + // Update input + this.input.setValue( inputValue ); + }; + /** * Set the visibility of the saved query button */ @@ -262,6 +308,7 @@ ); } }; + /** * Respond to model itemUpdate event * @@ -292,7 +339,7 @@ */ mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.isAllowedData = function ( data ) { return ( - this.menu.getItemFromData( data ) && + this.model.getItemByName( data ) && !this.isDuplicateData( data ) ); }; @@ -337,12 +384,15 @@ */ mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.onTagSelect = function ( tagItem ) { var widget = this, - menuOption = this.menu.getItemFromData( tagItem.getData() ), + menuOption = this.menu.getItemFromModel( tagItem.getModel() ), oldInputValue = this.input.getValue(); // Reset input this.input.setValue( '' ); + // Switch view + this.controller.switchView( tagItem.getView() ); + // Parent method mw.rcfilters.ui.FilterTagMultiselectWidget.parent.prototype.onTagSelect.call( this, tagItem ); @@ -442,46 +492,6 @@ ); }; - /** - * Populate the menu from the model - */ - mw.rcfilters.ui.FilterTagMultiselectWidget.prototype.populateFromModel = function () { - var widget = this, - items = []; - - // Reset - this.getMenu().clearItems(); - - $.each( this.model.getFilterGroups(), function ( groupName, groupModel ) { - items.push( - // Group section - new mw.rcfilters.ui.FilterMenuSectionOptionWidget( - widget.controller, - groupModel, - { - $overlay: widget.$overlay - } - ) - ); - - // Add items - widget.model.getGroupFilters( groupName ).forEach( function ( filterItem ) { - items.push( - new mw.rcfilters.ui.FilterMenuOptionWidget( - widget.controller, - filterItem, - { - $overlay: widget.$overlay - } - ) - ); - } ); - } ); - - // Add all items to the menu - this.getMenu().addItems( items ); - }; - /** * @inheritdoc */