diff --git a/src/UnicaenIndicateur/Controller/IndicateurController.php b/src/UnicaenIndicateur/Controller/IndicateurController.php index 773d2983b3d2752f0569f6b9213b9ee08346692b..37e0d15c2dc2da31af92e0724a421d361ea3a7d1 100644 --- a/src/UnicaenIndicateur/Controller/IndicateurController.php +++ b/src/UnicaenIndicateur/Controller/IndicateurController.php @@ -67,11 +67,13 @@ class IndicateurController extends AbstractActionController { { $indicateur = new Indicateur(); - $namespace = $this->params()->fromQuery('namespace'); - if ($namespace) $indicateur->setNamespace($namespace); - $form = $this->getIndicateurForm(); $form->setAttribute('action', $this->url()->fromRoute('indicateur/creer', [], ['query' => ['namespace' => $namespace]], true)); + $namespace = $this->params()->fromQuery('namespace'); + if ($namespace) { + $indicateur->setNamespace($namespace); + $form->get('namespace')->setAttribute('readonly', true); + } $form->bind($indicateur); $request = $this->getRequest(); @@ -100,6 +102,11 @@ class IndicateurController extends AbstractActionController { $indicateur = $this->getIndicateurService()->getRequestedIndicateur($this); $form = $this->getIndicateurForm(); $form->setAttribute('action', $this->url()->fromRoute('indicateur/modifier', [], [], true)); + $namespace = $this->params()->fromQuery('namespace'); + if ($namespace) { + $indicateur->setNamespace($namespace); + $form->get('namespace')->setAttribute('readonly', true); + } $form->bind($indicateur); /** @var Request $request */ @@ -122,12 +129,31 @@ class IndicateurController extends AbstractActionController { return $vm; } - public function detruireAction(): Response + public function detruireAction(): ViewModel { $indicateur = $this->getIndicateurService()->getRequestedIndicateur($this); - $this->getIndicateurService()->dropView($indicateur); - $this->getIndicateurService()->delete($indicateur); - return $this->redirect()->toRoute('indicateurs', [], [], true); + + /** @var Request $request */ + $request = $this->getRequest(); + if ($request->isPost()) { + $data = $request->getPost(); + if ($data["reponse"] === "oui") { + $this->getIndicateurService()->dropView($indicateur); + $this->getIndicateurService()->delete($indicateur); + } + exit(); + } + + $vm = new ViewModel(); + if ($indicateur !== null) { + $vm->setTemplate('unicaen-indicateur/default/confirmation'); + $vm->setVariables([ + 'title' => "Suppression de l'indicateur " . $indicateur->getTitre(), + 'text' => "La suppression est définitive êtes-vous sûr·e de vouloir continuer ?", + 'action' => $this->url()->fromRoute('indicateur/detruire', ["indicateur" => $indicateur->getId()], [], true), + ]); + } + return $vm; } public function regenererAction() : Response diff --git a/view/unicaen-indicateur/default/confirmation.phtml b/view/unicaen-indicateur/default/confirmation.phtml new file mode 100644 index 0000000000000000000000000000000000000000..d7edbbb6a3d9948bfc827011b9a069c64eac0eb2 --- /dev/null +++ b/view/unicaen-indicateur/default/confirmation.phtml @@ -0,0 +1,37 @@ +<?php + +/** + * @var string $title + * @var string $text + * @var string $action + */ + +?> + +<p class="lead"> +<?php echo $text; ?> +</p> + +<table> + <tr><td> +<form method="post" action="<?php echo $action; ?>"> + <input type="hidden" name="reponse" value="oui"> + <input type="submit" name="oui" class="btn btn-success action" value="Oui, je suis sûr·e"> +</form> + </td><td> +<form method="post" action="<?php echo $action; ?>"> + <input type="hidden" name="reponse" value="non"> + <input type="submit" id="non" name="reponse" class="btn btn-danger action" value="Non, je ne veux pas"> +</form> + </td></tr> +</table> + +<script> + $(function() { + $("input#non").click(function(e){ + $('div.modal').modal('hide'); + e.preventDefault(e); + }); + }); +</script> +