Commit 207e40f4 authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Confirmation avant suppression Indicateur + Blocage namespace si donné

parent 63aa667b
Loading
Loading
Loading
Loading
Loading
+33 −7
Original line number Diff line number Diff line
@@ -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);

        /** @var Request $request */
        $request = $this->getRequest();
        if ($request->isPost()) {
            $data = $request->getPost();
            if ($data["reponse"] === "oui") {
                $this->getIndicateurService()->dropView($indicateur);
                $this->getIndicateurService()->delete($indicateur);
        return $this->redirect()->toRoute('indicateurs', [], [], true);
            }
            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
+37 −0
Original line number Diff line number Diff line
<?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&middot;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>