diff --git a/assets/controllers/ajax_modal_controller.js b/assets/controllers/ajax_modal_controller.js index d3965c7..f418a63 100644 --- a/assets/controllers/ajax_modal_controller.js +++ b/assets/controllers/ajax_modal_controller.js @@ -3,7 +3,7 @@ import { useFetch } from '../mixins/use_fetch' export default class extends Controller { - static targets = [ 'title', 'content', 'spinner', 'backbutton' ] + static targets = [ 'title', 'content', 'spinner' ] static values = { loading: Boolean } connect() { @@ -41,9 +41,7 @@ export default class extends Controller { this.loadingValue = true const form = event.target const formData = new FormData(form) - if (this.hasBackbuttonTarget && event.submitter === this.backbuttonTarget) { - formData.append(this.backbuttonTarget.name, this.backbuttonTarget.value) - } + formData.append(event.submitter.name, event.submitter.value) fetch(form.action, this.getInitObject('post', formData)) .then(this.checkStatus) .then(this.parseJSON) diff --git a/src/Controller/Admin/Assignment/IndexController.php b/src/Controller/Admin/Assignment/IndexController.php index ebb403a..a84e2bf 100644 --- a/src/Controller/Admin/Assignment/IndexController.php +++ b/src/Controller/Admin/Assignment/IndexController.php @@ -24,12 +24,7 @@ class IndexController extends AbstractController #[IsGranted('ROLE_ADMINISTRATIVE')] public function index(Request $request): Response { - $this->filterHandler->setNamespace('filter:assignment:admin'); - $filterForm = $this->filterHandler->getForm(); - $filterDto = $this->filterHandler->handleRequest($filterForm, $request); - if (true === $filterDto->isReset()) { - return $this->redirectToRoute('app_admin_assignment_index'); - } + $filterDto = $this->filterHandler->getFilterSettings(); $query = $this ->assignmentRepository @@ -48,7 +43,6 @@ class IndexController extends AbstractController return $this->render('admin/assignment/index.html.twig', [ 'pagination' => $pagination, - 'filterForm' => $filterForm, 'filterDto' => $filterDto, ]); } diff --git a/src/Controller/Common/AssignmentFilterController.php b/src/Controller/Common/AssignmentFilterController.php new file mode 100644 index 0000000..52ba5f1 --- /dev/null +++ b/src/Controller/Common/AssignmentFilterController.php @@ -0,0 +1,59 @@ +generateUrl('app_common_assignment_filter', ['r' => $request->query->get('r')]); + $formData = $this->filterHandler->getFilterSettings(); + $filterOptions = $this->assignmentRepository->getFilterOptions(); + $formOptions = [ + 'action' => $formAction, + 'ajax_submit' => true, + 'min_date' => $filterOptions['minDate'], + 'max_date' => $filterOptions['maxDate'], + 'job_profiles' => $filterOptions['jobProfiles'], + 'destinations' => $filterOptions['destinations'], + ]; + + $form = $this->createForm(AssignmentFilterType::class, $formData, $formOptions); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $this->filterHandler->handleRequest($form); + $returnUrl = $this->getReturnUrl($request, 'app_admin_assignment_index'); + $response->setCloseAndRedirect($returnUrl); + } else { + $response->setContent($this->renderView('common/assignment_filter.html.twig', [ + 'filterForm' => $form, + 'filterDto' => $form->getData(), + ])); + } + + return $this->json($response); + } +} \ No newline at end of file diff --git a/src/Controller/Teamer/IndexController.php b/src/Controller/Teamer/IndexController.php index 94aa8b2..3ba05ef 100644 --- a/src/Controller/Teamer/IndexController.php +++ b/src/Controller/Teamer/IndexController.php @@ -34,12 +34,7 @@ class IndexController extends AbstractController // Validate teamer data to show missing data right away $errors = $this->validator->validate($teamer, null, ['profile_preflight']); - $this->filterHandler->setNamespace('filter:assignment:teamer'); - $filterForm = $this->filterHandler->getForm(); - $filterDto = $this->filterHandler->handleRequest($filterForm, $request); - if (true === $filterDto->isReset()) { - return $this->redirectToRoute('app_teamer_index'); - } + $filterDto = $this->filterHandler->getFilterSettings(); $query = $this ->assignmentRepository @@ -60,7 +55,6 @@ class IndexController extends AbstractController 'teamer' => $teamer, 'errors' => $errors, 'pagination' => $pagination, - 'filterForm' => $filterForm, 'filterDto' => $filterDto, ]); } diff --git a/src/Service/Common/AssignmentFilterHandler.php b/src/Service/Common/AssignmentFilterHandler.php index 9c4dd0b..978caf8 100644 --- a/src/Service/Common/AssignmentFilterHandler.php +++ b/src/Service/Common/AssignmentFilterHandler.php @@ -2,15 +2,11 @@ namespace App\Service\Common; -use App\Entity\Assignment; use App\Entity\Destination; use App\Entity\JobProfile; -use App\Form\AssignmentFilterType; use App\Model\AssignmentFilterDto; use Doctrine\ORM\EntityManagerInterface; -use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\Form\FormInterface; -use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Session\SessionInterface; @@ -20,8 +16,7 @@ class AssignmentFilterHandler public function __construct( private readonly RequestStack $requestStack, - private readonly EntityManagerInterface $entityManager, - private readonly FormFactoryInterface $formFactory, + private readonly EntityManagerInterface $entityManager ) { } @@ -32,44 +27,21 @@ class AssignmentFilterHandler return $this; } - public function getForm(): FormInterface + public function handleRequest(FormInterface $form): AssignmentFilterDto { - $filterDto = $this->getFilterSettings(); - - $assignmentRepository = $this - ->entityManager - ->getRepository(Assignment::class) - ; - $filterOptions = $assignmentRepository->getFilterOptions(); - - return $this->formFactory->create(AssignmentFilterType::class, $filterDto, [ - 'min_date' => $filterOptions['minDate'], - 'max_date' => $filterOptions['maxDate'], - 'job_profiles' => $filterOptions['jobProfiles'], - 'destinations' => $filterOptions['destinations'], - ]); - } - - public function handleRequest( - FormInterface $form, - Request $request - ): AssignmentFilterDto { - $form->handleRequest($request); $filterDto = $form->getData(); - if ($form->isSubmitted() && $form->isValid()) { - if ($form->has('reset') && $form->get('reset')->isClicked()) { - $filterDto = new AssignmentFilterDto(true); - $this->getSession()->remove($this->namespace); - } elseif ($form->has('apply') && $form->get('apply')->isClicked()) { - $this->saveFilterSettings($filterDto); - } + if ($form->get('reset')->isClicked()) { + $filterDto = new AssignmentFilterDto(true); + $this->getSession()->remove($this->namespace); + } elseif ($form->get('apply')->isClicked()) { + $this->saveFilterSettings($filterDto); } return $filterDto; } - private function getFilterSettings(): AssignmentFilterDto + public function getFilterSettings(): AssignmentFilterDto { if (null === $data = $this->getSession()->get($this->namespace)) { return new AssignmentFilterDto(); diff --git a/templates/_partials/_filterpanel.html.twig b/templates/_partials/_filterpanel.html.twig deleted file mode 100644 index 797ca16..0000000 --- a/templates/_partials/_filterpanel.html.twig +++ /dev/null @@ -1,25 +0,0 @@ -{{ form_start(filterForm) }} -