Mooeypoo has uploaded a new change for review.
https://gerrit.wikimedia.org/r/150001
Change subject: Use to $.when() in MediaSearchWidget
......................................................................
Use to $.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(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor
refs/changes/01/150001/1
diff --git a/modules/ve-mw/ui/widgets/ve.ui.MWMediaSearchWidget.js
b/modules/ve-mw/ui/widgets/ve.ui.MWMediaSearchWidget.js
index 7ba489a..c2e956c 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, url,
+ var i, len, source, url, request,
+ promises = [],
value = this.query.getValue();
if ( value === '' ) {
@@ -130,7 +132,7 @@
url = source.apiurl || ( source.scriptDirUrl +
'/api.php' );
}
this.query.pushPending();
- source.request =
ve.init.target.constructor.static.apiRequest( {
+ request = ve.init.target.constructor.static.apiRequest(
{
'action': 'query',
'generator': 'search',
'gsrsearch': value,
@@ -151,10 +153,13 @@
// but isn't working for some reason.
'dataType': 'jsonp'
} )
- .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 ) );
}
};
@@ -164,25 +169,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: newchange
Gerrit-Change-Id: I437ef639918ace1041bb8c9f7fdd04a4e83885eb
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Mooeypoo <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits