From 7e1b901a84c7bc27dc8d4da14144db507cdbeb66 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Sat, 18 Oct 2014 10:19:40 +0200 Subject: [PATCH] Changed post upload stop button to act immediately --- .../js/Presenters/PostUploadPresenter.js | 35 ++++++++----------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/public_html/js/Presenters/PostUploadPresenter.js b/public_html/js/Presenters/PostUploadPresenter.js index 634bd6b9..2983326a 100644 --- a/public_html/js/Presenters/PostUploadPresenter.js +++ b/public_html/js/Presenters/PostUploadPresenter.js @@ -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 {