From 6a8fea3ff1c18ec0379864b1ab3a64df1e1d0177 Mon Sep 17 00:00:00 2001 From: amcmanu3 Date: Wed, 12 Jul 2023 12:23:49 -0400 Subject: [PATCH] Add HTML form logic --- .../templates/panel/server_backup.html | 45 +++++++++++++++++-- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/app/frontend/templates/panel/server_backup.html b/app/frontend/templates/panel/server_backup.html index 4061d58d..e271eaf2 100644 --- a/app/frontend/templates/panel/server_backup.html +++ b/app/frontend/templates/panel/server_backup.html @@ -44,11 +44,8 @@


-
+ {% raw xsrf_form_html() %} - - - {% if data['backing_up'] %}
@@ -415,6 +412,46 @@ }); $(document).ready(function () { + $("#config_form").on("submit", async function (e) { + e.preventDefault(); + var token = getCookie("_xsrf") + let backupForm = document.getElementById("backup_form"); + //Remove checks that we don't need in form data. + $(this).children("before-check").remove(); + $(this).children("after-check").remove(); + let formData = new FormData(backupForm); + //Create an object from the form data entries + let formDataObject = Object.fromEntries(formData.entries()); + //We need to make sure these are sent regardless of whether or not they're checked + formDataObject.compress = $("#compress").prop('checked'); + formDataObject.shutdown = $("#shutdown").prop('checked'); + console.log(formDataObject); + // Format the plain form data as JSON + let formDataJsonString = JSON.stringify(formDataObject, replacer); + formDataJsonString["ignored_exits"] = toString(formDataJsonString["ignored_exits"]); + console.log(formDataJsonString.ignored_exits) + + console.log(formDataJsonString); + + let res = await fetch(`/api/v2/servers/${serverId}`, { + method: 'PATCH', + headers: { + 'X-XSRFToken': token + }, + body: formDataJsonString, + }); + let responseData = await res.json(); + if (responseData.status === "ok") { + window.location.reload(); + } else { + + bootbox.alert({ + title: responseData.error, + message: responseData.error_data + }); + } + }); + try { if ($('#backup_path').val() == '') { console.log('true')