Enhance API functionality: add token generation methods, implement entry management, and improve setup process with settings storage

This commit is contained in:
marc-go committed 2026-10-06 14:46:25 +02:00
1 parent 8ef5f7a941
commit 9316818753
9 files changed
+248 -25

No files matched your search

@@ -26,13 +26,86 @@
p {
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
hr {
border: 1px solid rgb(211, 211, 211);
}
.loader {
display: flex;
justify-content: center;
align-items: center;
}
</style>
</head>
<body>
<h1 class="md-typescale-display-large">%appname%</h1>
<h3 class="md-typescale-display-medium">All Entrys</h3>
<md-filled-tonal-button>
<md-filled-tonal-button id="entry_add">
Add Entry
</md-filled-tonal-button>
</body>
<h2 class="md-typescale-display-medium">All Entrys</h2>
%entrys%
<md-dialog id="add_entry_dialog">
<div slot="headline">
Add entry
</div>
<form slot="content" method="dialog">
<md-filled-text-field id="entry_name" label="Name"></md-filled-text-field><br><br>
<md-filled-text-field id="entry_text" label="Text" rows="5" style="resize: vertical;" type="textarea"></md-filled-text-field>
<div class="loader" id="loader" style="display: none;">
<md-circular-progress id="add_entry_load" indeterminate></md-circular-progress>
</div>
<p id="entry_return"></p>
</form>
<div slot="actions">
<md-filled-button id="entry_submit">Submit</md-filled-button>
<md-text-button id="entry_close">Close</md-text-button>
</div>
</md-dialog>
<script>
document.getElementById("entry_add").addEventListener("click", function() {
document.getElementById("add_entry_dialog").setAttribute("open", "");
});
document.getElementById("entry_close").addEventListener("click", function() {
document.getElementById("add_entry_dialog").removeAttribute("open");
});
document.getElementById("entry_submit").addEventListener("click", function() {
document.getElementById("entry_name").style.display = "none";
document.getElementById("entry_text").style.display = "none";
document.getElementById("entry_submit").style.display = "none";
document.getElementById("entry_close").style.display = "none";
document.getElementById("loader").style.display = "flex";
name = document.getElementById("entry_name").value;
text = document.getElementById("entry_text").value;
fetch("/api/entrys/add.php", {
method: "POST",
body: JSON.stringify({
name: name,
text: text
})
})
.then(response => response.json())
.then(data => {
document.getElementById("loader").style.display = "none";
if (data.status !== 200) {
document.getElementById("entry_return").innerHTML = "API returned an error: " + data.error_text;
document.getElementById("entry_close").style.display = "block";
}else{
document.getElementById("entry_return").innerHTML = "Success! Maybe your entry must be aproved by the owner.";
document.getElementById("entry_close").style.display = "block";
}
})
.catch(error => {
document.getElementById("loader").style.display = "none";
document.getElementById("entry_return").innerHTML = "There was an error: " + error;
document.getElementById("entry_close").style.display = "block";
});
});
</script>
</body>
</html>
+26 -5
View File
@@ -66,6 +66,18 @@
<md-filled-button id="close-button">Close</md-filled-button>
</div>
</md-dialog>
<md-dialog id="success-dialog">
<div slot="headline">
Success!
</div>
<form slot="content" method="dialog" id="error-dialog-text">
Your Guestbook is finaly configurated! You can find the admin Panel on <span id="success-admin-url"></span>.
</form>
<div slot="actions">
<md-filled-button id="success-dialog-home">Open Guestbook</md-filled-button>
<md-filled-button id="success-dialog-admin">Open Admin Panel</md-filled-button>
</div>
</md-dialog>
<script>
if (window.location.protocol == "http:") {
document.getElementById("http-dialog").setAttribute("open", "");
@@ -80,7 +92,15 @@
document.getElementById("close-button").addEventListener("click", function() {
document.getElementById("error-dialog").removeAttribute("open");
})
});
document.getElementById("success-dialog-home").addEventListener("click", function() {
window.location.reload();
});
document.getElementById("success-dialog-admin").addEventListener("click", function() {
window.location.href = "/admin";
});
function checkSetup() {
const username = document.getElementById("setup-username").value;
@@ -108,14 +128,15 @@
}
})
.then(response => response.json())
.then(data => function() {
if (data.status !== 200) {
.then(data => {
if (data.status == 200) {
document.getElementById("success-admin-url").innerHTML = window.location.href + "admin";
document.getElementById("success-dialog").setAttribute("open", "");
}else{
console.error("Server returned following message: " + data.error);
document.getElementById("error-dialog-text").innerHTML = data.display_error;
document.getElementById("error-dialog").setAttribute("open", "");
}else{
alert("Tres bien!");
}
})
}