Refactored codebase & auth bug fix

This commit is contained in:
2025-05-15 13:33:58 +03:00
parent 36226dbbac
commit eeda1b500d
13 changed files with 424 additions and 347 deletions
+59
View File
@@ -0,0 +1,59 @@
const sql_table = document.getElementById("sql_table");
const upload = document.getElementById("upload");
const download = document.getElementById("download");
const logout = document.getElementById("logout");
const add = document.getElementById("add");
const sql_rows = sql_table.rows;
function setEventListeners(element, cb) {
element.onmouseenter = async function () {
this.style.backgroundColor = "blue";
};
element.onmouseleave = async function () {
this.style.backgroundColor = "";
};
element.onmousedown = async function () {
this.style.backgroundColor = "red";
};
element.ondblclick = async function () {
this.style.backgroundColor = "blue";
cb();
};
}
setEventListeners(upload, async () => {
const input = document.getElementById("file_input");
const upload = (file) => {
const formData = new FormData();
formData.append('file', file);
fetch('/app/upload', {
method: 'POST',
body: formData
}).then((response) => {
location.reload();
});
}
const onSelectFile = () => upload(input.files[0]);
input.addEventListener('change', onSelectFile, false);
input.click();
});
setEventListeners(add, () => {
window.location.href = "/app/add";
});
setEventListeners(download, () => {
window.location.href = "/app/download";
});
setEventListeners(logout, () => {
window.location.href = `${window.location.protocol}//logout@${window.location.host}/`;
});
for (let i = 1; i < sql_rows.length; i++) {
setEventListeners(sql_rows[i], () => {
window.location.href = `/app/edit?element=${sql_rows[i].cells[0].innerText}`;
});
}