diff --git a/changelog.md b/changelog.md
index 30f0304..50114c7 100644
--- a/changelog.md
+++ b/changelog.md
@@ -64,4 +64,5 @@
### Next
#### Improve
-- Move columns in activity table
\ No newline at end of file
+- Move columns in activity table
+- Reditect to activity after creating one
\ No newline at end of file
diff --git a/src/Controller/ActivityController.php b/src/Controller/ActivityController.php
index 648a6c8..6fad908 100644
--- a/src/Controller/ActivityController.php
+++ b/src/Controller/ActivityController.php
@@ -14,6 +14,7 @@
use App\Form\Activity\ActivityDeleteForm;
use App\Form\Activity\ActivityEditForm;
use App\Form\Activity\ActivityFilterForm;
+use Symfony\Component\Routing\Generator\UrlGenerator;
/**
* Controller for activity related pages
@@ -52,8 +53,9 @@
$entityManager->persist($activity);
$entityManager->flush();
return $this->ajaxFormAnswer([
- 'refresh' => true,
- 'reset' => true,
+ 'redirect' => $this->generateUrl('activity_activity', [
+ 'id' => $activity->getId()
+ ], UrlGenerator::ABSOLUTE_PATH),
]);
} else {
return $this->ajaxFormAnswer([
@@ -153,6 +155,33 @@
}
}
+ // Activity delete form
+ /** @var ActivityDeleteForm $activityDeleteForm */
+ $activityDeleteForm = $this->createNamedCustomForm('activityDelete', ActivityDeleteForm::class);
+ $activityDeleteForm->handleRequest($request);
+ if ($activityDeleteForm->isSubmitted() && $activityDeleteForm->isValid()) {
+ $errors = $activityDeleteForm->validate();
+ if (empty($errors)) {
+ if (!is_null($activity)) {
+ $entityManager->remove($activity);
+ $entityManager->flush();
+ return $this->ajaxFormAnswer([
+ 'redirect' => $this->generateUrl('activity_activities', [], UrlGenerator::ABSOLUTE_PATH),
+ ]);
+ } else {
+ return $this->ajaxFormAnswer([
+ 'error' => 'Activité non trouvé',
+ 'code' => Response::HTTP_BAD_REQUEST,
+ ]);
+ }
+ } else {
+ return $this->ajaxFormAnswer([
+ 'error' => join('
', $errors),
+ 'code' => Response::HTTP_BAD_REQUEST,
+ ]);
+ }
+ }
+
// Update fields
$activityEditForm->updateFields($activity);
@@ -166,6 +195,7 @@
'activity' => $activity,
'tasks' => $tasks,
'activityEditForm' => $activityEditForm,
+ 'activityDeleteForm' => $activityDeleteForm,
]);
}
}
\ No newline at end of file
diff --git a/src/Controller/ActorController.php b/src/Controller/ActorController.php
index 9363d9c..d2c414d 100644
--- a/src/Controller/ActorController.php
+++ b/src/Controller/ActorController.php
@@ -145,7 +145,7 @@
$entityManager->remove($actor);
$entityManager->flush();
return $this->ajaxFormAnswer([
- 'redirect' => $this->generateUrl('actors_actors', [], UrlGenerator::ABSOLUTE_PATH),
+ 'redirect' => $this->generateUrl('actor_actors', [], UrlGenerator::ABSOLUTE_PATH),
]);
} else {
return $this->ajaxFormAnswer([
@@ -174,8 +174,8 @@
'actor' => $actor,
'activities' => $activities,
'tasks' => $tasks,
- 'editForm' => $actorEditForm,
- 'deleteForm' => $actorDeleteForm,
+ 'actorEditForm' => $actorEditForm,
+ 'actorDeleteForm' => $actorDeleteForm,
]);
}
}
diff --git a/templates/_includes/html/form/activity/add.html.twig b/templates/_includes/html/form/activity/add.html.twig
index e160425..483635d 100644
--- a/templates/_includes/html/form/activity/add.html.twig
+++ b/templates/_includes/html/form/activity/add.html.twig
@@ -15,7 +15,6 @@
{{ form_label(form.actor, 'Acteur', {label_attr: {class: 'input-text-label'}}) }}
{{ form_widget(form.actor, {attr: {class: 'w-100'}}) }}
-