Skip to content

Commit

Permalink
Updated edit profile cancellation to include any action leaving page …
Browse files Browse the repository at this point in the history
…(ie reload, closing, etc)
  • Loading branch information
andrewzpu committed Apr 24, 2024
1 parent e9bf030 commit 4c5c4e7
Showing 1 changed file with 35 additions and 15 deletions.
50 changes: 35 additions & 15 deletions frontend/src/Pages/ProfileEdit.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@
let other_degree = true;
let other_degree_value = "";
window.onbeforeunload = function() {
var formData = new FormData(document.querySelector('form'));
formData = updateFormData(formData);
if (dataChanged(formData)) {
return "Data will be lost if you leave the page, are you sure?";
} else {
return void (0);
}
};
function checkMajor(major, currOption) {
if (currOption == major) {
other_major = false;
Expand Down Expand Up @@ -73,6 +85,21 @@
.find((element) => element.startsWith("csrftoken="))
.split("=")[1];
function updateFormData(formData) {
if (formData.get("preferred_name") == "") {
formData.set("preferred_name", first_name)
}
if (formData.get("major") == "Other") {
formData.set("major", formData.get("other_major"))
}
if (formData.get("degree") == "Other") {
formData.set("degree", formData.get("other_degree"))
}
return formData;
}
async function onSubmit(event) {
event.preventDefault();
Expand All @@ -87,20 +114,11 @@
// outreach
// car
const formData = new FormData(form);
var formData = new FormData(form);
formData.set("csrfmiddlewaretoken", CSRFToken);
if (formData.get("preferred_name") == "") {
formData.set("preferred_name", first_name)
}
if (formData.get("major") == "Other") {
formData.set("major", formData.get("other_major"))
}
if (formData.get("degree") == "Other") {
formData.set("degree", formData.get("other_degree"))
}
formData = updateFormData();
const submitType = event.submitter.value;
if (submitType == "Cancel") {
Expand All @@ -125,9 +143,7 @@
}
}
function onCancel(formData) {
console.log(user_groups)
function dataChanged(formData) {
let changed = false;
Expand All @@ -145,7 +161,11 @@
}
if (!changed || confirm("You have unsaved changes. Are you sure you want to leave?")) {
return changed;
}
function onCancel(formData) {
if (dataChanged(formData) || confirm("You have unsaved changes. Are you sure you want to leave?")) {
navigate("/profile/self")
}
}
Expand Down

0 comments on commit 4c5c4e7

Please sign in to comment.