Skip to content

Commit

Permalink
webworkflow warn before leaving page during upload. Allow upload to s…
Browse files Browse the repository at this point in the history
…ucceed if user clicks into a directory.
  • Loading branch information
FoamyGuy committed Sep 14, 2024
1 parent 64cb762 commit a0d470a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion supervisor/shared/web_workflow/static/directory.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,17 @@ async function mkdir(e) {
}
}

const beforeUnloadHandler = function(event){
// Recommended
event.preventDefault();

// Included for legacy support, e.g. Chrome/Edge < 119
event.returnValue = true;
}

async function upload(e) {
const upload_path = current_path;
window.addEventListener("beforeunload", beforeUnloadHandler);
set_upload_enabled(false);
let progress = document.querySelector("#progress");
let made_dirs = new Set();
Expand All @@ -213,7 +223,7 @@ async function upload(e) {
made_dirs.add(parent_dir);
}
}
let file_path = new URL("/fs" + current_path + file_name, url_base);
let file_path = new URL("/fs" + upload_path + file_name, url_base);
const response = await fetch(file_path,
{
method: "PUT",
Expand Down Expand Up @@ -242,6 +252,7 @@ async function upload(e) {
files.value = "";
dirs.value = "";
set_upload_enabled(true);
window.removeEventListener("beforeunload", beforeUnloadHandler);
}

async function del(e) {
Expand Down

0 comments on commit a0d470a

Please sign in to comment.