uploader-queue.js revision 998c7852929b955e119e1b7cc12d304693e42958
/**
* The class manages a queue of files that should be uploaded to the server.
* It initializes the required number of uploads, tracks them as they progress,
* and automatically advances to the next upload when a preceding one has completed.
* @module uploader-queue
*/
/**
* The class manages a queue of files to be uploaded to the server.
* @class UploaderQueue
* @extends Base
* @constructor
*/
var UploaderQueue = function(o) {
currentUploads = {};
currentFiles = {};
errorFiles = [];
lastUploadPointer = 0;
fileListLength = 0;
uploadsLeftCounter = 0;
totalBytesUploaded = 0;
totalBytes = 0;
};
initializer : function (cfg) {
},
_uploadErrorHandler : function (event) {
var updatedEvent = event;
this.pauseUpload();
}
else if (errorAction === UploaderQueue.RESTART_ASAP || errorAction === UploaderQueue.RESTART_AFTER) {
}
},
_uploadCompleteHandler : function (event) {
uploadsLeftCounter -= 1;
lastUploadPointer += 1;
}
else if (this._currentState === UploaderQueue.UPLOADING && errorAction === UploaderQueue.RESTART_ASAP && errorFiles.length > 0) {
}
var updatedEvent = event;
if (uploadsLeftCounter == 0) {
this.fire("alluploadscomplete");
}
},
_uploadProgressHandler : function (event) {
var updatedEvent = event;
var uploadedTotal = totalBytesUploaded;
uploadedTotal += value;
});
},
startUpload: function() {
currentUploads = {};
currentFiles = {};
errorFiles = [];
lastUploadPointer = 0;
totalBytesUploaded = 0;
}
},
pauseUpload: function () {
},
restartUpload: function () {
if (lastUploadPointer < fileListLength) {
lastUploadPointer += 1;
}
},
cancelUpload: function () {
for (fid in currentFiles) {
}
currentUploads = {};
currentFiles = {};
errorFiles = [];
lastUploadPointer = 0;
totalBytesUploaded = 0;
}
}, {
CONTINUE: "continue",
STOP: "stop",
RESTART_ASAP: "restartasap",
RESTART_AFTER: "restartafter",
STOPPED: "stopped",
UPLOADING: "uploading",
NAME: 'uploaderqueue',
ATTRS: {
/**
* @property simUploads
* @type Number
* @description Maximum number of simultaneous uploads
*/
simUploads: {
value: 2,
}
},
errorAction: {
value: "continue",
return (val === UploaderQueue.CONTINUE || val === UploaderQueue.STOP || val === UploaderQueue.RESTART_ASAP || val === UploaderQueue.RESTART_AFTER);
}
},
readOnly: true,
value: 0
},
bytesTotal: {
readOnly: true,
value: 0
},
fileList: {
value: [],
lazyAdd: false,
});
return val;
}
},
value: "Filedata"
},
uploadURL: {
value: ""
},
value: {}
}
}
});
Y.namespace('Uploader');