From 9daa00bc10f8199145cf5952382512f4db95aa4a Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Tue, 17 Jan 2023 11:15:36 +0300 Subject: upload: Enable cancelling an upload. --- qc_app/static/js/upload_progress.js | 10 ++++++++++ qc_app/templates/index.html | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/qc_app/static/js/upload_progress.js b/qc_app/static/js/upload_progress.js index 049dbfe..98a503a 100644 --- a/qc_app/static/js/upload_progress.js +++ b/qc_app/static/js/upload_progress.js @@ -35,6 +35,15 @@ function make_progress_updater(file, indicator_elt) { }; } +function setup_cancel_upload(request, indicator_elt) { + document.getElementById("btn-cancel-upload").addEventListener( + "click", function(event) { + event.preventDefault(); + request.abort(); + indicator_elt.setAttribute("class", "hidden"); + }); +} + function setup_request(file, progress_indicator_elt) { var request = new XMLHttpRequest(); var updater = make_progress_updater(file, progress_indicator_elt); @@ -42,6 +51,7 @@ function setup_request(file, progress_indicator_elt) { request.onload = function(event) { document.location.assign(request.responseURL); }; + setup_cancel_upload(request, progress_indicator_elt) return request; } diff --git a/qc_app/templates/index.html b/qc_app/templates/index.html index 9ee3af6..2db6048 100644 --- a/qc_app/templates/index.html +++ b/qc_app/templates/index.html @@ -75,6 +75,11 @@

Uploading 0%

Processing

+
+ +
{%endblock%} -- cgit v1.2.3