/**
 * The Upload class which is used to represent a uploading file. It's a promise-
 * like object that also supports a simple event interface for providing progress
 * notifications. You normally don't create these yourself; they're the objects
 * returned by the Upload API:
 *
 *      var upload = Ext.space.Uploads.upload({
 *          url: "http://example.com/uploadHandler",
 *          fileFieldName: "exampleField",
 *          params: {field1: "foo"}, // optional extra form fields
 *          headers: {"x-example-app": "testing123"} // optional request headers
 *      });
 *
 *      // get the File object (and the completed Upload object)
 *      upload.then(function(file, finishedUpload) {
 *          // do something with the file
 *          Ext.space.Logger.log(file instanceof Ext.space.files.File); // true
 *          Ext.space.Logger.log(finishedUpload instanceof Ext.space.files.Upload); // true
 *      });
 *
 *      // get progress updates
 *      upload.on("progress", function(updatedUpload) {
 *          // inspect the latest data
 *      });
 *
 *      // cancel the upload
 *      upload.cancel().then(function() {
 *          // done
 *      });
 * 
 */
Ext.define("Ext.space.files.Upload", {
    extend: Ext.space.files.Transfer,
 
    /**
     * @private
     */
    manager: Ext.space.Uploads,
 
    /**
     * @private
     */
    idField: "uploadId",
 
    /**
     * Internal identifier for this upload
     * @type {String}
     */
    uploadId: null,
 
    /**
     * @private
     */
    bytesTransferredField: "bytesUploaded",
 
    /**
     * Progress so far
     * @type {Number}
     */
    bytesUploaded: 0,
 
    /**
     * Server response from the upload (.statusCode, .headers, .body)
     * @type {Object}
     */
    response: null,
 
    /**
     * @private
     */
    constructor: function(args) {
        Ext.space.files.Upload.superclass.constructor.apply(this, args);
    },
 
    /**
     * Bulk update this upload with the data provided.
     *
     * @private
     * @param {Object} source Object with data to overwrite onto this Upload
     */
    _updateWith: function(source) {
        if (source) {
            if (source.response) { this.response = source.response; }
        }
        return Ext.space.files.Upload.superclass._updateWith.apply(this, arguments);
    }
});