Disconnect functional

This commit is contained in:
2024-04-14 12:21:38 +02:00
parent 81af439f50
commit 2830958299
2 changed files with 65 additions and 21 deletions

View File

@@ -15,7 +15,7 @@
<body>
<div id="topbar">
<div id="topInfo">
<a href="index.php">
<a id="home">
<p id="DoctISEN" class="top-0 position-fixed">
Doct'ISEN
</p>

View File

@@ -4,6 +4,12 @@ console.log("index.js loaded");
//Felix Part
document.addEventListener("DOMContentLoaded", function() {
if(sessionStorage.getItem("token") !== null) {
displayHomeTopBar();
}
});
function displaySearchResults(data) {
let container = document.getElementById("content");
container.innerHTML = "";
@@ -65,7 +71,7 @@ function removeSearchTopBar(){
topbar.innerHTML = "";
topbar.innerHTML = `
<div id="topInfo">
<a href="index.php">
<a id="home">
<p id="DoctISEN" class="top-0 position-fixed">
Doct'ISEN
</p>
@@ -210,7 +216,7 @@ function displayHomeTopBar() {
if(sessionStorage.getItem("token") === null) {
topbar.innerHTML = `
<div id="topInfo">
<a href="index.php">
<a id="home">
<p id="DoctISEN" class="top-0 position-fixed">
Doct'ISEN
</p>
@@ -230,7 +236,7 @@ function displayHomeTopBar() {
if(user.type === "patient") {
topbar.innerHTML = `
<div id="topInfo">
<a href="index.php">
<a id="home">
<p id="DoctISEN" class="top-0 position-fixed">
Doct'ISEN
</p>
@@ -238,16 +244,17 @@ function displayHomeTopBar() {
<div class="d-flex position-fixed end-0 flex-row align-items-center gap-3 mt-2 top-0">
<img src="https://www.gravatar.com/avatar/${mailMD5}?s=64" alt="avatar" id="avatar" style="width: 14.3%; height: auto; border-radius: 50%">
<div>
<p class="text-white" id="user-name-disconect">${user.name} ${user.surname}</p>
<a class="text-white" id="user-name-disconect">${user.name} ${user.surname}</a>
</div>
<p class="text-white fw-bold link-underline-opacity-75-hover link-underline link-underline-opacity-0 link-offset-3-hover link-underline-light" id="my-rdv">Mes rendez-vous</p>
</div>
</div>`;
attachDisconnectEventListener();
}
else if (user.type === "medecin") {
topbar.innerHTML = `
<div id="topInfo">
<a href="index.php">
<a id="home">
<p id="DoctISEN" class="top-0 position-fixed">
Doct'ISEN
</p>
@@ -255,11 +262,12 @@ function displayHomeTopBar() {
<div class="d-flex position-fixed end-0 flex-row align-items-center gap-3 mt-2 top-0">
<img src="https://www.gravatar.com/avatar/${mailMD5}?s=64" alt="avatar" id="avatar" style="width: 14.3%; height: auto; border-radius: 50%">
<div>
<p class="text-white" id="user-name-disconect">${user.name} ${user.surname}</p>
<a class="text-white" id="user-name-disconect">${user.name} ${user.surname}</a>
</div>
<p class="text-white fw-bold link-underline-opacity-75-hover link-underline link-underline-opacity-0 link-offset-3-hover link-underline-light" id="my-rdv-medecin">Mes rendez-vous practicien</p>
</div>
</div>`;
attachDisconnectEventListener();
}
else {
topbar.innerHTML = `
@@ -270,7 +278,7 @@ function displayHomeTopBar() {
}
}
function displayHome() {
function displayHome(text) {
removeSearchTopBar();
displayHomeTopBar();
let container = document.getElementById("content");
@@ -320,7 +328,9 @@ function displayHome() {
</footer>`;
attachSearchEventListener();
attachLoginUserDisplayEventListener();
displayAlert("Rendez-vous pris avec succès");
if(text !== ""){
displayAlert(text);
}
}
function performSearch(event) {
@@ -390,7 +400,7 @@ function displayLoginUser() {
ajaxRequest('POST', "src/API/requests.php/api/login/patient", function (data) {
if (data.message === "Login success") {
sessionStorage.setItem("token", data.token);
displayHome();
displayHome("Vous êtes connecté");
} else {
alert("Erreur lors de la connexion");
}
@@ -441,7 +451,7 @@ function displayLoginPraticien() {
ajaxRequest('POST', "src/API/requests.php/api/login/medecin", function (data) {
if (data.message === "Login success") {
sessionStorage.setItem("token", data.token)
displayHome();
displayHome("Vous êtes connecté");
} else {
alert("Erreur lors de la connexion");
}
@@ -630,6 +640,11 @@ function displaySignUpUser() {
});
}
function disconnect() {
sessionStorage.removeItem("token");
displayHome("Vous êtes déconnecté");
}
function attachSearchEventListener() {
try{
document.getElementById("recherche").addEventListener("click", function (event) {
@@ -660,15 +675,20 @@ function attachPrendreRDVEventListener() {
let buttons = document.querySelectorAll("button[id^='rdv-id-']");
buttons.forEach(function (button) {
button.addEventListener("click", function (event) {
let RDVid = event.target.id.split("-")[2];
let data = "rdv_id=" + RDVid + "&patient_id=" + 1;
ajaxRequest('PUT', "src/API/requests.php/api/rdv", function (returnData){
if (returnData.success) {
displayHome();
} else {
alert("Erreur lors de la prise de rendez-vous");
}
}, data);
if(sessionStorage.getItem("token") === null) {
displayHome("Vous devez être connecté pour prendre un rendez-vous");
}
else{
let RDVid = event.target.id.split("-")[2];
let data = "rdv_id=" + RDVid + "&patient_id=" + 1;
ajaxRequest('PUT', "src/API/requests.php/api/rdv", function (returnData){
if (returnData.success) {
displayHome("Rendez-vous pris avec succès");
} else {
alert("Erreur lors de la prise de rendez-vous");
}
}, data);
}
});
});
}
@@ -697,6 +717,28 @@ function attachLoginPraticienDisplayEventListener() {
}
}
function attachReturnHomeEventListener() {
try {
document.getElementById("home").addEventListener("click", function (event) {
displayHome("");
});
}
catch (e) {
//Do nothing
//console.error(e);
}
}
function attachDisconnectEventListener() {
try {
document.getElementById("user-name-disconect").addEventListener("click", function (event) {
disconnect();
});
} catch (e) {
//Do nothing
}
}
//Yanis Part
@@ -761,4 +803,6 @@ function ButtonShowRdvPraticient() {
ButtonShowRdvPraticient();
attachSearchEventListener();
attachLoginUserDisplayEventListener();
attachLoginPraticienDisplayEventListener();
attachLoginPraticienDisplayEventListener();
attachReturnHomeEventListener();
attachDisconnectEventListener();