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) { ...@@ -4,6 +4,8 @@ define(function(require) {
4 var $ = require('jquery'); 4 var $ = require('jquery');
5 var Backbone = require('backbone'); 5 var Backbone = require('backbone');
6 var Flow = require('flow'); 6 var Flow = require('flow');
7 var api = require('api');
8 var OwnerContent = require('models/OwnerContent');
7 9
8 var Status = Backbone.Model.extend({ 10 var Status = Backbone.Model.extend({
9 defaults: function() { 11 defaults: function() {
...@@ -72,6 +74,45 @@ define(function(require) { ...@@ -72,6 +74,45 @@ define(function(require) {
72 Uploads: Uploads, 74 Uploads: Uploads,
73 Status: Status, 75 Status: Status,
74 flowEventHandlers: { 76 flowEventHandlers: {
77 uploadStart: function() {
78 var self = this;
79 // Pre-allocate the contentIds for each file's upload
80 if (!this.model.get('prechecked')) {
81 this.flow.pause();
82
83 var ownerContentDeferreds = [];
84 self.model.get('collection').each(function(file) {
85 if (file.flowFile != undefined) {
86 var flowFile = file.flowFile;
87 var flowTotalChunks = Math.floor(file.get('size') / flowFile.flowObj.opts.chunkSize);
88 if (flowTotalChunks == 0) {
89 flowTotalChunks = 1;
90 }
91 var ownerContent = new OwnerContent({
92 flowChunkNumber: 0,
93 flowChunkSize: flowFile.flowObj.opts.chunkSize,
94 flowCurrentChunkSize: (file.get('size') < flowFile.flowObj.opts.chunkSize) ? file.get('size') : flowFile.flowObj.opts.chunkSize,
95 flowTotalSize: file.get('size'),
96 flowIdentifier: flowFile.uniqueIdentifier,
97 flowFilename: flowFile.name,
98 flowRelativePath: flowFile.relativePath,
99 flowTotalChunks: flowTotalChunks
100 });
101 flowFile.flowObj.ownerContent = ownerContent;
102 var deferred = ownerContent.save();
103 ownerContentDeferreds.push(deferred);
104 }
105 });
106
107 $.when(ownerContentDeferreds).done(function(ownerContent) {
108 self.model.set('prechecked', true);
109 self.flow.resume();
110 setTimeout(function() {
111 self.model.set('prechecked', false);
112 }, 500);
113 });
114 }
115 },
75 fileAdded: function(flowFile) { 116 fileAdded: function(flowFile) {
76 var model = flowFile._model; 117 var model = flowFile._model;
77 if (!model) { 118 if (!model) {
...@@ -109,6 +150,12 @@ define(function(require) { ...@@ -109,6 +150,12 @@ define(function(require) {
109 result: 'success', 150 result: 'success',
110 resultData: message, 151 resultData: message,
111 }); 152 });
153
154 console.log('UPLOAD COMPLETE', flowFile.flowObj.ownerContent);
155 flowFile.flowObj.ownerContent.set('statusId', 'CTNT_AVAILABLE');
156 flowFile.flowObj.ownerContent.save(function() {
157 console.log('MARKED', flowFile.flowObj.ownerContent, ' AVAILABLE');
158 });
112 } 159 }
113 }, 160 },
114 fileError: function(flowFile, message, chunk) { 161 fileError: function(flowFile, message, chunk) {
...@@ -178,8 +225,8 @@ define(function(require) { ...@@ -178,8 +225,8 @@ define(function(require) {
178 'fileRemoved', 225 'fileRemoved',
179 'fileRetry', 226 'fileRetry',
180 'fileError', 227 'fileError',
181 //'uploadStart', 228 'uploadStart',
182 //'complete', 229 'complete',
183 //'progress', 230 //'progress',
184 //'error', 231 //'error',
185 ], function(eventName) { 232 ], function(eventName) {
......