a43dbc30 by Adam Heath

Merge branch 'BF-7621' of /home/git/repositories/brainfood/frontend-uploads

2 parents 2fd9a9ca ccd3127c
......@@ -5,12 +5,11 @@ define(function(require) {
var Backbone = require('backbone');
var Flow = require('flow');
var api = require('api');
var OwnerContent = require('models/OwnerContent');
var Status = Backbone.Model.extend({
defaults: function() {
return {
result: null,
result: 'pending',
resultData: null,
sent: null,
completion: null,
......@@ -75,42 +74,8 @@ define(function(require) {
Status: Status,
flowEventHandlers: {
uploadStart: function() {
var self = this;
// Pre-allocate the contentIds for each file's upload
if (!this.model.get('prechecked')) {
this.flow.pause();
var ownerContentDeferreds = [];
self.model.get('collection').each(function(file) {
if (file.flowFile != undefined) {
var flowFile = file.flowFile;
var flowTotalChunks = Math.floor(file.get('size') / flowFile.flowObj.opts.chunkSize);
if (flowTotalChunks == 0) {
flowTotalChunks = 1;
}
var ownerContent = new OwnerContent({
flowChunkNumber: 0,
flowChunkSize: flowFile.flowObj.opts.chunkSize,
flowCurrentChunkSize: (file.get('size') < flowFile.flowObj.opts.chunkSize) ? file.get('size') : flowFile.flowObj.opts.chunkSize,
flowTotalSize: file.get('size'),
flowIdentifier: flowFile.uniqueIdentifier,
flowFilename: flowFile.name,
flowRelativePath: flowFile.relativePath,
flowTotalChunks: flowTotalChunks
});
flowFile.flowObj.ownerContent = ownerContent;
var deferred = ownerContent.save();
ownerContentDeferreds.push(deferred);
}
});
$.when(ownerContentDeferreds).done(function(ownerContent) {
self.model.set('prechecked', true);
self.flow.resume();
setTimeout(function() {
self.model.set('prechecked', false);
}, 500);
});
if (this.model.get('handlers') && this.model.get('handlers').uploadStart !== undefined) {
this.model.get('handlers').uploadStart();
}
},
fileAdded: function(flowFile) {
......@@ -124,13 +89,17 @@ define(function(require) {
model.flowFile = flowFile;
this.model.get('collection').add(model);
}
if (this.model.get('handlers') && this.model.get('handlers').fileAdded !== undefined) {
this.model.get('handlers').fileAdded(flowFile);
}
return true;
},
filesAdded: function() {
return true;
},
filesSubmitted: function() {
this.flow.upload();
// this.flow.upload();
},
fileProgress: function(flowFile) {
var model = flowFile._model;
......@@ -151,11 +120,9 @@ define(function(require) {
resultData: message,
});
console.log('UPLOAD COMPLETE', flowFile.flowObj.ownerContent);
flowFile.flowObj.ownerContent.set('statusId', 'CTNT_AVAILABLE');
flowFile.flowObj.ownerContent.save(function() {
console.log('MARKED', flowFile.flowObj.ownerContent, ' AVAILABLE');
});
if (this.model.get('handlers') && this.model.get('handlers').fileSuccess !== undefined) {
this.model.get('handlers').fileSuccess(flowFile);
}
}
},
fileError: function(flowFile, message, chunk) {
......