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

Change subject: mediawiki.Upload.BookletLayout: Allow for asynchronous 
initialization
......................................................................


mediawiki.Upload.BookletLayout: Allow for asynchronous initialization

It happens to be convenient, since it turned out that we need to fire
a few API requests to correctly render some bits of the UI.

Follow-up to 86dedeea7f7cae5452acf5162672f34c32b593fd. This makes the
code less hacky and more reliable.

Change-Id: I65a92e3915a6844056fb7b3a2758a168eb12e6b8
---
M resources/src/mediawiki/mediawiki.ForeignStructuredUpload.BookletLayout.js
M resources/src/mediawiki/mediawiki.Upload.BookletLayout.js
M resources/src/mediawiki/mediawiki.Upload.Dialog.js
3 files changed, 18 insertions(+), 10 deletions(-)

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



diff --git 
a/resources/src/mediawiki/mediawiki.ForeignStructuredUpload.BookletLayout.js 
b/resources/src/mediawiki/mediawiki.ForeignStructuredUpload.BookletLayout.js
index 01917f8..717e2ec 100644
--- a/resources/src/mediawiki/mediawiki.ForeignStructuredUpload.BookletLayout.js
+++ b/resources/src/mediawiki/mediawiki.ForeignStructuredUpload.BookletLayout.js
@@ -39,15 +39,20 @@
         * @inheritdoc
         */
        mw.ForeignStructuredUpload.BookletLayout.prototype.initialize = 
function () {
-               
mw.ForeignStructuredUpload.BookletLayout.parent.prototype.initialize.call( this 
);
-               // Point the CategorySelector to the right wiki as soon as we 
know what the right wiki is
-               this.upload.apiPromise.done( function ( api ) {
-                       // If this is a ForeignApi, it will have a apiUrl, 
otherwise we don't need to do anything
-                       if ( api.apiUrl ) {
-                               // Can't reuse the same object, 
CategorySelector calls #abort on its mw.Api instance
-                               this.categoriesWidget.api = new mw.ForeignApi( 
api.apiUrl );
-                       }
-               }.bind( this ) );
+               var deferred = $.Deferred();
+               
mw.ForeignStructuredUpload.BookletLayout.parent.prototype.initialize.call( this 
)
+                       .done( function () {
+                               // Point the CategorySelector to the right wiki
+                               this.upload.apiPromise.done( function ( api ) {
+                                       // If this is a ForeignApi, it will 
have a apiUrl, otherwise we don't need to do anything
+                                       if ( api.apiUrl ) {
+                                               // Can't reuse the same object, 
CategorySelector calls #abort on its mw.Api instance
+                                               this.categoriesWidget.api = new 
mw.ForeignApi( api.apiUrl );
+                                       }
+                                       deferred.resolve();
+                               }.bind( this ) );
+                       }.bind( this ) );
+               return deferred.promise();
        };
 
        /**
diff --git a/resources/src/mediawiki/mediawiki.Upload.BookletLayout.js 
b/resources/src/mediawiki/mediawiki.Upload.BookletLayout.js
index dd199ce..c616829 100644
--- a/resources/src/mediawiki/mediawiki.Upload.BookletLayout.js
+++ b/resources/src/mediawiki/mediawiki.Upload.BookletLayout.js
@@ -147,11 +147,14 @@
 
        /**
         * Initialize for a new upload
+        *
+        * @return {jQuery.Promise} Promise resolved when everything is 
initialized
         */
        mw.Upload.BookletLayout.prototype.initialize = function () {
                this.clear();
                this.upload = this.createUpload();
                this.setPage( 'upload' );
+               return $.Deferred().resolve().promise();
        };
 
        /**
diff --git a/resources/src/mediawiki/mediawiki.Upload.Dialog.js 
b/resources/src/mediawiki/mediawiki.Upload.Dialog.js
index 220a3fe..53afca8 100644
--- a/resources/src/mediawiki/mediawiki.Upload.Dialog.js
+++ b/resources/src/mediawiki/mediawiki.Upload.Dialog.js
@@ -174,7 +174,7 @@
        mw.Upload.Dialog.prototype.getSetupProcess = function ( data ) {
                return mw.Upload.Dialog.parent.prototype.getSetupProcess.call( 
this, data )
                        .next( function () {
-                               this.uploadBooklet.initialize();
+                               return this.uploadBooklet.initialize();
                        }, this );
        };
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I65a92e3915a6844056fb7b3a2758a168eb12e6b8
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Bartosz DziewoƄski <[email protected]>
Gerrit-Reviewer: Edokter <[email protected]>
Gerrit-Reviewer: Esanders <[email protected]>
Gerrit-Reviewer: Jack Phoenix <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to