Files
auth_service_c/web/js/del_user.js
T
wt 155c259ea9
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Make (push) Successful in 9s
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-CMake (push) Successful in 14s
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Meson (push) Failing after 8s
added web and fix some problems
2025-08-27 17:00:57 +07:00

42 lines
1.4 KiB
JavaScript

const userstablebody = document.querySelector('#alluserstablebody')
const confirmform = document.querySelector('.confirmform')
const confirmformcancel = document.querySelector('#no')
const confirmformok = document.querySelector('#yes')
let useridtodelete = "";
userstablebody.addEventListener('click', e => {
if (e.target.classList.contains('deleteuser')) {
useridtodelete = e.target.id
confirmform.classList.add("active")
}
if (e.target.classList.contains('changepassword')) {
change_password(e.target.id)
}
if (e.target.classList.contains('changeuser')) {
change_user_data(parseInt(e.target.id))
}
})
confirmformcancel.addEventListener('click', () => {
useridtodelete = ""
confirmform.classList.remove('active')
})
confirmformok.addEventListener('click', async () => {
const status = await fetch(routes.deluser(), {
method: 'DELETE',
body: `{"token":"${localStorage.getItem('token')}","userid":${useridtodelete}}`
}).then(data => data.json()).then(jsondata => jsondata).catch((error) => {
notification(`Ошибка на сервере: ${error}`, "error")
})
if (status.success) {
confirmform.classList.remove('active')
await get_all_users()
notification("Пользователь успешно удален", "success")
} else {
notification("Can't delete user", "error")
confirmform.classList.remove('active')
}
})