Mise a jour des Modals

This commit is contained in:
Joshua 2024-12-06 11:27:16 +01:00
parent e6135b438c
commit a048381457
6 changed files with 105 additions and 14 deletions

View File

@ -36,8 +36,8 @@ security:
access_control:
# - { path: ^/, roles: ROLE_USER }
- { path: ^/logout, roles: IS_AUTHENTICATED }
- { path: ^/login, roles: PUBLIC_ACCESS }
- { path: ^/logout, roles: ROLE_USER }
- { path: ^/index, roles: [ROLE_ADMIN, ROLE_CUISINIER, ROLE_SERVEUR]}
- { path: ^/user, roles: ROLE_ADMIN }

View File

@ -0,0 +1,77 @@
document.querySelector('.btn-gestion-promotion').addEventListener('click', function(event) {
event.preventDefault();
document.getElementById('container_modal');
fetch('/reductions')
.then(response => {
if (!response.ok) {
throw new Error('Erreur de chargement de la section Promotions');
}
return response.text();
})
.then(html => {
// Insérer le HTML dans le conteneur et l'afficher
container_modal.innerHTML = html;
container_modal.style.display = 'block';
})
.catch(error => {
console.error('Erreur:', error);
});
});
function addPromotion (event) {
document.getElementById('container_modal');
fetch(`/reductions/new`)
.then(response => {
return response.text();
})
.then(html => {
// Insérer le HTML dans le conteneur et l'afficher
container_modal.innerHTML = html;
container_modal.style.display = 'block';
})
.catch(error => {
console.error('Erreur:', error);
});
}
function updatePromotion (event) {
document.getElementById('container_modal');
const reductionsIdString = event.getAttribute('data-id');
let reductionsId = parseInt(reductionsIdString);
fetch(`/reductions/${reductionsId}/edit`)
.then(response => {
return response.text();
})
.then(html => {
// Insérer le HTML dans le conteneur et l'afficher
container_modal.innerHTML = html;
container_modal.style.display = 'block';
})
.catch(error => {
console.error('Erreur:', error);
});
}
function deletePromotion (event) {
document.getElementById('container_modal');
const reductionsIdString = event.getAttribute('data-id');
let reductionsId = parseInt(reductionsIdString);
fetch(`/reductions/${reductionsId}`)
.then(response => {
return response.text();
})
.then(html => {
// Insérer le HTML dans le conteneur et l'afficher
container_modal.innerHTML = html;
container_modal.style.display = 'block';
})
.catch(error => {
console.error('Erreur:', error);
});
}

View File

@ -26,14 +26,17 @@ final class ReductionsController extends AbstractController
public function new(Request $request, EntityManagerInterface $entityManager): Response
{
$reduction = new Reductions();
$form = $this->createForm(ReductionsType::class, $reduction);
$form = $this->createForm(ReductionsType::class, $reduction, [
'action' => $this->generateUrl('app_reductions_new')
] );
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager->persist($reduction);
$entityManager->flush();
return $this->redirectToRoute('app_reductions_index', [], Response::HTTP_SEE_OTHER);
return $this->redirectToRoute('app_index', [], Response::HTTP_SEE_OTHER);
}
return $this->render('reductions/new.html.twig', [
@ -46,13 +49,15 @@ final class ReductionsController extends AbstractController
#[Route('/{id}/edit', name: 'app_reductions_edit', methods: ['GET', 'POST'])]
public function edit(Request $request, Reductions $reduction, EntityManagerInterface $entityManager): Response
{
$form = $this->createForm(ReductionsType::class, $reduction);
$form = $this->createForm(ReductionsType::class, $reduction, [
'action' => $this->generateUrl('app_reductions_edit', ['id' => $reduction->getId()])
]);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager->flush();
return $this->redirectToRoute('app_reductions_index', [], Response::HTTP_SEE_OTHER);
return $this->redirectToRoute('app_index', [], Response::HTTP_SEE_OTHER);
}
return $this->render('reductions/edit.html.twig', [
@ -69,6 +74,6 @@ final class ReductionsController extends AbstractController
$entityManager->flush();
}
return $this->redirectToRoute('app_reductions_index', [], Response::HTTP_SEE_OTHER);
return $this->redirectToRoute('app_index', [], Response::HTTP_SEE_OTHER);
}
}

View File

@ -26,7 +26,9 @@ class UserController extends AbstractController
public function register(Request $request, UserPasswordHasherInterface $userPasswordHasher, Security $security, EntityManagerInterface $entityManager): Response
{
$user = new Utilisateurs();
$form = $this->createForm(AddUserFormType::class, $user);
$form = $this->createForm(AddUserFormType::class, $user, [
'action' => $this->generateUrl('add_user')
]);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
@ -53,7 +55,9 @@ class UserController extends AbstractController
public function update(Request $request, UserPasswordHasherInterface $userPasswordHasher, Security $security, EntityManagerInterface $entityManager, int $id): Response
{
$user = $this->utilisateursRepository->find($id);
$form = $this->createForm(UpdateUserType::class, $user);
$form = $this->createForm(UpdateUserType::class, $user , [
'action' => $this->generateUrl('update-user', ['id' => $user->getId()])
]);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
@ -66,7 +70,7 @@ class UserController extends AbstractController
$entityManager->persist($user);
$entityManager->flush();
return $this->redirectToRoute('app_index');
return $security->login($user, LoginAuthenticator::class, 'main');
}
return $this->render('user/update.html.twig', [

View File

@ -53,7 +53,7 @@
</div>
</li>
<li>
<div class="btn-custom icon-container">
<div class="btn-custom btn-gestion-promotion icon-container">
<i class="icon-medium"> {{ ux_icon('lsicon:badge-promotion-outline') }}</i>
<span>Gestion Promotion</span>
</div>
@ -133,4 +133,5 @@
{% block javascripts %}
<script src="{{ asset('js/Compte/CompteModal.js') }}" defer></script>
<script src="{{ asset('js/GestionUtilisateurs/GestionUtilisateurs.js') }}" defer></script>
<script src="{{ asset('js/GestionPromotion/GestionPromotion.js') }}" defer></script>
{% endblock %}

View File

@ -36,7 +36,7 @@
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ reduction.id) }}">
{{ include('reductions/_delete_form.html.twig') }}
</form>
<a href="{{ path('app_reductions_edit', {'id': reduction.id}) }}">Modifier</a>
<button onclick="updatePromotion(this)" data-id="{{ reduction.id }}" href="{{ path('app_reductions_edit', {'id': reduction.id}) }}">Modifier</button>
</td>
</tr>
{% else %}
@ -47,5 +47,9 @@
</tbody>
</table>
<a href="{{ path('app_reductions_new') }}">Créer une réduction</a>
<button onclick="addPromotion(this)" href="{{ path('app_reductions_new') }}">Créer une réduction</button>
{% endblock %}
{% block javascripts %}
<script src="{{ asset('js/GestionPromotion/GestionPromotion.js') }}" defer></script>
{% endblock %}