Info:
diff --git a/js/forms.js b/js/forms.js
index b2ec701..41601db 100644
--- a/js/forms.js
+++ b/js/forms.js
@@ -563,22 +563,6 @@ var tmForms = {
tmData.addTrack(track, localStorage.getItem('rikitraki-token'), function(data) {
var files = $('#track-photo-files')[0].files;
var images = $('#track-photos-container img');
- // This function is a task to upload a single image
- function uploadPicture(i, blob) {
- return tmData.uploadTrackPic(blob, data.trackId, i, localStorage.getItem('rikitraki-token'));
- }
- // This function makes a canvas.toBlob task for converting a resized image to jpeg for uploading
- function resizeToBlob (i) {
- var d = $.Deferred();
- self.resizeImage(images[i], IMAGE_RESIZE_WIDTH).toBlob(function (blob) {
- uploadPictureTasks.push(uploadPicture(i, blob));
- d.resolve();
- },
- 'image/jpeg', IMAGE_RESIZE_QUALITY);
- return d.promise();
- }
- // Set up upload image tasks
- // var uploadResizedPictureTasks = [];
var resizeToBlobTasks = [];
var uploadPictureTasks = [];
for (var j=0; j
MAX_IMAGE_SIZE) {
- resizeToBlobTasks.push(resizeToBlob(j));
+ resizeToBlobTasks.push(self.resizeToBlob(data.trackId, images[j], j, uploadPictureTasks));
} else {
- uploadPictureTasks.push(uploadPicture(j, files[i]));
+ uploadPictureTasks.push(self.uploadPicture(data.trackId, j, files[i]));
}
}
- // This is a mess because we have to do a bunch of async tasks of two kinds in a loop
- if (resizeToBlobTasks.length > 0) {
- $.when.apply(this, resizeToBlobTasks).then(function () {
- $.when.apply(this, uploadPictureTasks).then(function () {
- $('#uploadingMessage').hide();
- $('#uploadMessage').fadeIn('slow');
- setTimeout(function () {
- window.location.href='?track=' + data.trackId;
- }, 2000);
- }, function (jqxhr) {
- console.log(jqxhr);
- });
- });
- } else {
+ $.when.apply(this, resizeToBlobTasks).then(function () {
$.when.apply(this, uploadPictureTasks).then(function () {
$('#uploadingMessage').hide();
$('#uploadMessage').fadeIn('slow');
@@ -615,7 +586,8 @@ var tmForms = {
}, function (jqxhr) {
console.log(jqxhr);
});
- }
+ });
+
}, function(jqxhr) { // jqxhr, textStatus
// Add internal error message here
console.log(jqxhr);
@@ -680,6 +652,20 @@ var tmForms = {
});
return d.promise();
},
+ uploadPicture: function (trackId, picIndex, blob) {
+ return tmData.uploadTrackPic(blob, trackId, picIndex, localStorage.getItem('rikitraki-token'));
+ },
+ resizeToBlob: function (trackId, img, picIndex, uploadPictureTasks) {
+ // This function makes a canvas.toBlob task for converting a resized image to jpeg for uploading
+ self = this;
+ var d = $.Deferred();
+ self.resizeImage(img, IMAGE_RESIZE_WIDTH).toBlob(function (blob) {
+ uploadPictureTasks.push(self.uploadPicture(trackId, picIndex, blob));
+ d.resolve();
+ },
+ 'image/jpeg', IMAGE_RESIZE_QUALITY);
+ return d.promise();
+ },
resizeImage: function (img, width) {
var height;
if ((width <= 0) || (img.naturalWidth <= width)) {
@@ -727,13 +713,15 @@ var tmForms = {
}
$('#edit-track-photos-container').empty();
- for (var i=0; i' +
- '