Merge "mw.ForeignStructuredUpload: Provide category suggestions from the right wiki"
[lhc/web/wiklou.git] / resources / src / mediawiki / mediawiki.ForeignStructuredUpload.BookletLayout.js
index 4ea5a56..86fb91b 100644 (file)
 
        /* Uploading */
 
+       /**
+        * @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 ) );
+       };
+
        /**
         * Returns a {@link mw.ForeignStructuredUpload mw.ForeignStructuredUpload}
         * with the {@link #cfg-target target} specified in config.
                        mustBeBefore: moment().add( 1, 'day' ).locale( 'en' ).format( 'YYYY-MM-DD' ) // Tomorrow
                } );
                this.categoriesWidget = new mw.widgets.CategorySelector( {
+                       // Can't be done here because we don't know the target wiki yet... done in #initialize.
+                       // api: new mw.ForeignApi( ... ),
                        $overlay: this.$overlay
                } );