1 ere phase complète
This commit is contained in:
0
resources/views/authentification.blade.php
Normal file
0
resources/views/authentification.blade.php
Normal file
@@ -17,6 +17,7 @@
|
||||
<th scope=\"col\">Nom du client</th>
|
||||
<th scope=\"col\">Adresse e-mail</th>
|
||||
<th scope=\"col\">Voir le client</th>
|
||||
<th scope=\"col\">Supprimer</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody> `;
|
||||
@@ -25,16 +26,103 @@
|
||||
table.innerHTML += `<tr>
|
||||
<td>${c.nom}</td>
|
||||
<td>${c.email}</td>
|
||||
<td><a href="{{ url('/clients/${c.id}') }}">le client ${c.id}<a></td>
|
||||
<td><a href="#" onclick="leClient(${c.id});">Informations</a></td>
|
||||
<td><a href="#" onclick="supprimer(${c.id});">supprimer</a></td>
|
||||
</tr>`;
|
||||
});
|
||||
list.innerHTML += "</tbody> </table>"
|
||||
list.innerHTML += "</tbody> </table> "
|
||||
|
||||
} catch (error) {
|
||||
console.error('Erreur :', error);
|
||||
list.innerHTML = '<li>Impossible de charger les clients</li>';
|
||||
}
|
||||
}
|
||||
|
||||
async function supprimer(id){
|
||||
try{
|
||||
await fetch(`http://192.168.56.56:8000/api/clients/${id}`, {
|
||||
method: 'DELETE'
|
||||
});
|
||||
await loadClients();
|
||||
}catch(err){
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
async function leClient(id) {
|
||||
try {
|
||||
const response = await fetch(`http://192.168.56.56:8000/api/clients/${id}`, {
|
||||
method: 'GET'
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error("Client introuvable");
|
||||
}
|
||||
|
||||
const client = await response.json();
|
||||
|
||||
// zone d'affichage
|
||||
const zone = document.getElementById("client-info");
|
||||
|
||||
// formulaire
|
||||
zone.innerHTML = `
|
||||
<h2>Modifier le client</h2>
|
||||
|
||||
<form onsubmit="updateClient(${client.id}); return false;">
|
||||
|
||||
<label>Nom :</label><br>
|
||||
<input type="text" id="edit-nom" value="${client.nom}" required><br><br>
|
||||
|
||||
<label>Prénom :</label><br>
|
||||
<input type="text" id="edit-prenom" value="${client.prenom}" required><br><br>
|
||||
|
||||
<label>Email :</label><br>
|
||||
<input type="email" id="edit-email" value="${client.email}" required><br><br>
|
||||
|
||||
<label>Numéro de téléphone :</label><br>
|
||||
<input type="text" id="edit-ntelephone" value="${client.ntelephone ?? ''}"><br><br>
|
||||
|
||||
<button type="submit">Mettre à jour</button>
|
||||
</form>
|
||||
`;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
document.getElementById("client-info").innerHTML =
|
||||
"<p>Erreur lors du chargement du client.</p>";
|
||||
}
|
||||
}
|
||||
|
||||
async function updateClient(id) {
|
||||
try {
|
||||
const nom = document.getElementById("edit-nom").value;
|
||||
const prenom = document.getElementById("edit-prenom").value;
|
||||
const email = document.getElementById("edit-email").value;
|
||||
const telephone = document.getElementById("edit-ntelephone").value;
|
||||
|
||||
const response = await fetch(`http://192.168.56.56:8000/api/clients/${id}`, {
|
||||
method: 'PUT',
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ nom, prenom, email, telephone })
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error("Erreur de mise à jour");
|
||||
}
|
||||
|
||||
alert("Client mis à jour !");
|
||||
loadClients();
|
||||
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
alert("Impossible de mettre à jour le client.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
loadClients();
|
||||
|
||||
|
||||
</script>
|
||||
@endsection
|
||||
<div id="client-info"></div>
|
||||
@endsection
|
||||
|
||||
|
||||
@@ -2,21 +2,30 @@
|
||||
@section('content')
|
||||
<link href="{{ asset('css/style.css') }}" rel="stylesheet">
|
||||
<h1>Création d'un nouveau client</h1>
|
||||
<form action="{{ url('ajout')}}" method="POST">
|
||||
<form class="form-clean" action="{{ url('/clients/ajout') }}" method="POST">
|
||||
@csrf
|
||||
<label for="nom">Nom:</label>
|
||||
<input type="text" name="nom" id="nom" required>
|
||||
<div class="field">
|
||||
<label for="nom">Nom</label>
|
||||
<input type="text" id="nom" name="nom" required>
|
||||
</div>
|
||||
|
||||
<label for="prenom">Prenom:</label>
|
||||
<input type="text" name="prenom" id="prenom" required>
|
||||
<div class="field">
|
||||
<label for="prenom">Prénom</label>
|
||||
<input type="text" id="prenom" name="prenom" required>
|
||||
</div>
|
||||
|
||||
<label for="email">E-mail:</label>
|
||||
<input type="text" name="email" id="email" required>
|
||||
<div class="field">
|
||||
<label for="email">E-mail</label>
|
||||
<input type="email" id="email" name="email" required>
|
||||
</div>
|
||||
|
||||
<label for="telephone">Numero de Telephone:</label>
|
||||
<input type="text" name="telephone" id="telephone">
|
||||
|
||||
<input type="submit" value="Soumettre">
|
||||
<div class="field">
|
||||
<label for="telephone">Téléphone</label>
|
||||
<input type="text" id="telephone" name="telephone">
|
||||
</div>
|
||||
|
||||
<button class="btn-submit" type="submit">Soumettre</button>
|
||||
</form>
|
||||
|
||||
|
||||
@endsection
|
||||
@@ -10,9 +10,6 @@
|
||||
<a href="{{ url('/') }}">Accueil</a>
|
||||
<a href="{{ url('/clients') }}">Liste des clients</a>
|
||||
<a href="{{ url('/ajoutClient') }}">Crée un client</a>
|
||||
<a href="{{ url('/clients') }}">Mise à jour complète d'un client</a>
|
||||
<a href="{{ url('/clients') }}">Mise à jour partielle d'un client</a>
|
||||
<a href="{{ url('/clients') }}">Supprimer un client</a>
|
||||
</nav>
|
||||
|
||||
|
||||
|
||||
5
resources/views/majClient.blade.php
Normal file
5
resources/views/majClient.blade.php
Normal file
@@ -0,0 +1,5 @@
|
||||
@extends('layout')
|
||||
@section('content')
|
||||
<link href="{{ asset('css/style.css') }}" rel="stylesheet">
|
||||
|
||||
@endsection
|
||||
Reference in New Issue
Block a user