mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Add HTML form logic
This commit is contained in:
parent
c82e0fe20a
commit
6a8fea3ff1
@ -44,11 +44,8 @@
|
|||||||
<div class="col-md-6 col-sm-12">
|
<div class="col-md-6 col-sm-12">
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
<form class="forms-sample" method="post" action="/panel/server_backup">
|
<form id="backup-form" class="forms-sample" method="post" action="/panel/server_backup">
|
||||||
{% raw xsrf_form_html() %}
|
{% raw xsrf_form_html() %}
|
||||||
<input type="hidden" name="id" value="{{ data['server_stats']['server_id']['server_id'] }}">
|
|
||||||
<input type="hidden" name="subpage" value="backup">
|
|
||||||
|
|
||||||
|
|
||||||
{% if data['backing_up'] %}
|
{% if data['backing_up'] %}
|
||||||
<div class="progress" style="height: 15px;">
|
<div class="progress" style="height: 15px;">
|
||||||
@ -415,6 +412,46 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
$(document).ready(function () {
|
$(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 {
|
try {
|
||||||
if ($('#backup_path').val() == '') {
|
if ($('#backup_path').val() == '') {
|
||||||
console.log('true')
|
console.log('true')
|
||||||
|
Loading…
Reference in New Issue
Block a user