jenkins-bot has submitted this change and it was merged.

Change subject: Use $.when() in MediaSearchWidget
......................................................................


Use $.when() in MediaSearchWidget

Use $.when() to check if there were results to the search. This
also makes sure that the 'results not found' message only appears
when it actually should.

Bug: 65321
Bug: 67438
Change-Id: I437ef639918ace1041bb8c9f7fdd04a4e83885eb
---
M modules/ve-mw/ui/widgets/ve.ui.MWMediaSearchWidget.js
1 file changed, 12 insertions(+), 20 deletions(-)

Approvals:
  Catrope: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/ve-mw/ui/widgets/ve.ui.MWMediaSearchWidget.js 
b/modules/ve-mw/ui/widgets/ve.ui.MWMediaSearchWidget.js
index c31f82f..6a1f9ba 100755
--- a/modules/ve-mw/ui/widgets/ve.ui.MWMediaSearchWidget.js
+++ b/modules/ve-mw/ui/widgets/ve.ui.MWMediaSearchWidget.js
@@ -36,6 +36,7 @@
        this.$noItemsMessage = this.$( '<div>' )
                .addClass( 've-ui-mwMediaSearchWidget-noresults' )
                .text( ve.msg( 'visualeditor-dialog-media-noresults' ) )
+               .hide()
                .appendTo( this.$query );
 
        // Events
@@ -100,7 +101,8 @@
  * @method
  */
 ve.ui.MWMediaSearchWidget.prototype.queryMediaSources = function () {
-       var i, len, source,
+       var i, len, source, request,
+               promises = [],
                ajaxOptions = {},
                value = this.query.getValue();
 
@@ -144,7 +146,7 @@
                                };
                        }
                        this.query.pushPending();
-                       source.request = 
ve.init.target.constructor.static.apiRequest( {
+                       request = ve.init.target.constructor.static.apiRequest( 
{
                                'action': 'query',
                                'generator': 'search',
                                'gsrsearch': value,
@@ -155,10 +157,13 @@
                                'iiprop': 'dimensions|url|mediatype',
                                'iiurlheight': this.size
                        }, ajaxOptions )
-                               .done( this.onMediaQueryDone.bind( this, source 
) )
-                               .always( this.onMediaQueryAlways.bind( this, 
source ) );
+                               .done( this.onMediaQueryDone.bind( this, source 
) );
                        source.value = value;
+                       promises.push( request );
                }
+
+               // When all sources are done, check to see if there are results
+               $.when.apply( $, promises ).done( 
this.onAllMediaQueriesDone.bind( this ) );
        }
 };
 
@@ -168,25 +173,12 @@
  * @method
  * @param {Object} source Media query source
  */
-ve.ui.MWMediaSearchWidget.prototype.onMediaQueryAlways = function ( source ) {
+ve.ui.MWMediaSearchWidget.prototype.onAllMediaQueriesDone = function ( source 
) {
        source.request = null;
        this.query.popPending();
 
-       // Count this source as done
-       this.sourceCounter++;
-
-       // Check if all sources are done
-       // TODO use $.when() instead (bug 65321)
-       if ( this.sourceCounter >= this.sources.length ) {
-               if ( this.results.getItems().length === 0 ) {
-                       this.$noItemsMessage.show();
-               }
-       }
-
-       // Even if the whole list of sources didn't finish yet
-       // if there are results, make the message go away
-       if ( this.results.getItems().length > 0 ) {
-               this.$noItemsMessage.hide();
+       if ( this.results.getItems().length === 0 ) {
+               this.$noItemsMessage.show();
        }
 };
 

-- 
To view, visit https://gerrit.wikimedia.org/r/150001
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I437ef639918ace1041bb8c9f7fdd04a4e83885eb
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Mooeypoo <mor...@gmail.com>
Gerrit-Reviewer: Catrope <roan.katt...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to