diff --git a/.gitignore b/.gitignore index 11982d1ef..a8c2d3a3a 100644 --- a/.gitignore +++ b/.gitignore @@ -39,6 +39,7 @@ bin/ src npm-debug.log +Vagrantfile test/dev/handlers/s3/composer.lock test/dev/handlers/traditional/files diff --git a/client/js/uploader.basic.api.js b/client/js/uploader.basic.api.js index 6468d77a4..cf507059e 100644 --- a/client/js/uploader.basic.api.js +++ b/client/js/uploader.basic.api.js @@ -397,6 +397,35 @@ return this._uploadData.uuidChanged(id, newUuid); }, + /** + * Expose the internal status of a file id to the public api for manual state changes + * @public + * + * @param {Number} id, + * @param {String} newStatus + * + * @todo Implement the remaining methods + */ + setStatus: function(id, newStatus) { + var fileRecord = this.getUploads({id: id}); + if (!fileRecord) { + throw new qq.Error(id + " is not a valid file ID."); + } + + switch (newStatus) { + case qq.status.DELETED: + this._onDeleteComplete(id, null, false); + break; + case qq.status.DELETE_FAILED: + this._onDeleteComplete(id, null, true); + break; + default: + var errorMessage = "Method setStatus called on '" + name + "' not implemented yet for " + newStatus; + this.log(errorMessage); + throw new qq.Error(errorMessage); + } + }, + uploadStoredFiles: function() { if (this._storedIds.length === 0) { this._itemError("noFilesError"); @@ -1067,6 +1096,35 @@ }); }, + _handleDeleteSuccess: function(id) { + if (this.getUploads({id: id}).status !== qq.status.DELETED) { + var name = this.getName(id); + + this._netUploadedOrQueued--; + this._netUploaded--; + this._handler.expunge(id); + this._uploadData.setStatus(id, qq.status.DELETED); + this.log("Delete request for '" + name + "' has succeeded."); + } + }, + + _handleDeleteFailed: function(id, xhrOrXdr) { + var name = this.getName(id); + + this._uploadData.setStatus(id, qq.status.DELETE_FAILED); + this.log("Delete request for '" + name + "' has failed.", "error"); + + // Check first if xhrOrXdr is actually passed or valid + // For error reporting, we only have access to the response status if this is not + // an `XDomainRequest`. + if (!xhrOrXdr || xhrOrXdr.withCredentials === undefined) { + this._options.callbacks.onError(id, name, "Delete request failed", xhrOrXdr); + } + else { + this._options.callbacks.onError(id, name, "Delete request failed with response code " + xhrOrXdr.status, xhrOrXdr); + } + }, + // Creates an extra button element _initExtraButton: function(spec) { var button = this._createUploadButton({ @@ -1420,24 +1478,10 @@ var name = this.getName(id); if (isError) { - this._uploadData.setStatus(id, qq.status.DELETE_FAILED); - this.log("Delete request for '" + name + "' has failed.", "error"); - - // For error reporting, we only have access to the response status if this is not - // an `XDomainRequest`. - if (xhrOrXdr.withCredentials === undefined) { - this._options.callbacks.onError(id, name, "Delete request failed", xhrOrXdr); - } - else { - this._options.callbacks.onError(id, name, "Delete request failed with response code " + xhrOrXdr.status, xhrOrXdr); - } + this._handleDeleteFailed(id, xhrOrXdr); } else { - this._netUploadedOrQueued--; - this._netUploaded--; - this._handler.expunge(id); - this._uploadData.setStatus(id, qq.status.DELETED); - this.log("Delete request for '" + name + "' has succeeded."); + this._handleDeleteSuccess(id); } }, diff --git a/docs/api/methods.jmd b/docs/api/methods.jmd index cd1d6f822..dedd9cdfa 100644 --- a/docs/api/methods.jmd +++ b/docs/api/methods.jmd @@ -25,7 +25,7 @@ $(document).ready(function() { # Methods Traditional {: .page-header } {% endmarkdown %} -