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) { ...@@ -5,12 +5,11 @@ define(function(require) {
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'); 7 var api = require('api');
8 var OwnerContent = require('models/OwnerContent');
9 8
10 var Status = Backbone.Model.extend({ 9 var Status = Backbone.Model.extend({
11 defaults: function() { 10 defaults: function() {
12 return { 11 return {
13 result: null, 12 result: 'pending',
14 resultData: null, 13 resultData: null,
15 sent: null, 14 sent: null,
16 completion: null, 15 completion: null,
...@@ -75,42 +74,8 @@ define(function(require) { ...@@ -75,42 +74,8 @@ define(function(require) {
75 Status: Status, 74 Status: Status,
76 flowEventHandlers: { 75 flowEventHandlers: {
77 uploadStart: function() { 76 uploadStart: function() {
78 var self = this; 77 if (this.model.get('handlers') && this.model.get('handlers').uploadStart !== undefined) {
79 // Pre-allocate the contentIds for each file's upload 78 this.model.get('handlers').uploadStart();
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 } 79 }
115 }, 80 },
116 fileAdded: function(flowFile) { 81 fileAdded: function(flowFile) {
...@@ -124,13 +89,17 @@ define(function(require) { ...@@ -124,13 +89,17 @@ define(function(require) {
124 model.flowFile = flowFile; 89 model.flowFile = flowFile;
125 this.model.get('collection').add(model); 90 this.model.get('collection').add(model);
126 } 91 }
92
93 if (this.model.get('handlers') && this.model.get('handlers').fileAdded !== undefined) {
94 this.model.get('handlers').fileAdded(flowFile);
95 }
127 return true; 96 return true;
128 }, 97 },
129 filesAdded: function() { 98 filesAdded: function() {
130 return true; 99 return true;
131 }, 100 },
132 filesSubmitted: function() { 101 filesSubmitted: function() {
133 this.flow.upload(); 102 // this.flow.upload();
134 }, 103 },
135 fileProgress: function(flowFile) { 104 fileProgress: function(flowFile) {
136 var model = flowFile._model; 105 var model = flowFile._model;
...@@ -151,11 +120,9 @@ define(function(require) { ...@@ -151,11 +120,9 @@ define(function(require) {
151 resultData: message, 120 resultData: message,
152 }); 121 });
153 122
154 console.log('UPLOAD COMPLETE', flowFile.flowObj.ownerContent); 123 if (this.model.get('handlers') && this.model.get('handlers').fileSuccess !== undefined) {
155 flowFile.flowObj.ownerContent.set('statusId', 'CTNT_AVAILABLE'); 124 this.model.get('handlers').fileSuccess(flowFile);
156 flowFile.flowObj.ownerContent.save(function() { 125 }
157 console.log('MARKED', flowFile.flowObj.ownerContent, ' AVAILABLE');
158 });
159 } 126 }
160 }, 127 },
161 fileError: function(flowFile, message, chunk) { 128 fileError: function(flowFile, message, chunk) {
......