Skip to content

Commit

Permalink
provide value motif via data-attribute #3381
Browse files Browse the repository at this point in the history
  • Loading branch information
sfinx13 committed Dec 3, 2024
1 parent 855609c commit c7966a3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,15 @@ modalsElement.forEach(modalElement => {
})
})

document.querySelectorAll('button[data-cloture-type]').forEach(button => {
button.addEventListener('click', (e) => {
const element = e.target;
if (element && element?.dataset) {
document.getElementById('cloture_type').value = element.dataset.clotureType
}
});
});

document?.getElementById('signalement-add-suivi-notify-usager')?.addEventListeners('change', (e) => {
document.getElementById('signalement-add-suivi-submit').textContent = (e.target.checked) ? 'Envoyer le suivi à l\'usager' : 'Enregistrer le suivi interne'
})
Expand Down
6 changes: 1 addition & 5 deletions src/Controller/Back/SignalementController.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,7 @@ public function viewSignalement(
}
}
$isClosedForMe = $isClosedForMe ?? Signalement::STATUS_CLOSED === $signalement->getStatut();
$clotureForm = $this->createForm(type: ClotureType::class, options: [
'is_admin_territory' => $this->isGranted('ROLE_ADMIN_TERRITORY'),
'is_accepted' => $isAccepted,
'is_affected' => $isAffected,
]);
$clotureForm = $this->createForm(ClotureType::class);
$clotureForm->handleRequest($request);
$eventParams = [];
if ($clotureForm->isSubmitted() && $clotureForm->isValid()) {
Expand Down
13 changes: 1 addition & 12 deletions src/Form/ClotureType.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@ class ClotureType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$clotureType = 'partner';
if ($options['is_admin_territory']) {
$clotureType = 'all';
if ($options['is_affected'] && $options['is_accepted']) {
$clotureType = 'partner';
}
}

$builder
->add('motif', EnumType::class, [
'class' => MotifCloture::class,
Expand All @@ -39,17 +31,14 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'class' => 'fr-hint-text',
],
])
->add('type', HiddenType::class, ['data' => $clotureType]);
->add('type', HiddenType::class);
}

public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => null,
'allow_extra_fields' => true,
'is_admin_territory' => false,
'is_affected' => false,
'is_accepted' => false,
'attr' => [
'id' => 'cloture_form',
],
Expand Down
4 changes: 3 additions & 1 deletion templates/_partials/_modal_cloture.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
<button class="fr-btn fr-icon-check-line"
form="cloture_form"
type="submit"
data-cloture-type="all"
disabled>
Clôturer pour tous les partenaires
</button>
Expand All @@ -78,6 +79,7 @@
<button class="fr-btn fr-icon-check-line"
form="cloture_form"
type="submit"
data-cloture-type="partner"
disabled>
Clôturer pour {{ app.user.partner ? app.user.partner.nom }}
</button>
Expand All @@ -87,7 +89,7 @@
<li>
<button class="fr-btn fr-icon-check-line"
form="cloture_form"
value="partner"
data-cloture-type="partner"
type="submit"
disabled>
Clôturer pour {{ app.user.partner ? app.user.partner.nom }}
Expand Down

0 comments on commit c7966a3

Please sign in to comment.