mirror of
https://github.com/BreizhHardware/ProjetS4COMWEB.git
synced 2026-01-18 16:47:35 +01:00
Merge pull request #25 from BreizhHardware/felix
Refactor code to be in multiple file instead of one big js file
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import {TokenDecode} from "./lib.js";
|
||||
import {attachSearchEventListener} from "./search.js";
|
||||
import {attachLoginUserDisplayEventListener, attachLoginPraticienDisplayEventListener, disconnect, displayHome, displayHomeTopBar} from "./login.js";
|
||||
console.log("index.js loaded");
|
||||
|
||||
|
||||
@@ -10,733 +11,6 @@ document.addEventListener("DOMContentLoaded", function() {
|
||||
}
|
||||
});
|
||||
|
||||
function displaySearchResults(data) {
|
||||
let container = document.getElementById("content");
|
||||
container.innerHTML = "";
|
||||
let mainDiv = document.createElement("div");
|
||||
mainDiv.classList.add("d-flex", "flex-row", "flex-wrap", "mx-5", "gap-5", "justify-content-center");
|
||||
let count = 0;
|
||||
data.forEach(function(element) {
|
||||
count++;
|
||||
let card = document.createElement("div");
|
||||
card.classList.add("card", "w-25");
|
||||
card.innerHTML = `
|
||||
<div class="row g-0">
|
||||
<div class="col-md-4">
|
||||
<img src="src/img/Medecin_test.jpeg" alt="doctor" class="img-fluid rounded-start" width="300" height="300">
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">${element.m_surname} ${element.m_name}</h5>
|
||||
<h6 class="card-subtitle mb-2 text-body-secondary">${element.m_specialty}</h6>
|
||||
<p class="card-text">Code Postal: ${element.m_postal}</p>
|
||||
<button type="submit" class="btn btn-danger" id="m-id-${element.m_id}">Prendre rendez-vous</button>
|
||||
</div>
|
||||
</div>`;
|
||||
mainDiv.appendChild(card);
|
||||
});
|
||||
container.appendChild(mainDiv);
|
||||
if(count === 0) {
|
||||
mainDiv.innerHTML = "<h1>Aucun résultats</h1>";
|
||||
}
|
||||
else {
|
||||
let resultText = document.createElement("h1");
|
||||
resultText.textContent = count + " résultats";
|
||||
container.insertBefore(resultText, mainDiv);
|
||||
attachRDVEventListener();
|
||||
}
|
||||
}
|
||||
|
||||
function displaySearchTopBar(){
|
||||
let topbar = document.getElementById("topbar");
|
||||
let searchbar = document.getElementById("searchbar");
|
||||
|
||||
let form = topbar.querySelector("form");
|
||||
if (form) {
|
||||
topbar.removeChild(form);
|
||||
}
|
||||
|
||||
searchbar.innerHTML = `
|
||||
<form class="input-group p-5" onsubmit="performSearch(event)" method="post">
|
||||
<input type="text" aria-label="First name" class="form-control" id="nom" name="nom" placeholder="Nom, spécialité">
|
||||
<input type="text" aria-label="Last name" class="form-control" id="postal" name="postal" placeholder="Où ?">
|
||||
<button class="btn btn-danger" type="submit" id="recherche">Rechercher</button>
|
||||
</form>`;
|
||||
|
||||
attachSearchEventListener();
|
||||
}
|
||||
|
||||
function removeSearchTopBar(){
|
||||
let topbar = document.getElementById("topbar");
|
||||
topbar.innerHTML = "";
|
||||
topbar.innerHTML = `
|
||||
<div id="topInfo">
|
||||
<a id="home">
|
||||
<p id="DoctISEN" class="top-0 position-fixed">
|
||||
Doct'ISEN
|
||||
</p>
|
||||
</a>
|
||||
<div class="d-flex position-fixed end-0 flex-row align-items-center gap-3 mt-2 top-0">
|
||||
<?php
|
||||
loginUI($pdo);
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<div id="searchbar"></div>`;
|
||||
}
|
||||
|
||||
function displayRDVForDate(data) {
|
||||
let container = document.getElementById("rdv-list");
|
||||
container.innerHTML = "";
|
||||
let count = 0;
|
||||
data.forEach(function(element) {
|
||||
try{
|
||||
let card = document.createElement("div");
|
||||
card.classList.add("card");
|
||||
element.rdv_time = element.rdv_time.slice(0, 5);
|
||||
card.innerHTML = `
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">${element.rdv_time}</h5>
|
||||
<p class="card-text">Adresse: ${element.l_adress} <br>
|
||||
Ville: ${element.l_city} ${element.l_postal}</p>
|
||||
<button type="submit" class="btn btn-danger" id="rdv-id-${element.rdv_id}">Prendre ce rendez-vous</button>
|
||||
</div>`;
|
||||
container.appendChild(card);
|
||||
count++;
|
||||
} catch (e) {
|
||||
//Do nothing
|
||||
//console.error(e);
|
||||
}
|
||||
});
|
||||
if(count === 0) {
|
||||
container.innerHTML = "<h1>Aucun rendez-vous</h1>";
|
||||
}
|
||||
else {
|
||||
let resultText = document.createElement("h1");
|
||||
resultText.textContent = count + " rendez-vous";
|
||||
container.insertBefore(resultText, container.firstChild);
|
||||
attachPrendreRDVEventListener();
|
||||
}
|
||||
}
|
||||
|
||||
function displayCalendar(data) {
|
||||
let container = document.getElementById("content");
|
||||
container.innerHTML = "";
|
||||
let mainDiv = document.createElement("div");
|
||||
mainDiv.classList.add("row");
|
||||
|
||||
// Colonne de gauche
|
||||
let leftCol = document.createElement("div");
|
||||
leftCol.classList.add("col", "h-100", "border-dark", "border-3", "justify-content-center", "text-center", "ms-3");
|
||||
let leftDiv = document.createElement("div");
|
||||
leftDiv.classList.add("d-flex", "flex-column", "justify-content-center", "gap-6");
|
||||
|
||||
// Calendrier de sélection de date
|
||||
let form = document.createElement("form");
|
||||
form.classList.add("mt-3");
|
||||
form.id = "date-selection-form";
|
||||
let label = document.createElement("label");
|
||||
label.setAttribute("for", "date");
|
||||
label.textContent = "Choisissez une date :";
|
||||
form.appendChild(label);
|
||||
let input = document.createElement("input");
|
||||
input.setAttribute("type", "date");
|
||||
input.setAttribute("name", "start");
|
||||
input.setAttribute("id", "date");
|
||||
input.classList.add("mt-2", "form-control");
|
||||
form.appendChild(input);
|
||||
let submit = document.createElement("input");
|
||||
submit.setAttribute("type", "submit");
|
||||
submit.setAttribute("value", "Valider");
|
||||
submit.classList.add("mt-2", "btn", "btn-outline-danger");
|
||||
form.appendChild(submit);
|
||||
leftDiv.appendChild(form);
|
||||
|
||||
// Carte du médecin
|
||||
let medecinCard = document.createElement("div");
|
||||
medecinCard.classList.add("card", "mx-auto", "d-flex", "flex-row");
|
||||
medecinCard.innerHTML = `
|
||||
<div class="row g-0">
|
||||
<div class="col-md-4">
|
||||
<img src="src/img/Medecin_test.jpeg" class="img-fluid rounded-start" alt="doctor" width="300" height="300">
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">${data[0].m_surname} ${data[0].m_name}</h5>
|
||||
<h6 class="card-subtitle mb-2 text-body-secondary">${data[0].m_specialty}</h6>
|
||||
</div>
|
||||
</div>
|
||||
</div>`;
|
||||
leftDiv.appendChild(medecinCard);
|
||||
|
||||
leftCol.appendChild(leftDiv);
|
||||
mainDiv.appendChild(leftCol);
|
||||
|
||||
// Colonne de droite
|
||||
let rightCol = document.createElement("div");
|
||||
rightCol.classList.add("col-8", "h-100", "border-start", "border-dark", "border-3", "me-3");
|
||||
|
||||
// Liste des rendez-vous
|
||||
let rdvList = document.createElement("div");
|
||||
rdvList.classList.add("mt-3", "d-flex", "flex-column", "gap-3");
|
||||
rdvList.id = "rdv-list";
|
||||
rightCol.appendChild(rdvList);
|
||||
|
||||
mainDiv.appendChild(rightCol);
|
||||
container.appendChild(mainDiv);
|
||||
displayRDVForDate(data);
|
||||
document.getElementById("date-selection-form").addEventListener("submit", function(event) {
|
||||
event.preventDefault();
|
||||
let date = document.getElementById("date").value;
|
||||
let id = data[0].m_id; // Assuming 'data' is accessible in this scope and contains the doctor's details
|
||||
ajaxRequest('GET', "src/API/requests.php/api/rdv-date?date=" + date + "&id=" + id, function (data) {
|
||||
displayRDVForDate(data);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function displayAlert(text) {
|
||||
let alert = document.getElementById("Alert");
|
||||
alert.innerHTML = "";
|
||||
alert.innerHTML = `
|
||||
<div class="alert alert-success" role="alert">
|
||||
${text}
|
||||
</div>`;
|
||||
setTimeout(clearAlert, 5000);
|
||||
}
|
||||
|
||||
function clearAlert() {
|
||||
let alert = document.getElementById("Alert");
|
||||
alert.innerHTML = "";
|
||||
}
|
||||
|
||||
function displayHomeTopBar() {
|
||||
let topbar = document.getElementById("topbar");
|
||||
topbar.innerHTML = "";
|
||||
if(sessionStorage.getItem("token") === null) {
|
||||
topbar.innerHTML = `
|
||||
<div id="topInfo">
|
||||
<a id="home">
|
||||
<p id="DoctISEN" class="top-0 position-fixed">
|
||||
Doct'ISEN
|
||||
</p>
|
||||
</a>
|
||||
<div class="d-flex position-fixed end-0 flex-row align-items-center gap-3 mt-2 top-0">
|
||||
<button type="button" class="btn btn-danger" style="top: 0.4375em;" id="login-praticien">Vous êtes praticien ?</button> <button type="button" class="btn btn-danger" style="top: 0.4375em;" id="login-user">Se connecter</button><p> </p>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
attachLoginUserDisplayEventListener();
|
||||
attachLoginPraticienDisplayEventListener();
|
||||
}
|
||||
else {
|
||||
let token = sessionStorage.getItem("token");
|
||||
let user = TokenDecode(token);
|
||||
const mailMD5 = CryptoJS.MD5(user.mail);
|
||||
if(user.type === "patient") {
|
||||
topbar.innerHTML = `
|
||||
<div id="topInfo">
|
||||
<a id="home">
|
||||
<p id="DoctISEN" class="top-0 position-fixed">
|
||||
Doct'ISEN
|
||||
</p>
|
||||
</a>
|
||||
<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>
|
||||
<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 id="home">
|
||||
<p id="DoctISEN" class="top-0 position-fixed">
|
||||
Doct'ISEN
|
||||
</p>
|
||||
</a>
|
||||
<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>
|
||||
<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 = `
|
||||
<div id="topInfo">
|
||||
<p class="alert-danger">Erreur</p>
|
||||
</div>`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function displayHome(text) {
|
||||
removeSearchTopBar();
|
||||
displayHomeTopBar();
|
||||
let container = document.getElementById("content");
|
||||
container.classList = "";
|
||||
container.innerHTML = "";
|
||||
container.innerHTML = `
|
||||
<div style="background-color: red; height: 50vh;">
|
||||
<div class="d-flex justify-content-center align-items-center" style="background-color: red;" id="Alert"></div>
|
||||
<img src="src/img/img_index.png" alt="img_index" id="img_index">
|
||||
<div id="rdv">
|
||||
<p class="text-white fw-bold fs-3">Trouvez un rendez vous avec un medecin</p>
|
||||
<form action="" class="input-group" method="post">
|
||||
<input type="text" aria-label="First name" class="form-control" id="nom" name="nom" placeholder="Nom, spécialité">
|
||||
<input type="text" aria-label="Last name" class="form-control" id="postal" name="postal" placeholder="Où ?">
|
||||
<button class="btn btn-success" type="submit" id="recherche">Rechercher</button>
|
||||
</form>
|
||||
</div>
|
||||
<div class="d-flex justify-content-center gap-5 w-100" id="cardPos">
|
||||
<div class="card" style="width: 18rem;">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Information</h5>
|
||||
<h6 class="card-subtitle mb-2 text-body-secondary">Ligue contre le cancer</h6>
|
||||
<p class="card-text">Mois sans tabac: c’est le moment d’arrêter !</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card" style="width: 18rem;">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Information</h5>
|
||||
<h6 class="card-subtitle mb-2 text-body-secondary">Pharmacie Sanchez</h6>
|
||||
<p class="card-text">Le rôle du phramacien évolue: Venez nous voir.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card" style="width: 18rem;">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Information</h5>
|
||||
<h6 class="card-subtitle mb-2 text-body-secondary">Doct’ISEN</h6>
|
||||
<p class="card-text">Un empechement: Prevenez votre soignant.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<footer class="fixed-bottom m-2 mx-4">
|
||||
<p>Recherche de praticiens</p>
|
||||
<p>Doct’ISEN, 33 QUATER Av. du Champ de Manœuvre, 44470 Carquefou</p>
|
||||
<p class="text-secondary">Conditions générales d'utilisation • Conditions d'utilisation du site Doct'ISEN • Politique relative à la protection des données personnelles • Politique en matière de cookies • Gestion des cookies et consentement • Règles de référencement • Mentions légales</p>
|
||||
<p class="text-secondary">Annuaire des médecins du CNOM • Annuaire des chirurgiens-dentistes de l'ONCD • Ordre National des Médecins • Ordre National des Chirurgiens-Dentistes</p>
|
||||
</footer>`;
|
||||
attachSearchEventListener();
|
||||
attachLoginUserDisplayEventListener();
|
||||
if(text !== ""){
|
||||
displayAlert(text);
|
||||
}
|
||||
}
|
||||
|
||||
function performSearch(event) {
|
||||
event.preventDefault();
|
||||
let type = document.getElementById("nom").value;
|
||||
let postal = document.getElementById("postal").value;
|
||||
if (postal === "") {
|
||||
if (type === "") {
|
||||
alert("Veuillez remplir au moins un champ");
|
||||
return;
|
||||
} else {
|
||||
ajaxRequest('GET', "src/API/requests.php/api/search-type?type=" + type, function (data) {
|
||||
displaySearchResults(data);
|
||||
displaySearchTopBar();
|
||||
})
|
||||
}
|
||||
} else if (type === "") {
|
||||
ajaxRequest('GET', "src/API/requests.php/api/search-postal?postal=" + postal, function (data) {
|
||||
displaySearchResults(data);
|
||||
displaySearchTopBar();
|
||||
});
|
||||
} else {
|
||||
ajaxRequest('GET', "src/API/requests.php/api/search?type=" + type + "&postal=" + postal, function (data) {
|
||||
displaySearchResults(data);
|
||||
displaySearchTopBar();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function displayLoginUser() {
|
||||
if (sessionStorage.getItem("token") === null) {
|
||||
let container = document.getElementById("content");
|
||||
container.innerHTML = "";
|
||||
container.className = 'd-flex flex-column justify-content-center text-center w-100 login-ui';
|
||||
container.innerHTML = `
|
||||
<div class="h-100 d-flex flex-column gap-0 justify-content-center text-center w-50 mx-25">
|
||||
<div class="p-3 m-0 border-0 bd-example m-0 border-0" id="login-part">
|
||||
<div class="text-center align-content-center">
|
||||
<h5 class="text-center fw-bold">J'ai déjà un compte Doct'ISEN</h5>
|
||||
<form class="px-4 py-3">
|
||||
<div class="mb-3">
|
||||
<label for="user-login-mail" class="form-label">Adresse mail</label>
|
||||
<input type="email" class="form-control" id="user-login-mail" placeholder="email@example.com" name="mail">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="user-login-password" class="form-label">Mot de passe</label>
|
||||
<input type="password" class="form-control" id="user-login-password" placeholder="********" name="password">
|
||||
</div>
|
||||
<div class="text-center justify-content-center">
|
||||
<button type="submit" class="btn btn-danger logButton" id="user-login-button">Se connecter</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="p-3 m-0 border-0 bd-example m-0 border-0 text-center justify-content-center mt-5" id="signup-part">
|
||||
<div class="text-center align-content-center">
|
||||
<h5 class="fw-bold">Nouveau sur Doct'ISEN?</h5>
|
||||
<a id="signup-user">
|
||||
<button class="btn btn-danger logButton">S'inscrire</button>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>`;
|
||||
document.getElementById("user-login-button").addEventListener("click", function (event) {
|
||||
event.preventDefault();
|
||||
let mail = document.getElementById("user-login-mail").value;
|
||||
let password = document.getElementById("user-login-password").value;
|
||||
let data = "mail=" + mail + "&password=" + password;
|
||||
ajaxRequest('POST', "src/API/requests.php/api/login/patient", function (data) {
|
||||
if (data.message === "Login success") {
|
||||
sessionStorage.setItem("token", data.token);
|
||||
displayHome("Vous êtes connecté");
|
||||
} else {
|
||||
alert("Erreur lors de la connexion");
|
||||
}
|
||||
}, data);
|
||||
});
|
||||
document.getElementById("signup-user").addEventListener("click", function (event) {
|
||||
displaySignUpUser();
|
||||
});
|
||||
}
|
||||
else {
|
||||
displayHome("Vous êtes déjà connecté");
|
||||
}
|
||||
}
|
||||
|
||||
function displayLoginPraticien() {
|
||||
let container = document.getElementById("content");
|
||||
if (sessionStorage.getItem("token") === null) {
|
||||
container.innerHTML = "";
|
||||
container.className = 'd-flex flex-column justify-content-center text-center w-100 login-ui';
|
||||
container.innerHTML = `
|
||||
<div class="h-100 d-flex flex-column gap-0 justify-content-center text-center w-50 mx-25">
|
||||
<div class="p-3 m-0 border-0 bd-example m-0 border-0" id="login-part">
|
||||
<div class="text-center align-content-center">
|
||||
<h5 class="text-center fw-bold">J'ai déjà un compte praticien Doct'ISEN</h5>
|
||||
<form class="px-4 py-3">
|
||||
<div class="mb-3">
|
||||
<label for="praticien-login-mail" class="form-label">Adresse mail</label>
|
||||
<input type="email" class="form-control" id="praticien-login-mail" placeholder="email@example.com" name="mail">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="praticien-login-password" class="form-label">Mot de passe</label>
|
||||
<input type="password" class="form-control" id="praticien-login-password" placeholder="********" name="password">
|
||||
</div>
|
||||
<div class="text-center justify-content-center">
|
||||
<button type="submit" class="btn btn-danger logButton" id="praticien-login-button">Se connecter</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="p-3 m-0 border-0 bd-example m-0 border-0 text-center justify-content-center mt-5" id="signup-part">
|
||||
<div class="text-center align-content-center">
|
||||
<h5 class="fw-bold">Nouveau praticien sur Doct'ISEN?</h5>
|
||||
<a id="signup-praticien">
|
||||
<button class="btn btn-danger logButton">S'inscrire</button>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>`;
|
||||
document.getElementById("praticien-login-button").addEventListener("click", function (event) {
|
||||
event.preventDefault();
|
||||
let mail = document.getElementById("praticien-login-mail").value;
|
||||
let password = document.getElementById("praticien-login-password").value;
|
||||
let data = "mail=" + mail + "&password=" + password;
|
||||
ajaxRequest('POST', "src/API/requests.php/api/login/medecin", function (data) {
|
||||
if (data.message === "Login success") {
|
||||
sessionStorage.setItem("token", data.token)
|
||||
displayHome("Vous êtes connecté");
|
||||
} else {
|
||||
alert("Erreur lors de la connexion");
|
||||
}
|
||||
}, data);
|
||||
});
|
||||
document.getElementById("signup-praticien").addEventListener("click", function (event) {
|
||||
displaySignUpPraticien();
|
||||
});
|
||||
}
|
||||
else {
|
||||
displayHome("Vous êtes déjà connecté");
|
||||
}
|
||||
}
|
||||
|
||||
function displaySignUpPraticien() {
|
||||
if (sessionStorage.getItem("token") === null) {
|
||||
let container = document.getElementById("content");
|
||||
container.innerHTML = "";
|
||||
container.className = 'd-flex flex-column justify-content-center text-center w-100 signup-ui-praticien';
|
||||
container.innerHTML = `
|
||||
<div class="h-100 d-flex flex-column gap-0 justify-content-center text-center w-50 mx-25" style="margin-top: -15%;">
|
||||
<div class="p-3 m-0 border-0 bd-example border-0" id="signup-sign-part">
|
||||
<div class="text-center align-content-center">
|
||||
<h5 class="text-center fw-bold">Inscription praticien sur Doct'ISEN</h5>
|
||||
<form class="px-4 py-3">
|
||||
<div class="mb-3">
|
||||
<label for="praticien-signup-name" class="form-label">Nom</label>
|
||||
<input type="text" class="form-control" id="praticien-signup-name" placeholder="Nom" name="name">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="praticien-signup-surname" class="form-label">Prénom</label>
|
||||
<input type="text" class="form-control" id="praticien-signup-surname" placeholder="Prénom" name="surname">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="praticien-signup-mail" class="form-label">Adresse mail</label>
|
||||
<input type="email" class="form-control" id="praticien-signup-mail" placeholder="example@example.com" name="mail">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="praticien-signup-mail-confirm" class="form-label">Confirmer adresse mail</label>
|
||||
<input type="email" class="form-control" id="praticien-signup-mail-confirm" placeholder="example@example.com" name="mail-confirm">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="praticien-signup-password" class="form-label">Mot de passe</label>
|
||||
<input type="password" class="form-control" id="praticien-signup-password" placeholder="********" name="password">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="praticien-signup-password-confirm" class="form-label">Confirmer mot de passe</label>
|
||||
<input type="password" class="form-control" id="praticien-signup-password-confirm" placeholder="********" name="password-confirm">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="praticien-signup-phone" class="form-label">Numéro de téléphone</label>
|
||||
<input type="tel" class="form-control" id="praticien-signup-phone" placeholder="06********" name="phone">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="praticien-signup-specialty" class="form-label">Spécialité</label>
|
||||
<input type="text" class="form-control" id="praticien-signup-specialty" placeholder="Spécialité" name="specialty">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="praticien-signup-postal" class="form-label">Code postal</label>
|
||||
<input type="text" class="form-control" id="praticien-signup-postal" placeholder="Code postal" name="postal">
|
||||
</div>
|
||||
<div class="text-center justify-content-center">
|
||||
<button type="submit" class="btn btn-danger logButton" id="praticien-signup-button">S'inscrire</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="p-3 m-0 border-0 bd-example m-0 border-0 text-center justify-content-center mt-5" id="signup-part">
|
||||
<div class="text-center align-content-center">
|
||||
<h5 class="fw-bold">Déjà inscrit en tant que praticien ?</h5>
|
||||
<a id="login-praticien2">
|
||||
<button class="btn btn-danger logButton">Se connecter</button>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>`;
|
||||
document.getElementById("login-praticien2").addEventListener("click", function (event) {
|
||||
displayLoginPraticien();
|
||||
});
|
||||
document.getElementById("praticien-signup-button").addEventListener("click", function (event) {
|
||||
event.preventDefault();
|
||||
let name = document.getElementById("praticien-signup-name").value;
|
||||
let surname = document.getElementById("praticien-signup-surname").value;
|
||||
let mail = document.getElementById("praticien-signup-mail").value;
|
||||
let mailConfirm = document.getElementById("praticien-signup-mail-confirm").value;
|
||||
let password = document.getElementById("praticien-signup-password").value;
|
||||
let passwordConfirm = document.getElementById("praticien-signup-password-confirm").value;
|
||||
let phone = document.getElementById("praticien-signup-phone").value;
|
||||
let specialty = document.getElementById("praticien-signup-specialty").value;
|
||||
let postal = document.getElementById("praticien-signup-postal").value;
|
||||
if (mail !== mailConfirm) {
|
||||
alert("Les adresses mail ne correspondent pas");
|
||||
return;
|
||||
}
|
||||
if (password !== passwordConfirm) {
|
||||
alert("Les mots de passe ne correspondent pas");
|
||||
return;
|
||||
}
|
||||
let data = "name=" + name + "&surname=" + surname + "&mail=" + mail + "&password=" + password + "&specialite=" + specialty + "&phone=" + phone + "&postal=" + postal;
|
||||
ajaxRequest('PUT', "src/API/requests.php/api/signup/medecin", function (data) {
|
||||
if (data.success) {
|
||||
displayLoginPraticien();
|
||||
} else {
|
||||
alert("Erreur lors de l'inscription");
|
||||
}
|
||||
}, data);
|
||||
});
|
||||
}
|
||||
else {
|
||||
displayHome("Vous êtes déjà connecté");
|
||||
}
|
||||
}
|
||||
|
||||
function displaySignUpUser() {
|
||||
if (sessionStorage.getItem("token") === null) {
|
||||
let container = document.getElementById("content");
|
||||
container.innerHTML = "";
|
||||
container.className = 'd-flex flex-column justify-content-center text-center w-100 signup-ui';
|
||||
container.innerHTML = `
|
||||
<div class="h-100 d-flex flex-column gap-0 justify-content-center text-center w-50 mx-25" style="margin-top: -15%;">
|
||||
<div class="p-3 m-0 border-0 bd-example border-0" id="signup-sign-part">
|
||||
<div class="text-center align-content-center">
|
||||
<h5 class="text-center fw-bold">Inscription sur Doct'ISEN</h5>
|
||||
<form class="px-4 py-3">
|
||||
<div class="mb-3">
|
||||
<label for="user-signup-name" class="form-label">Nom</label>
|
||||
<input type="text" class="form-control" id="user-signup-name" placeholder="Nom" name="name">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="user-signup-surname" class="form-label">Prénom</label>
|
||||
<input type="text" class="form-control" id="user-signup-surname" placeholder="Prénom" name="surname">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="user-signup-mail" class="form-label">Adresse mail</label>
|
||||
<input type="email" class="form-control" id="user-signup-mail" placeholder="email@example.com" name="mail">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="user-signup-mail-confirm" class="form-label">Confirmer adresse mail</label>
|
||||
<input type="email" class="form-control" id="user-signup-mail-confirm" placeholder="email@example.com" name="mail-confirm">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="user-signup-password" class="form-label">Mot de passe</label>
|
||||
<input type="password" class="form-control" id="user-signup-password" placeholder="********" name="password">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="user-signup-password-confirm" class="form-label">Confirmer mot de passe</label>
|
||||
<input type="password" class="form-control" id="user-signup-password-confirm" placeholder="********" name="password-confirm">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="user-signup-phone" class="form-label">Numéro de téléphone</label>
|
||||
<input type="tel" class="form-control" id="user-signup-phone" placeholder="06********" name="phone">
|
||||
</div>
|
||||
<div class="text-center justify-content-center">
|
||||
<button type="submit" class="btn btn-danger logButton" id="user-signup-button">S'inscrire</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="p-3 m-0 border-0 bd-example m-0 border-0 text-center justify-content-center mt-5" id="signup-part">
|
||||
<div class="text-center align-content-center">
|
||||
<h5 class="fw-bold">Déjà inscrit ?</h5>
|
||||
<a id="login-user2">
|
||||
<button class="btn btn-danger logButton">Se connecter</button>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>`;
|
||||
document.getElementById("login-user2").addEventListener("click", function (event) {
|
||||
displayLoginUser();
|
||||
});
|
||||
document.getElementById("user-signup-button").addEventListener("click", function (event) {
|
||||
event.preventDefault();
|
||||
let name = document.getElementById("user-signup-name").value;
|
||||
let surname = document.getElementById("user-signup-surname").value;
|
||||
let mail = document.getElementById("user-signup-mail").value;
|
||||
let mailConfirm = document.getElementById("user-signup-mail-confirm").value;
|
||||
let password = document.getElementById("user-signup-password").value;
|
||||
let passwordConfirm = document.getElementById("user-signup-password-confirm").value;
|
||||
let phone = document.getElementById("user-signup-phone").value;
|
||||
if (mail !== mailConfirm) {
|
||||
alert("Les adresses mail ne correspondent pas");
|
||||
return;
|
||||
}
|
||||
if (password !== passwordConfirm) {
|
||||
alert("Les mots de passe ne correspondent pas");
|
||||
return;
|
||||
}
|
||||
let data = "name=" + name + "&surname=" + surname + "&mail=" + mail + "&password=" + password + "&phone=" + phone;
|
||||
ajaxRequest('PUT', "src/API/requests.php/api/signup/patient", function (data) {
|
||||
if (data.success) {
|
||||
displayLoginUser();
|
||||
} else {
|
||||
alert("Erreur lors de l'inscription");
|
||||
}
|
||||
}, data);
|
||||
});
|
||||
}
|
||||
else {
|
||||
displayHome("Vous êtes déjà connecté");
|
||||
}
|
||||
}
|
||||
|
||||
function disconnect() {
|
||||
sessionStorage.removeItem("token");
|
||||
displayHome("Vous êtes déconnecté");
|
||||
}
|
||||
|
||||
function attachSearchEventListener() {
|
||||
try{
|
||||
document.getElementById("recherche").addEventListener("click", function (event) {
|
||||
performSearch(event);
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
//Do nothing
|
||||
//console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
function attachRDVEventListener() {
|
||||
let buttons = document.querySelectorAll("button[id^='m-id-']");
|
||||
buttons.forEach(function (button) {
|
||||
button.addEventListener("click", function (event) {
|
||||
let id = event.target.id.split("-")[2]
|
||||
let today = new Date();
|
||||
let date = today.getFullYear() + "-" + (today.getMonth() + 1).toString().padStart(2, "0") + "-" + today.getDate().toString().padStart(2, "0");
|
||||
ajaxRequest('GET', "src/API/requests.php/api/rdv-date?date=" + date + "&id=" + id, function (data) {
|
||||
displayCalendar(data);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function attachPrendreRDVEventListener() {
|
||||
let buttons = document.querySelectorAll("button[id^='rdv-id-']");
|
||||
buttons.forEach(function (button) {
|
||||
button.addEventListener("click", function (event) {
|
||||
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);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function attachLoginUserDisplayEventListener() {
|
||||
try {
|
||||
document.getElementById("login-user").addEventListener("click", function (event) {
|
||||
displayLoginUser();
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
//Do nothing
|
||||
//console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
function attachLoginPraticienDisplayEventListener() {
|
||||
try {
|
||||
document.getElementById("login-praticien").addEventListener("click", function (event) {
|
||||
displayLoginPraticien();
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
//Do nothing
|
||||
//console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
function attachReturnHomeEventListener() {
|
||||
try {
|
||||
document.getElementById("home").addEventListener("click", function (event) {
|
||||
|
||||
473
src/js/AJAX/login.js
Normal file
473
src/js/AJAX/login.js
Normal file
@@ -0,0 +1,473 @@
|
||||
import {TokenDecode} from "./lib";
|
||||
|
||||
console.log("login.js loaded");
|
||||
import {attachSearchEventListener, removeSearchTopBar} from "./search.js";
|
||||
|
||||
function displayLoginUser() {
|
||||
if (sessionStorage.getItem("token") === null) {
|
||||
let container = document.getElementById("content");
|
||||
container.innerHTML = "";
|
||||
container.className = 'd-flex flex-column justify-content-center text-center w-100 login-ui';
|
||||
container.innerHTML = `
|
||||
<div class="h-100 d-flex flex-column gap-0 justify-content-center text-center w-50 mx-25">
|
||||
<div class="p-3 m-0 border-0 bd-example m-0 border-0" id="login-part">
|
||||
<div class="text-center align-content-center">
|
||||
<h5 class="text-center fw-bold">J'ai déjà un compte Doct'ISEN</h5>
|
||||
<form class="px-4 py-3">
|
||||
<div class="mb-3">
|
||||
<label for="user-login-mail" class="form-label">Adresse mail</label>
|
||||
<input type="email" class="form-control" id="user-login-mail" placeholder="email@example.com" name="mail">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="user-login-password" class="form-label">Mot de passe</label>
|
||||
<input type="password" class="form-control" id="user-login-password" placeholder="********" name="password">
|
||||
</div>
|
||||
<div class="text-center justify-content-center">
|
||||
<button type="submit" class="btn btn-danger logButton" id="user-login-button">Se connecter</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="p-3 m-0 border-0 bd-example m-0 border-0 text-center justify-content-center mt-5" id="signup-part">
|
||||
<div class="text-center align-content-center">
|
||||
<h5 class="fw-bold">Nouveau sur Doct'ISEN?</h5>
|
||||
<a id="signup-user">
|
||||
<button class="btn btn-danger logButton">S'inscrire</button>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>`;
|
||||
document.getElementById("user-login-button").addEventListener("click", function (event) {
|
||||
event.preventDefault();
|
||||
let mail = document.getElementById("user-login-mail").value;
|
||||
let password = document.getElementById("user-login-password").value;
|
||||
let data = "mail=" + mail + "&password=" + password;
|
||||
ajaxRequest('POST', "src/API/requests.php/api/login/patient", function (data) {
|
||||
if (data.message === "Login success") {
|
||||
sessionStorage.setItem("token", data.token);
|
||||
displayHome("Vous êtes connecté");
|
||||
} else {
|
||||
alert("Erreur lors de la connexion");
|
||||
}
|
||||
}, data);
|
||||
});
|
||||
document.getElementById("signup-user").addEventListener("click", function (event) {
|
||||
displaySignUpUser();
|
||||
});
|
||||
}
|
||||
else {
|
||||
displayHome("Vous êtes déjà connecté");
|
||||
}
|
||||
}
|
||||
|
||||
function displayLoginPraticien() {
|
||||
let container = document.getElementById("content");
|
||||
if (sessionStorage.getItem("token") === null) {
|
||||
container.innerHTML = "";
|
||||
container.className = 'd-flex flex-column justify-content-center text-center w-100 login-ui';
|
||||
container.innerHTML = `
|
||||
<div class="h-100 d-flex flex-column gap-0 justify-content-center text-center w-50 mx-25">
|
||||
<div class="p-3 m-0 border-0 bd-example m-0 border-0" id="login-part">
|
||||
<div class="text-center align-content-center">
|
||||
<h5 class="text-center fw-bold">J'ai déjà un compte praticien Doct'ISEN</h5>
|
||||
<form class="px-4 py-3">
|
||||
<div class="mb-3">
|
||||
<label for="praticien-login-mail" class="form-label">Adresse mail</label>
|
||||
<input type="email" class="form-control" id="praticien-login-mail" placeholder="email@example.com" name="mail">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="praticien-login-password" class="form-label">Mot de passe</label>
|
||||
<input type="password" class="form-control" id="praticien-login-password" placeholder="********" name="password">
|
||||
</div>
|
||||
<div class="text-center justify-content-center">
|
||||
<button type="submit" class="btn btn-danger logButton" id="praticien-login-button">Se connecter</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="p-3 m-0 border-0 bd-example m-0 border-0 text-center justify-content-center mt-5" id="signup-part">
|
||||
<div class="text-center align-content-center">
|
||||
<h5 class="fw-bold">Nouveau praticien sur Doct'ISEN?</h5>
|
||||
<a id="signup-praticien">
|
||||
<button class="btn btn-danger logButton">S'inscrire</button>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>`;
|
||||
document.getElementById("praticien-login-button").addEventListener("click", function (event) {
|
||||
event.preventDefault();
|
||||
let mail = document.getElementById("praticien-login-mail").value;
|
||||
let password = document.getElementById("praticien-login-password").value;
|
||||
let data = "mail=" + mail + "&password=" + password;
|
||||
ajaxRequest('POST', "src/API/requests.php/api/login/medecin", function (data) {
|
||||
if (data.message === "Login success") {
|
||||
sessionStorage.setItem("token", data.token)
|
||||
displayHome("Vous êtes connecté");
|
||||
} else {
|
||||
alert("Erreur lors de la connexion");
|
||||
}
|
||||
}, data);
|
||||
});
|
||||
document.getElementById("signup-praticien").addEventListener("click", function (event) {
|
||||
displaySignUpPraticien();
|
||||
});
|
||||
}
|
||||
else {
|
||||
displayHome("Vous êtes déjà connecté");
|
||||
}
|
||||
}
|
||||
|
||||
function displaySignUpPraticien() {
|
||||
if (sessionStorage.getItem("token") === null) {
|
||||
let container = document.getElementById("content");
|
||||
container.innerHTML = "";
|
||||
container.className = 'd-flex flex-column justify-content-center text-center w-100 signup-ui-praticien';
|
||||
container.innerHTML = `
|
||||
<div class="h-100 d-flex flex-column gap-0 justify-content-center text-center w-50 mx-25" style="margin-top: -15%;">
|
||||
<div class="p-3 m-0 border-0 bd-example border-0" id="signup-sign-part">
|
||||
<div class="text-center align-content-center">
|
||||
<h5 class="text-center fw-bold">Inscription praticien sur Doct'ISEN</h5>
|
||||
<form class="px-4 py-3">
|
||||
<div class="mb-3">
|
||||
<label for="praticien-signup-name" class="form-label">Nom</label>
|
||||
<input type="text" class="form-control" id="praticien-signup-name" placeholder="Nom" name="name">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="praticien-signup-surname" class="form-label">Prénom</label>
|
||||
<input type="text" class="form-control" id="praticien-signup-surname" placeholder="Prénom" name="surname">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="praticien-signup-mail" class="form-label">Adresse mail</label>
|
||||
<input type="email" class="form-control" id="praticien-signup-mail" placeholder="example@example.com" name="mail">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="praticien-signup-mail-confirm" class="form-label">Confirmer adresse mail</label>
|
||||
<input type="email" class="form-control" id="praticien-signup-mail-confirm" placeholder="example@example.com" name="mail-confirm">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="praticien-signup-password" class="form-label">Mot de passe</label>
|
||||
<input type="password" class="form-control" id="praticien-signup-password" placeholder="********" name="password">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="praticien-signup-password-confirm" class="form-label">Confirmer mot de passe</label>
|
||||
<input type="password" class="form-control" id="praticien-signup-password-confirm" placeholder="********" name="password-confirm">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="praticien-signup-phone" class="form-label">Numéro de téléphone</label>
|
||||
<input type="tel" class="form-control" id="praticien-signup-phone" placeholder="06********" name="phone">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="praticien-signup-specialty" class="form-label">Spécialité</label>
|
||||
<input type="text" class="form-control" id="praticien-signup-specialty" placeholder="Spécialité" name="specialty">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="praticien-signup-postal" class="form-label">Code postal</label>
|
||||
<input type="text" class="form-control" id="praticien-signup-postal" placeholder="Code postal" name="postal">
|
||||
</div>
|
||||
<div class="text-center justify-content-center">
|
||||
<button type="submit" class="btn btn-danger logButton" id="praticien-signup-button">S'inscrire</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="p-3 m-0 border-0 bd-example m-0 border-0 text-center justify-content-center mt-5" id="signup-part">
|
||||
<div class="text-center align-content-center">
|
||||
<h5 class="fw-bold">Déjà inscrit en tant que praticien ?</h5>
|
||||
<a id="login-praticien2">
|
||||
<button class="btn btn-danger logButton">Se connecter</button>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>`;
|
||||
document.getElementById("login-praticien2").addEventListener("click", function (event) {
|
||||
displayLoginPraticien();
|
||||
});
|
||||
document.getElementById("praticien-signup-button").addEventListener("click", function (event) {
|
||||
event.preventDefault();
|
||||
let name = document.getElementById("praticien-signup-name").value;
|
||||
let surname = document.getElementById("praticien-signup-surname").value;
|
||||
let mail = document.getElementById("praticien-signup-mail").value;
|
||||
let mailConfirm = document.getElementById("praticien-signup-mail-confirm").value;
|
||||
let password = document.getElementById("praticien-signup-password").value;
|
||||
let passwordConfirm = document.getElementById("praticien-signup-password-confirm").value;
|
||||
let phone = document.getElementById("praticien-signup-phone").value;
|
||||
let specialty = document.getElementById("praticien-signup-specialty").value;
|
||||
let postal = document.getElementById("praticien-signup-postal").value;
|
||||
if (mail !== mailConfirm) {
|
||||
alert("Les adresses mail ne correspondent pas");
|
||||
return;
|
||||
}
|
||||
if (password !== passwordConfirm) {
|
||||
alert("Les mots de passe ne correspondent pas");
|
||||
return;
|
||||
}
|
||||
let data = "name=" + name + "&surname=" + surname + "&mail=" + mail + "&password=" + password + "&specialite=" + specialty + "&phone=" + phone + "&postal=" + postal;
|
||||
ajaxRequest('PUT', "src/API/requests.php/api/signup/medecin", function (data) {
|
||||
if (data.success) {
|
||||
displayLoginPraticien();
|
||||
} else {
|
||||
alert("Erreur lors de l'inscription");
|
||||
}
|
||||
}, data);
|
||||
});
|
||||
}
|
||||
else {
|
||||
displayHome("Vous êtes déjà connecté");
|
||||
}
|
||||
}
|
||||
|
||||
function displaySignUpUser() {
|
||||
if (sessionStorage.getItem("token") === null) {
|
||||
let container = document.getElementById("content");
|
||||
container.innerHTML = "";
|
||||
container.className = 'd-flex flex-column justify-content-center text-center w-100 signup-ui';
|
||||
container.innerHTML = `
|
||||
<div class="h-100 d-flex flex-column gap-0 justify-content-center text-center w-50 mx-25" style="margin-top: -15%;">
|
||||
<div class="p-3 m-0 border-0 bd-example border-0" id="signup-sign-part">
|
||||
<div class="text-center align-content-center">
|
||||
<h5 class="text-center fw-bold">Inscription sur Doct'ISEN</h5>
|
||||
<form class="px-4 py-3">
|
||||
<div class="mb-3">
|
||||
<label for="user-signup-name" class="form-label">Nom</label>
|
||||
<input type="text" class="form-control" id="user-signup-name" placeholder="Nom" name="name">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="user-signup-surname" class="form-label">Prénom</label>
|
||||
<input type="text" class="form-control" id="user-signup-surname" placeholder="Prénom" name="surname">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="user-signup-mail" class="form-label">Adresse mail</label>
|
||||
<input type="email" class="form-control" id="user-signup-mail" placeholder="email@example.com" name="mail">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="user-signup-mail-confirm" class="form-label">Confirmer adresse mail</label>
|
||||
<input type="email" class="form-control" id="user-signup-mail-confirm" placeholder="email@example.com" name="mail-confirm">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="user-signup-password" class="form-label">Mot de passe</label>
|
||||
<input type="password" class="form-control" id="user-signup-password" placeholder="********" name="password">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="user-signup-password-confirm" class="form-label">Confirmer mot de passe</label>
|
||||
<input type="password" class="form-control" id="user-signup-password-confirm" placeholder="********" name="password-confirm">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="user-signup-phone" class="form-label">Numéro de téléphone</label>
|
||||
<input type="tel" class="form-control" id="user-signup-phone" placeholder="06********" name="phone">
|
||||
</div>
|
||||
<div class="text-center justify-content-center">
|
||||
<button type="submit" class="btn btn-danger logButton" id="user-signup-button">S'inscrire</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="p-3 m-0 border-0 bd-example m-0 border-0 text-center justify-content-center mt-5" id="signup-part">
|
||||
<div class="text-center align-content-center">
|
||||
<h5 class="fw-bold">Déjà inscrit ?</h5>
|
||||
<a id="login-user2">
|
||||
<button class="btn btn-danger logButton">Se connecter</button>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>`;
|
||||
document.getElementById("login-user2").addEventListener("click", function (event) {
|
||||
displayLoginUser();
|
||||
});
|
||||
document.getElementById("user-signup-button").addEventListener("click", function (event) {
|
||||
event.preventDefault();
|
||||
let name = document.getElementById("user-signup-name").value;
|
||||
let surname = document.getElementById("user-signup-surname").value;
|
||||
let mail = document.getElementById("user-signup-mail").value;
|
||||
let mailConfirm = document.getElementById("user-signup-mail-confirm").value;
|
||||
let password = document.getElementById("user-signup-password").value;
|
||||
let passwordConfirm = document.getElementById("user-signup-password-confirm").value;
|
||||
let phone = document.getElementById("user-signup-phone").value;
|
||||
if (mail !== mailConfirm) {
|
||||
alert("Les adresses mail ne correspondent pas");
|
||||
return;
|
||||
}
|
||||
if (password !== passwordConfirm) {
|
||||
alert("Les mots de passe ne correspondent pas");
|
||||
return;
|
||||
}
|
||||
let data = "name=" + name + "&surname=" + surname + "&mail=" + mail + "&password=" + password + "&phone=" + phone;
|
||||
ajaxRequest('PUT', "src/API/requests.php/api/signup/patient", function (data) {
|
||||
if (data.success) {
|
||||
displayLoginUser();
|
||||
} else {
|
||||
alert("Erreur lors de l'inscription");
|
||||
}
|
||||
}, data);
|
||||
});
|
||||
}
|
||||
else {
|
||||
displayHome("Vous êtes déjà connecté");
|
||||
}
|
||||
}
|
||||
|
||||
function disconnect() {
|
||||
sessionStorage.removeItem("token");
|
||||
displayHome("Vous êtes déconnecté");
|
||||
}
|
||||
|
||||
function attachLoginUserDisplayEventListener() {
|
||||
try {
|
||||
document.getElementById("login-user").addEventListener("click", function (event) {
|
||||
displayLoginUser();
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
//Do nothing
|
||||
//console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
function attachLoginPraticienDisplayEventListener() {
|
||||
try {
|
||||
document.getElementById("login-praticien").addEventListener("click", function (event) {
|
||||
displayLoginPraticien();
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
//Do nothing
|
||||
//console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
function displayHomeTopBar() {
|
||||
let topbar = document.getElementById("topbar");
|
||||
topbar.innerHTML = "";
|
||||
if(sessionStorage.getItem("token") === null) {
|
||||
topbar.innerHTML = `
|
||||
<div id="topInfo">
|
||||
<a id="home">
|
||||
<p id="DoctISEN" class="top-0 position-fixed">
|
||||
Doct'ISEN
|
||||
</p>
|
||||
</a>
|
||||
<div class="d-flex position-fixed end-0 flex-row align-items-center gap-3 mt-2 top-0">
|
||||
<button type="button" class="btn btn-danger" style="top: 0.4375em;" id="login-praticien">Vous êtes praticien ?</button> <button type="button" class="btn btn-danger" style="top: 0.4375em;" id="login-user">Se connecter</button><p> </p>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
attachLoginUserDisplayEventListener();
|
||||
attachLoginPraticienDisplayEventListener();
|
||||
}
|
||||
else {
|
||||
let token = sessionStorage.getItem("token");
|
||||
let user = TokenDecode(token);
|
||||
const mailMD5 = CryptoJS.MD5(user.mail);
|
||||
if(user.type === "patient") {
|
||||
topbar.innerHTML = `
|
||||
<div id="topInfo">
|
||||
<a id="home">
|
||||
<p id="DoctISEN" class="top-0 position-fixed">
|
||||
Doct'ISEN
|
||||
</p>
|
||||
</a>
|
||||
<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>
|
||||
<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 id="home">
|
||||
<p id="DoctISEN" class="top-0 position-fixed">
|
||||
Doct'ISEN
|
||||
</p>
|
||||
</a>
|
||||
<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>
|
||||
<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 = `
|
||||
<div id="topInfo">
|
||||
<p class="alert-danger">Erreur</p>
|
||||
</div>`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function displayAlert(text) {
|
||||
let alert = document.getElementById("Alert");
|
||||
alert.innerHTML = "";
|
||||
alert.innerHTML = `
|
||||
<div class="alert alert-success" role="alert">
|
||||
${text}
|
||||
</div>`;
|
||||
setTimeout(clearAlert, 5000);
|
||||
}
|
||||
|
||||
function clearAlert() {
|
||||
let alert = document.getElementById("Alert");
|
||||
alert.innerHTML = "";
|
||||
}
|
||||
|
||||
function displayHome(text) {
|
||||
removeSearchTopBar();
|
||||
displayHomeTopBar();
|
||||
let container = document.getElementById("content");
|
||||
container.classList = "";
|
||||
container.innerHTML = "";
|
||||
container.innerHTML = `
|
||||
<div style="background-color: red; height: 50vh;">
|
||||
<div class="d-flex justify-content-center align-items-center" style="background-color: red;" id="Alert"></div>
|
||||
<img src="src/img/img_index.png" alt="img_index" id="img_index">
|
||||
<div id="rdv">
|
||||
<p class="text-white fw-bold fs-3">Trouvez un rendez vous avec un medecin</p>
|
||||
<form action="" class="input-group" method="post">
|
||||
<input type="text" aria-label="First name" class="form-control" id="nom" name="nom" placeholder="Nom, spécialité">
|
||||
<input type="text" aria-label="Last name" class="form-control" id="postal" name="postal" placeholder="Où ?">
|
||||
<button class="btn btn-success" type="submit" id="recherche">Rechercher</button>
|
||||
</form>
|
||||
</div>
|
||||
<div class="d-flex justify-content-center gap-5 w-100" id="cardPos">
|
||||
<div class="card" style="width: 18rem;">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Information</h5>
|
||||
<h6 class="card-subtitle mb-2 text-body-secondary">Ligue contre le cancer</h6>
|
||||
<p class="card-text">Mois sans tabac: c’est le moment d’arrêter !</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card" style="width: 18rem;">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Information</h5>
|
||||
<h6 class="card-subtitle mb-2 text-body-secondary">Pharmacie Sanchez</h6>
|
||||
<p class="card-text">Le rôle du phramacien évolue: Venez nous voir.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card" style="width: 18rem;">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Information</h5>
|
||||
<h6 class="card-subtitle mb-2 text-body-secondary">Doct’ISEN</h6>
|
||||
<p class="card-text">Un empechement: Prevenez votre soignant.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<footer class="fixed-bottom m-2 mx-4">
|
||||
<p>Recherche de praticiens</p>
|
||||
<p>Doct’ISEN, 33 QUATER Av. du Champ de Manœuvre, 44470 Carquefou</p>
|
||||
<p class="text-secondary">Conditions générales d'utilisation • Conditions d'utilisation du site Doct'ISEN • Politique relative à la protection des données personnelles • Politique en matière de cookies • Gestion des cookies et consentement • Règles de référencement • Mentions légales</p>
|
||||
<p class="text-secondary">Annuaire des médecins du CNOM • Annuaire des chirurgiens-dentistes de l'ONCD • Ordre National des Médecins • Ordre National des Chirurgiens-Dentistes</p>
|
||||
</footer>`;
|
||||
attachSearchEventListener();
|
||||
attachLoginUserDisplayEventListener();
|
||||
if(text !== ""){
|
||||
displayAlert(text);
|
||||
}
|
||||
}
|
||||
|
||||
export {attachLoginUserDisplayEventListener, attachLoginPraticienDisplayEventListener, disconnect, displayHome, displayHomeTopBar};
|
||||
118
src/js/AJAX/search.js
Normal file
118
src/js/AJAX/search.js
Normal file
@@ -0,0 +1,118 @@
|
||||
console.log("search.js loaded");
|
||||
import {attachRDVEventListener} from "./take-rdv.js";
|
||||
|
||||
function displaySearchResults(data) {
|
||||
let container = document.getElementById("content");
|
||||
container.innerHTML = "";
|
||||
let mainDiv = document.createElement("div");
|
||||
mainDiv.classList.add("d-flex", "flex-row", "flex-wrap", "mx-5", "gap-5", "justify-content-center");
|
||||
let count = 0;
|
||||
data.forEach(function(element) {
|
||||
count++;
|
||||
let card = document.createElement("div");
|
||||
card.classList.add("card", "w-25");
|
||||
card.innerHTML = `
|
||||
<div class="row g-0">
|
||||
<div class="col-md-4">
|
||||
<img src="src/img/Medecin_test.jpeg" alt="doctor" class="img-fluid rounded-start" width="300" height="300">
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">${element.m_surname} ${element.m_name}</h5>
|
||||
<h6 class="card-subtitle mb-2 text-body-secondary">${element.m_specialty}</h6>
|
||||
<p class="card-text">Code Postal: ${element.m_postal}</p>
|
||||
<button type="submit" class="btn btn-danger" id="m-id-${element.m_id}">Prendre rendez-vous</button>
|
||||
</div>
|
||||
</div>`;
|
||||
mainDiv.appendChild(card);
|
||||
});
|
||||
container.appendChild(mainDiv);
|
||||
if(count === 0) {
|
||||
mainDiv.innerHTML = "<h1>Aucun résultats</h1>";
|
||||
}
|
||||
else {
|
||||
let resultText = document.createElement("h1");
|
||||
resultText.textContent = count + " résultats";
|
||||
container.insertBefore(resultText, mainDiv);
|
||||
attachRDVEventListener();
|
||||
}
|
||||
}
|
||||
|
||||
function displaySearchTopBar(){
|
||||
let topbar = document.getElementById("topbar");
|
||||
let searchbar = document.getElementById("searchbar");
|
||||
|
||||
let form = topbar.querySelector("form");
|
||||
if (form) {
|
||||
topbar.removeChild(form);
|
||||
}
|
||||
|
||||
searchbar.innerHTML = `
|
||||
<form class="input-group p-5" onsubmit="performSearch(event)" method="post">
|
||||
<input type="text" aria-label="First name" class="form-control" id="nom" name="nom" placeholder="Nom, spécialité">
|
||||
<input type="text" aria-label="Last name" class="form-control" id="postal" name="postal" placeholder="Où ?">
|
||||
<button class="btn btn-danger" type="submit" id="recherche">Rechercher</button>
|
||||
</form>`;
|
||||
|
||||
attachSearchEventListener();
|
||||
}
|
||||
|
||||
function removeSearchTopBar(){
|
||||
let topbar = document.getElementById("topbar");
|
||||
topbar.innerHTML = "";
|
||||
topbar.innerHTML = `
|
||||
<div id="topInfo">
|
||||
<a id="home">
|
||||
<p id="DoctISEN" class="top-0 position-fixed">
|
||||
Doct'ISEN
|
||||
</p>
|
||||
</a>
|
||||
<div class="d-flex position-fixed end-0 flex-row align-items-center gap-3 mt-2 top-0">
|
||||
<?php
|
||||
loginUI($pdo);
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<div id="searchbar"></div>`;
|
||||
}
|
||||
|
||||
function performSearch(event) {
|
||||
event.preventDefault();
|
||||
let type = document.getElementById("nom").value;
|
||||
let postal = document.getElementById("postal").value;
|
||||
if (postal === "") {
|
||||
if (type === "") {
|
||||
alert("Veuillez remplir au moins un champ");
|
||||
return;
|
||||
} else {
|
||||
ajaxRequest('GET', "src/API/requests.php/api/search-type?type=" + type, function (data) {
|
||||
displaySearchResults(data);
|
||||
displaySearchTopBar();
|
||||
})
|
||||
}
|
||||
} else if (type === "") {
|
||||
ajaxRequest('GET', "src/API/requests.php/api/search-postal?postal=" + postal, function (data) {
|
||||
displaySearchResults(data);
|
||||
displaySearchTopBar();
|
||||
});
|
||||
} else {
|
||||
ajaxRequest('GET', "src/API/requests.php/api/search?type=" + type + "&postal=" + postal, function (data) {
|
||||
displaySearchResults(data);
|
||||
displaySearchTopBar();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function attachSearchEventListener() {
|
||||
try{
|
||||
document.getElementById("recherche").addEventListener("click", function (event) {
|
||||
performSearch(event);
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
//Do nothing
|
||||
//console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
export {removeSearchTopBar, attachSearchEventListener};
|
||||
150
src/js/AJAX/take-rdv.js
Normal file
150
src/js/AJAX/take-rdv.js
Normal file
@@ -0,0 +1,150 @@
|
||||
console.log("take-rdv.js loaded");
|
||||
import {displayHome} from "./login.js";
|
||||
|
||||
function displayRDVForDate(data) {
|
||||
let container = document.getElementById("rdv-list");
|
||||
container.innerHTML = "";
|
||||
let count = 0;
|
||||
data.forEach(function(element) {
|
||||
try{
|
||||
let card = document.createElement("div");
|
||||
card.classList.add("card");
|
||||
element.rdv_time = element.rdv_time.slice(0, 5);
|
||||
card.innerHTML = `
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">${element.rdv_time}</h5>
|
||||
<p class="card-text">Adresse: ${element.l_adress} <br>
|
||||
Ville: ${element.l_city} ${element.l_postal}</p>
|
||||
<button type="submit" class="btn btn-danger" id="rdv-id-${element.rdv_id}">Prendre ce rendez-vous</button>
|
||||
</div>`;
|
||||
container.appendChild(card);
|
||||
count++;
|
||||
} catch (e) {
|
||||
//Do nothing
|
||||
//console.error(e);
|
||||
}
|
||||
});
|
||||
if(count === 0) {
|
||||
container.innerHTML = "<h1>Aucun rendez-vous</h1>";
|
||||
}
|
||||
else {
|
||||
let resultText = document.createElement("h1");
|
||||
resultText.textContent = count + " rendez-vous";
|
||||
container.insertBefore(resultText, container.firstChild);
|
||||
attachPrendreRDVEventListener();
|
||||
}
|
||||
}
|
||||
|
||||
function displayCalendar(data) {
|
||||
let container = document.getElementById("content");
|
||||
container.innerHTML = "";
|
||||
let mainDiv = document.createElement("div");
|
||||
mainDiv.classList.add("row");
|
||||
|
||||
// Colonne de gauche
|
||||
let leftCol = document.createElement("div");
|
||||
leftCol.classList.add("col", "h-100", "border-dark", "border-3", "justify-content-center", "text-center", "ms-3");
|
||||
let leftDiv = document.createElement("div");
|
||||
leftDiv.classList.add("d-flex", "flex-column", "justify-content-center", "gap-6");
|
||||
|
||||
// Calendrier de sélection de date
|
||||
let form = document.createElement("form");
|
||||
form.classList.add("mt-3");
|
||||
form.id = "date-selection-form";
|
||||
let label = document.createElement("label");
|
||||
label.setAttribute("for", "date");
|
||||
label.textContent = "Choisissez une date :";
|
||||
form.appendChild(label);
|
||||
let input = document.createElement("input");
|
||||
input.setAttribute("type", "date");
|
||||
input.setAttribute("name", "start");
|
||||
input.setAttribute("id", "date");
|
||||
input.classList.add("mt-2", "form-control");
|
||||
form.appendChild(input);
|
||||
let submit = document.createElement("input");
|
||||
submit.setAttribute("type", "submit");
|
||||
submit.setAttribute("value", "Valider");
|
||||
submit.classList.add("mt-2", "btn", "btn-outline-danger");
|
||||
form.appendChild(submit);
|
||||
leftDiv.appendChild(form);
|
||||
|
||||
// Carte du médecin
|
||||
let medecinCard = document.createElement("div");
|
||||
medecinCard.classList.add("card", "mx-auto", "d-flex", "flex-row");
|
||||
medecinCard.innerHTML = `
|
||||
<div class="row g-0">
|
||||
<div class="col-md-4">
|
||||
<img src="src/img/Medecin_test.jpeg" class="img-fluid rounded-start" alt="doctor" width="300" height="300">
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">${data[0].m_surname} ${data[0].m_name}</h5>
|
||||
<h6 class="card-subtitle mb-2 text-body-secondary">${data[0].m_specialty}</h6>
|
||||
</div>
|
||||
</div>
|
||||
</div>`;
|
||||
leftDiv.appendChild(medecinCard);
|
||||
|
||||
leftCol.appendChild(leftDiv);
|
||||
mainDiv.appendChild(leftCol);
|
||||
|
||||
// Colonne de droite
|
||||
let rightCol = document.createElement("div");
|
||||
rightCol.classList.add("col-8", "h-100", "border-start", "border-dark", "border-3", "me-3");
|
||||
|
||||
// Liste des rendez-vous
|
||||
let rdvList = document.createElement("div");
|
||||
rdvList.classList.add("mt-3", "d-flex", "flex-column", "gap-3");
|
||||
rdvList.id = "rdv-list";
|
||||
rightCol.appendChild(rdvList);
|
||||
|
||||
mainDiv.appendChild(rightCol);
|
||||
container.appendChild(mainDiv);
|
||||
displayRDVForDate(data);
|
||||
document.getElementById("date-selection-form").addEventListener("submit", function(event) {
|
||||
event.preventDefault();
|
||||
let date = document.getElementById("date").value;
|
||||
let id = data[0].m_id; // Assuming 'data' is accessible in this scope and contains the doctor's details
|
||||
ajaxRequest('GET', "src/API/requests.php/api/rdv-date?date=" + date + "&id=" + id, function (data) {
|
||||
displayRDVForDate(data);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function attachRDVEventListener() {
|
||||
let buttons = document.querySelectorAll("button[id^='m-id-']");
|
||||
buttons.forEach(function (button) {
|
||||
button.addEventListener("click", function (event) {
|
||||
let id = event.target.id.split("-")[2]
|
||||
let today = new Date();
|
||||
let date = today.getFullYear() + "-" + (today.getMonth() + 1).toString().padStart(2, "0") + "-" + today.getDate().toString().padStart(2, "0");
|
||||
ajaxRequest('GET', "src/API/requests.php/api/rdv-date?date=" + date + "&id=" + id, function (data) {
|
||||
displayCalendar(data);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function attachPrendreRDVEventListener() {
|
||||
let buttons = document.querySelectorAll("button[id^='rdv-id-']");
|
||||
buttons.forEach(function (button) {
|
||||
button.addEventListener("click", function (event) {
|
||||
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);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export {attachRDVEventListener};
|
||||
Reference in New Issue
Block a user