2fd9a9ca by Adam Heath

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

2 parents 06f78870 4ae84755
......@@ -4,6 +4,8 @@ define(function(require) {
var $ = require('jquery');
var Backbone = require('backbone');
var Flow = require('flow');
var api = require('api');
var OwnerContent = require('models/OwnerContent');
var Status = Backbone.Model.extend({
defaults: function() {
......@@ -72,6 +74,45 @@ define(function(require) {
Uploads: Uploads,
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);
});
}
},
fileAdded: function(flowFile) {
var model = flowFile._model;
if (!model) {
......@@ -109,6 +150,12 @@ define(function(require) {
result: 'success',
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');
});
}
},
fileError: function(flowFile, message, chunk) {
......@@ -178,8 +225,8 @@ define(function(require) {
'fileRemoved',
'fileRetry',
'fileError',
//'uploadStart',
//'complete',
'uploadStart',
'complete',
//'progress',
//'error',
], function(eventName) {
......