кнопка адмена

This commit is contained in:
neroduckale 2024-01-03 16:21:15 +05:00
parent 5c9d1989f5
commit b1c5e4c5a5
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG key ID: 399E73062E1A3667
2 changed files with 64 additions and 31 deletions

View file

@ -1,5 +1,5 @@
console.log("Start!")
alert("startaed!")
const loading = document.getElementById("loading");
let loadingLive = true
async function getUsers() {
// отправляет запрос и получаем ответ
const response = await fetch("/api/users", {
@ -10,29 +10,46 @@ async function getUsers() {
if (response.ok === true) {
// получаем данные
const users = await response.json();
const table = document.querySelector("#users");
const count = document.querySelector("#count")
count.outerHTML = "1";
document.querySelector("#loading").destroy();
const table = document.getElementById("users");
if (loadingLive) {
loading.remove();
loadingLive = false
}
users.forEach(user => table.append(create(user)));
return users;
}
}
// Получение одного пользователя
async function getUser(id) {
const response = await fetch(`/api/users/${id}`, {
method: "GET",
headers: { "Accept": "application/json" }
});
if (response.ok === true) {
const user = await response.json();
document.getElementById("userId").value = user.id;
document.getElementById("userName").value = user.nickname;
document.getElementById("userMast").value = user.mast;
}
else {
// если произошла ошибка, получаем сообщение об ошибке
const error = await response.json();
console.log(error.message); // и выводим его на консоль
}
function create(user) {
let tr = document.createElement("tr");
let tdName = document.createElement("td");
let tdMast = document.createElement("td");
let tdId = document.createElement("td");
let tdBut = document.createElement("td");
let ButtDel = document.createElement("button");
let ButtEdit = document.createElement("button");
tdId.append(user.id);
tdName.append(user.nickname);
tdMast.append(user.mast);
ButtDel.append("УДАЛИТЬ");
ButtEdit.append("ИЗМЕНИТЬ");
tdBut.append(ButtDel, ButtEdit);
tdBut.id = "ADMINBUT" + user.id;
tdBut.className = "ADMINBUT"
tdBut.style.display = "none";
tr.append(tdId, tdName, tdMast, tdBut);
return tr;
}
// Добавление пользователя
await getUsers();
console.log(getUsers());
console.log("loaded!");
function admin() {
document.body.style.background = "black";
document.getElementById("admin").remove();
let adminbuttons = document.getElementsByClassName("ADMINBUT");
for (let item of adminbuttons) {
item.style.display = "inline";
}
}