From: David Lynch Date: Wed, 11 Nov 2015 22:54:53 +0000 (-0800) Subject: TitleSearchWidget: Use OO.ui.mixin.RequestManager X-Git-Tag: 1.31.0-rc.0~8936^2 X-Git-Url: http://git.cyclocoop.org/%27.generer_url_ecrire%28%27admin_couteau_suisse%27%2C%27cmd=descrip&outil=boites_privees?a=commitdiff_plain;h=15f41fa72803d4ea6cde1fd4508df53338212f62;p=lhc%2Fweb%2Fwiklou.git TitleSearchWidget: Use OO.ui.mixin.RequestManager Get that request management goodness that only LookupWidgets used to benefit from. We can undo the earlier hacky fix to avoid requests overrunning each other as part of this. Bug: T114175 Change-Id: I6ff686b3b157d23ff534357ce25ebcb4ef7efea1 --- diff --git a/resources/src/mediawiki.widgets/mw.widgets.TitleSearchWidget.js b/resources/src/mediawiki.widgets/mw.widgets.TitleSearchWidget.js index 546fbf8f87..96f95491eb 100644 --- a/resources/src/mediawiki.widgets/mw.widgets.TitleSearchWidget.js +++ b/resources/src/mediawiki.widgets/mw.widgets.TitleSearchWidget.js @@ -11,6 +11,7 @@ * * @class * @extends OO.ui.SearchWidget + * @mixins OO.ui.mixin.RequestManager * @mixins mw.widgets.TitleWidget * * @constructor @@ -23,6 +24,7 @@ // Mixin constructors mw.widgets.TitleWidget.call( this, config ); + OO.ui.mixin.RequestManager.call( this, config ); this.query.setValidation( this.isQueryValid.bind( this ) ); @@ -46,6 +48,7 @@ /* Setup */ OO.inheritClass( mw.widgets.TitleSearchWidget, OO.ui.SearchWidget ); + OO.mixinClass( mw.widgets.TitleSearchWidget, OO.ui.mixin.RequestManager ); OO.mixinClass( mw.widgets.TitleSearchWidget, mw.widgets.TitleWidget ); /* Methods */ @@ -72,19 +75,30 @@ mw.widgets.TitleSearchWidget.prototype.onQueryChange = function () { var widget = this; - if ( this.currentRequest ) { - this.currentRequest.abort(); - } - - this.currentRequest = this.getSuggestionsPromise(); - this.currentRequest.done( function ( response ) { + this.getRequestData().done( function ( data ) { // Parent method mw.widgets.TitleSearchWidget.parent.prototype.onQueryChange.call( widget ); - - widget.results.addItems( widget.getOptionsFromData( response.query || {} ) ); - - widget.currentRequest = false; + widget.results.addItems( widget.getOptionsFromData( data ) ); } ); }; + /** + * @inheritdoc OO.ui.mixin.RequestManager + */ + mw.widgets.TitleSearchWidget.prototype.getRequestQuery = function () { + return this.getQueryValue(); + }; + /** + * @inheritdoc OO.ui.mixin.RequestManager + */ + mw.widgets.TitleSearchWidget.prototype.getRequest = function () { + return this.getSuggestionsPromise(); + }; + /** + * @inheritdoc OO.ui.mixin.RequestManager + */ + mw.widgets.TitleSearchWidget.prototype.getRequestCacheDataFromResponse = function ( response ) { + return response.query || {}; + }; + }( jQuery, mediaWiki ) );