add function disable, cancel removing and remove user

This commit is contained in:
Valentin CZERYBA 2022-08-07 00:14:14 +02:00
parent 39010a92f3
commit d58f386aae

View File

@ -41,13 +41,55 @@ if(id.length > 0){
} }
if(buttonUser.length > 0){ if(buttonUser.length > 0){
console.log(disableUser);
document.getElementById(buttonUser).classList.remove("hidden"); document.getElementById(buttonUser).classList.remove("hidden");
} }
var listModalButton = ["disable", "enable", "cancel", "remove"];
for (var i=0; i<listModalButton.length; i++){
document.getElementById(listModalButton[i]+"UserButton").addEventListener("click", function(e){
var httpMethod = ""
var httpUrl = "";
var idInput = document.getElementById("idUpdateInput").value;
switch(e.currentTarget.id){
case "disableUserButton":
httpMethod = "delete";
httpUrl = "users/disable/"+idInput;
break;
case "removeUserButton":
httpMethod = "delete";
httpUrl = "users/"+idInput;
break;
default:
httpMethod = "patch";
httpUrl = "users/enable/"+idInput;
break;
}
instance({
method: httpMethod,
url: httpUrl,
withCredentials: true
})
.then(function(response){
if(response.status == 200){
location.href="/html/user.html?id="+idInput;
}
})
.catch(function(error){
console.log(error);
});
});
}
}) })
.catch(function(error){ .catch(function(error){
console.log(error); console.log(error);
}); });
} }