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