Merge "user: Allow "CAS update failed" exceptions to be normalised"
[lhc/web/wiklou.git] / resources / src / mediawiki.widgets / mw.widgets.TitleSearchWidget.js
index 546fbf8..b9bd1e0 100644 (file)
@@ -4,16 +4,18 @@
  * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
  * @license The MIT License (MIT); see LICENSE.txt
  */
-( function ( $, mw ) {
+( function () {
 
        /**
         * Creates an mw.widgets.TitleSearchWidget object.
         *
         * @class
         * @extends OO.ui.SearchWidget
+        * @mixins OO.ui.mixin.RequestManager
         * @mixins mw.widgets.TitleWidget
         *
         * @constructor
+        * @param {Object} [config] Configuration options
         */
        mw.widgets.TitleSearchWidget = function MwWidgetsTitleSearchWidget( config ) {
                config = config || {};
@@ -23,6 +25,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 +49,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 */
        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 ) );
                } );
        };
 
-}( jQuery, mediaWiki ) );
+       /**
+        * @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 || {};
+       };
+
+}() );