Show a confirmation dialog when closing the page while a submission is still pending

pull/260/head
ElementalAlchemist 3 years ago committed by Mike Lang
parent c1e20de813
commit 0709082af7

@ -513,6 +513,7 @@ async function sendVideoData(edited, overrideChanges) {
const submissionResponseElem = document.getElementById("submission-response"); const submissionResponseElem = document.getElementById("submission-response");
submissionResponseElem.classList.value = ["submission-response-pending"]; submissionResponseElem.classList.value = ["submission-response-pending"];
submissionResponseElem.innerText = "Submitting video..."; submissionResponseElem.innerText = "Submitting video...";
window.addEventListener("beforeunload", handleLeavePageWhilePending);
const rangesData = []; const rangesData = [];
for (const rangeContainer of document.getElementById("range-definitions").children) { for (const rangeContainer of document.getElementById("range-definitions").children) {
@ -602,6 +603,8 @@ async function sendVideoData(edited, overrideChanges) {
body: JSON.stringify(editData), body: JSON.stringify(editData),
}); });
window.removeEventListener("beforeunload", handleLeavePageWhilePending);
if (submitResponse.ok) { if (submitResponse.ok) {
submissionResponseElem.classList.value = ["submission-response-success"]; submissionResponseElem.classList.value = ["submission-response-success"];
if (edited) { if (edited) {
@ -642,6 +645,13 @@ async function sendVideoData(edited, overrideChanges) {
} }
} }
function handleLeavePageWhilePending(event) {
event.preventDefault();
event.returnValue =
"The video submission is still pending. Are you sure you want to exit? You may lose your edits.";
return event.returnValue;
}
function generateDownloadURL(timeRanges, downloadType, allowHoles, quality) { function generateDownloadURL(timeRanges, downloadType, allowHoles, quality) {
const queryParts = [`type=${downloadType}`, `allow_holes=${allowHoles}`]; const queryParts = [`type=${downloadType}`, `allow_holes=${allowHoles}`];
for (const range of timeRanges) { for (const range of timeRanges) {

Loading…
Cancel
Save