From d234415d3849d339fc3b12d25be75e63cd12b531 Mon Sep 17 00:00:00 2001 From: Miguel N Date: Wed, 27 Jan 2021 02:23:30 +0000 Subject: [PATCH] Logic changes for confirmation dialog This commit changes the deletion mechanism for forms. Currently, it sets the wanted deletion ID to the session, and redirects the user to the previous page, to open a confirmation dialog for deletion. --- app/Http/Controllers/FormController.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/app/Http/Controllers/FormController.php b/app/Http/Controllers/FormController.php index 7c8407a..7c22a0f 100755 --- a/app/Http/Controllers/FormController.php +++ b/app/Http/Controllers/FormController.php @@ -82,6 +82,23 @@ class FormController extends Controller public function destroy(Request $request, Form $form) { $this->authorize('delete', $form); + + $request->session()->put('pendingObjectID', $form->id); + $request->session()->put('openConfirmationDialog', true); + + return redirect()->back(); + + } + + public function performConfirmedDeletion(Request $request, Form $form) + { + $this->authorize('delete', $form); + if (!$request->has('confirmed') && $request->confirmed !== 'yes') + { + $request->session()->flash('error', 'You must confirm this action.'); + return redirect()->back(); + } + $deletable = true; if (! is_null($form) && ! is_null($form->vacancies) && $form->vacancies->count() !== 0 || ! is_null($form->responses)) { @@ -96,6 +113,9 @@ class FormController extends Controller $request->session()->flash('error', 'You cannot delete this form because it\'s tied to one or more applications and ranks, or because it doesn\'t exist.'); } + $request->session()->forget('pendingObjectID'); + $request->session()->forget('openConfirmationDialog'); + return redirect()->back(); }