* {@link #createUpload createUpload} method to
* return the new model. The {@link #saveFile saveFile}, and
* the {@link #uploadFile uploadFile} methods need to be
- * overriden to use the new model and data returned from the forms.
+ * overridden to use the new model and data returned from the forms.
*
* @class
* @extends OO.ui.BookletLayout
* The file has been saved to the database
*
* @event fileSaved
+ * @param {Object} imageInfo See mw.Upload#getImageInfo
*/
/**
/**
* Initialize for a new upload
+ *
+ * @return {jQuery.Promise} Promise resolved when everything is initialized
*/
mw.Upload.BookletLayout.prototype.initialize = function () {
+ var
+ apiPromise,
+ booklet = this,
+ deferred = $.Deferred();
+
this.clear();
this.upload = this.createUpload();
this.setPage( 'upload' );
+
+ apiPromise = this.upload.apiPromise || $.Deferred().resolve( this.upload.api );
+ apiPromise.done( function ( api ) {
+ // If the user can't upload anything, don't give them the option to.
+ api.getUserInfo().done( function ( userInfo ) {
+ if ( userInfo.rights.indexOf( 'upload' ) === -1 ) {
+ // TODO Use a better error message when not all logged-in users can upload
+ booklet.getPage( 'upload' ).$element.msg( 'api-error-mustbeloggedin' );
+ }
+ } ).always( function () {
+ deferred.resolve();
+ } );
+ } );
+
+ return deferred.promise();
};
/**
this.filenameWidget.setValue( file.name );
this.setPage( 'info' );
+ if ( this.shouldRecordBucket ) {
+ this.upload.bucket = this.bucket;
+ }
+
this.upload.setFile( file );
// Explicitly set the filename so that the old filename isn't used in case of retry
this.upload.setFilenameFromFile();
*
* @protected
* @fires fileSaved
- * @returns {jQuery.Promise} Rejects the promise with an
+ * @return {jQuery.Promise} Rejects the promise with an
* {@link OO.ui.Error error}, or resolves if the upload was successful.
*/
mw.Upload.BookletLayout.prototype.saveFile = function () {
layout.setPage( 'insert' );
deferred.resolve();
- layout.emit( 'fileSaved' );
+ layout.emit( 'fileSaved', layout.upload.getImageInfo() );
}, function () {
var errorMessage = layout.getErrorMessageForStateDetails();
deferred.reject( errorMessage );
* state and state details.
*
* @protected
- * @returns {OO.ui.Error} Error to display for given state and details.
+ * @return {OO.ui.Error} Error to display for given state and details.
*/
mw.Upload.BookletLayout.prototype.getErrorMessageForStateDetails = function () {
var message,
// won't help the fact that the file already exists.
if ( warnings.stashfailed !== undefined ) {
return new OO.ui.Error(
- $( '<p>' ).html(
- mw.message( 'api-error-stashfailed' ).parse()
- ),
+ $( '<p>' ).msg( 'api-error-stashfailed' ),
{ recoverable: false }
);
} else if ( warnings.exists !== undefined ) {
return new OO.ui.Error(
- $( '<p>' ).html(
- mw.message( 'fileexists', 'File:' + warnings.exists ).parse()
- ),
+ $( '<p>' ).msg( 'fileexists', 'File:' + warnings.exists ),
{ recoverable: false }
);
} else if ( warnings[ 'page-exists' ] !== undefined ) {
return new OO.ui.Error(
- $( '<p>' ).html(
- mw.message( 'filepageexists', 'File:' + warnings[ 'page-exists' ] ).parse()
- ),
+ $( '<p>' ).msg( 'filepageexists', 'File:' + warnings[ 'page-exists' ] ),
{ recoverable: false }
);
} else if ( warnings.duplicate !== undefined ) {
return new OO.ui.Error(
- $( '<p>' ).html(
- mw.message( 'api-error-duplicate', warnings.duplicate.length ).parse()
- ),
+ $( '<p>' ).msg( 'api-error-duplicate', warnings.duplicate.length ),
{ recoverable: false }
);
} else if ( warnings[ 'thumb-name' ] !== undefined ) {
return new OO.ui.Error(
- $( '<p>' ).html(
- mw.message( 'filename-thumb-name' ).parse()
- ),
+ $( '<p>' ).msg( 'filename-thumb-name' ),
{ recoverable: false }
);
} else if ( warnings[ 'bad-prefix' ] !== undefined ) {
return new OO.ui.Error(
- $( '<p>' ).html(
- mw.message( 'filename-bad-prefix', warnings[ 'bad-prefix' ] ).parse()
- ),
+ $( '<p>' ).msg( 'filename-bad-prefix', warnings[ 'bad-prefix' ] ),
{ recoverable: false }
);
} else if ( warnings[ 'duplicate-archive' ] !== undefined ) {
return new OO.ui.Error(
- $( '<p>' ).html(
- mw.message( 'api-error-duplicate-archive', 1 ).parse()
- ),
+ $( '<p>' ).msg( 'api-error-duplicate-archive', 1 ),
{ recoverable: false }
);
} else if ( warnings.badfilename !== undefined ) {
// TODO This might not really be the best place to do this
this.filenameWidget.setValue( warnings.badfilename );
return new OO.ui.Error(
- $( '<p>' ).html(
- mw.message( 'badfilename', warnings.badfilename ).parse()
- )
+ $( '<p>' ).msg( 'badfilename', warnings.badfilename )
);
} else {
return new OO.ui.Error(
*
* @protected
* @fires selectFile
- * @returns {OO.ui.FormLayout}
+ * @return {OO.ui.FormLayout}
*/
mw.Upload.BookletLayout.prototype.renderUploadForm = function () {
var fieldset;
* property.
*
* @protected
- * @returns {OO.ui.FormLayout}
+ * @return {OO.ui.FormLayout}
*/
mw.Upload.BookletLayout.prototype.renderInfoForm = function () {
var fieldset;
* sets the {@link #insertForm insertForm} property.
*
* @protected
- * @returns {OO.ui.FormLayout}
+ * @return {OO.ui.FormLayout}
*/
mw.Upload.BookletLayout.prototype.renderInsertForm = function () {
var fieldset;
* {@link #uploadForm upload form}.
*
* @protected
- * @returns {File|null}
+ * @return {File|null}
*/
mw.Upload.BookletLayout.prototype.getFile = function () {
return this.selectFileWidget.getValue();
* {@link #infoForm information form}.
*
* @protected
- * @returns {string}
+ * @return {string}
*/
mw.Upload.BookletLayout.prototype.getFilename = function () {
return this.filenameWidget.getValue();
* {@link #infoForm information form}.
*
* @protected
- * @returns {string}
+ * @return {string}
*/
mw.Upload.BookletLayout.prototype.getText = function () {
return this.descriptionWidget.getValue();