Changed post upload stop button to act immediately

This commit is contained in:
Marcin Kurczewski 2014-10-18 10:19:40 +02:00
parent c452152f74
commit 7e1b901a84

View file

@ -22,7 +22,7 @@ App.Presenters.PostUploadPresenter = function(
var tagInput; var tagInput;
var fileDropper; var fileDropper;
var interactionEnabled = true; var interactionEnabled = true;
var stopNextUpload = false; var currentUploadId = null;
function init(params, loaded) { function init(params, loaded) {
topNavigationPresenter.select('upload'); topNavigationPresenter.select('upload');
@ -235,9 +235,7 @@ App.Presenters.PostUploadPresenter = function(
function stopButtonClicked(e) { function stopButtonClicked(e) {
e.preventDefault(); e.preventDefault();
if (!uploadStopped()) { stopUpload();
stopUpload();
}
} }
function addPostFromFile(file) { function addPostFromFile(file) {
@ -528,25 +526,19 @@ App.Presenters.PostUploadPresenter = function(
$el.find('.upload').hide(); $el.find('.upload').hide();
$el.find('.stop').show(); $el.find('.stop').show();
interactionEnabled = false; interactionEnabled = false;
currentUploadId = Math.random();
uploadNextPost(); uploadNextPost();
} }
function uploadStopped() {
return stopNextUpload;
}
function stopUpload() { function stopUpload() {
stopNextUpload = true; currentUploadId = null;
showUploadError('Upload stopped.');
} }
function uploadNextPost() { function uploadNextPost() {
var priorUploadId = currentUploadId;
messagePresenter.hideMessages($messages); messagePresenter.hideMessages($messages);
if (uploadStopped()) {
showUploadError('Upload stopped.');
return;
}
var posts = getAllPosts(); var posts = getAllPosts();
if (posts.length === 0) { if (posts.length === 0) {
onUploadCompleted(); onUploadCompleted();
@ -577,13 +569,17 @@ App.Presenters.PostUploadPresenter = function(
promise.wait(api.post('/posts', formData)) promise.wait(api.post('/posts', formData))
.then(function(response) { .then(function(response) {
$row.slideUp(function(response) { $row.slideUp(function(response) {
$row.remove(); if (priorUploadId === currentUploadId) {
posts.shift(); $row.remove();
setAllPosts(posts); posts.shift();
uploadNextPost(); setAllPosts(posts);
uploadNextPost();
}
}); });
}).fail(function(response) { }).fail(function(response) {
showUploadError(response.json && response.json.error || response); if (priorUploadId === currentUploadId) {
showUploadError(response.json && response.json.error || response);
}
}); });
} }
@ -598,7 +594,6 @@ App.Presenters.PostUploadPresenter = function(
messagePresenter.hideMessages($messages); messagePresenter.hideMessages($messages);
messagePresenter.showError($messages, message); messagePresenter.showError($messages, message);
interactionEnabled = true; interactionEnabled = true;
stopNextUpload = false;
} }
return { return {