diff --git a/app/Http/Controllers/PreApplicationController.php b/app/Http/Controllers/PreApplicationController.php index 8c13818..60ca84b 100644 --- a/app/Http/Controllers/PreApplicationController.php +++ b/app/Http/Controllers/PreApplicationController.php @@ -7,6 +7,7 @@ use App\Mail\PreApplicationMail; use App\Models\ChaosEvents; use App\Models\PreApplications; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Mail; use Log; use Nette\Utils\Random; @@ -96,14 +97,62 @@ class PreApplicationController extends Controller $pa->last_name = $request->input('last_name'); $pa->location = $request->input('location'); $pa->passport_type = $request->input('passport_type'); - $pa->reference_number = $request->input('reference_number'); - $pa->event_id = $request->input('event_id'); - $pa->email = $request->input('email'); + $pa->event_id = $request->input('district_region'); + $pa->email = $request->input('mail'); + + $ce = ChaosEvents::find($pa->event_id); + $free_reference_number = false; + while(!$free_reference_number){ + $reference_number = $ce->shortname . '-' . strtoupper($pa->passport_type) . '-' . Random::generate(4, "0-9") . '-' . Random::generate(4, "0-9") . '-' . Random::generate(4, "0-9"); + $free_reference_number = !PreApplications::where('reference_number', $reference_number)->exists(); + } + $pa->reference_number = $reference_number; + $pa->save(); + return ["messageStatus" => "success", "errorMessage" => ""]; } catch(\Exception $e){ return ["messageStatus" => "failure", "errorMessage" => $e->getMessage()]; } } + abort(404); + } + + public function deleteApplication(Request $request){ + if(Auth::check()){ + try { + $pa = PreApplications::find($request->input('id')); + if ($pa) { + $pa->delete(); + return ["messageStatus" => "success", "errorMessage" => ""]; + } else { + return ["messageStatus" => "failure", "errorMessage" => __("controller_messages.PreApplicationController.application_not_found")]; + } + } catch(\Exception $e){ + return ["messageStatus" => "failure", "errorMessage" => $e->getMessage()]; + } + } + abort(404); + } + + public function editApplication(Request $request){ + if(Auth::check()){ + try { + $pa = PreApplications::find($request->input('id')); + if ($pa) { + $pa->first_name = $request->input('first_name'); + $pa->last_name = $request->input('last_name'); + $pa->location = $request->input('location'); + $pa->email = $request->input('mail'); + $pa->passport_type = $request->input('passport_type'); + $pa->save(); + return ["messageStatus" => "success", "errorMessage" => ""]; + } + return ["messageStatus" => "failure", "errorMessage" => __("controller_messages.PreApplicationController.application_not_found")]; + } catch(\Exception $e){ + return ["messageStatus" => "failure", "errorMessage" => $e->getMessage()]; + } + } + abort(404); } } diff --git a/lang/de/controller_messages.php b/lang/de/controller_messages.php index 33ab48f..7fcbc56 100644 --- a/lang/de/controller_messages.php +++ b/lang/de/controller_messages.php @@ -10,13 +10,14 @@ return [ 'unknown_error_with_details' => 'Ein unbekannter Fehler ist aufgetreten: :error', ], 'PreApplicationController' => [ - 'success' => 'Voranmeldung erfolgreich abgeschickt. Bitte überprüfen Sie Ihr elektronisches Postfach.', - 'already_submitted' => 'Sie haben bereits einen Vorantrag abgeschickt.', - 'wrong_passport_type' => 'Falscher Passtyp', + 'success' => 'Antrag erfolgreich abgeschickt. Bitte überprüfen Sie Ihr elektronisches Postfach.', + 'already_submitted' => 'Sie haben bereits einen Antrag abgeschickt.', + 'wrong_passport_type' => 'Falscher Reisepass-Typ', 'invalid_email_format' => 'Ungültiges E-Mail-Format', - 'failed_to_process' => 'Fehler beim Verarbeiten der Voranmeldung: :error', + 'failed_to_process' => 'Fehler beim Verarbeiten des Antrages: :error', 'invalid_characters' => 'Ungültige Zeichen im Namen oder Ort', 'event_not_found' => 'Chaos-Event nicht gefunden', + 'application_not_found' => 'Antrag nicht gefunden', ], 'BlogController' => [ 'error_occurred' => 'Ein Fehler ist beim Verarbeiten des Blogs aufgetreten: :error', diff --git a/lang/en/controller_messages.php b/lang/en/controller_messages.php index 0834d3b..375d79b 100644 --- a/lang/en/controller_messages.php +++ b/lang/en/controller_messages.php @@ -10,13 +10,14 @@ return [ 'unknown_error_with_details' => 'An unknown error occurred: :error', ], 'PreApplicationController' => [ - 'success' => 'Preapplication submitted successfully. Please check your email inbox.', - 'already_submitted' => 'You have already submitted a preapplication.', + 'success' => 'Application submitted successfully. Please check your email inbox.', + 'already_submitted' => 'You have already submitted an application.', 'wrong_passport_type' => 'Wrong passport type', 'invalid_email_format' => 'Invalid email format', - 'failed_to_process' => 'Failed to process preapplication: :error', + 'failed_to_process' => 'Failed to process application: :error', 'invalid_characters' => 'Invalid characters in name or location', 'event_not_found' => 'Chaos event not found', + 'application_not_found' => 'Application not found' ], 'BlogController' => [ 'error_occurred' => 'An error occurred while processing the blog: :error', diff --git a/public/js/blog/blog.js b/public/js/blog/blog.js index 18c5c8b..d8864fa 100644 --- a/public/js/blog/blog.js +++ b/public/js/blog/blog.js @@ -82,7 +82,6 @@ function deleteBlog(blogId){ if(r.messageStatus === "success"){ $('#blogDelete_' + blogId).closest('.blogEdit').fadeOut(300, function() { $(this).remove(); - location.reload(); }); } else { alert(r.errorMessage); diff --git a/public/js/preapplication/edit.js b/public/js/preapplication/edit.js index 0b22d89..73bc956 100644 --- a/public/js/preapplication/edit.js +++ b/public/js/preapplication/edit.js @@ -1,27 +1,63 @@ +$(function() { + $('select[autocomplete="off"]').each(function() { + let selectedValue = $(this).find('option[selected]').val(); + if (selectedValue) { + $(this).val(selectedValue); + } + }); + + function updateMaxlengths(element) { + const row = $(element).closest('tr'); + const passportType = row.find('.passport-type-select').val(); + + let maxLength; + switch (passportType) { + case 'd': + maxLength = 17; + break; + case 'k': + maxLength = 25; + break; + default: + maxLength = 17; + } + + row.find('.first-name-input, .last-name-input, .location-input').attr('maxlength', maxLength); + } + + $('.passport-type-select').each(function() { + updateMaxlengths(this); + }); + + $(document).on('change', '.passport-type-select', function() { + updateMaxlengths(this); + }); +}); + function addApplication(){ let data = {}; data.district_region = $('#region_new').val(); - data.passport_type = $('#passport_type').val(); - data.mail = $('#mail').val(); - data.first_name = $('#firstname').val(); - data.last_name = $('#lastname').val(); - data.location = $('#location').val(); + data.passport_type = $('#passport_type_new').val(); + data.mail = $('#mail_new').val(); + data.first_name = $('#first_name_new').val(); + data.last_name = $('#last_name_new').val(); + data.location = $('#location_new').val(); console.log(data); $.ajax({ type: "POST", - url: "/intern/antraege/neu", + url: "/intern/antraege/hinzufuegen", data: data, dataType: "json", success:function(r){ if(r.messageStatus === "success"){ - $('#mail').val(""); - $('#firstname').val(""); - $('#lastname').val(""); - $('#location').val(""); - alert(r.errorMessage); + $('#mail_new').val(""); + $('#first_name_new').val(""); + $('#last_name_new').val(""); + $('#location_new').val(""); + location.reload(); } else { alert(r.errorMessage); } @@ -35,7 +71,9 @@ function addApplication(){ function deleteApplication(applicationId){ let data = {}; data.id = applicationId; + console.log(data); + if(window.confirm(i18n.blog.confirm_delete)){ $.ajax({ type: "DELETE", @@ -44,7 +82,40 @@ function deleteApplication(applicationId){ dataType: "json", success:function(r){ if(r.messageStatus === "success"){ - alert(r.errorMessage); + $('#application_' + applicationId).fadeOut(300, function() { + $(this).remove(); + }); + } else { + alert(r.errorMessage); + } + }, + error:function(r, a, e){ + alert(i18n.common.error_occurred + e); + } + }); + } +} + +function editApplication(applicationId){ + let data = {}; + data.id = applicationId; + data.first_name = $('#first_name_'+applicationId).val(); + data.last_name = $('#last_name_'+applicationId).val(); + data.location = $('#location_'+applicationId).val(); + data.mail = $('#mail_'+applicationId).val(); + data.passport_type = $('#passport_type_'+applicationId).val(); + + console.log(data); + + if(window.confirm(i18n.blog.confirm_save)){ + $.ajax({ + type: "PUT", + url: "/intern/antraege/bearbeiten", + data: data, + dataType: "json", + success:function(r){ + if(r.messageStatus === "success"){ + location.reload(); } else { alert(r.errorMessage); } diff --git a/resources/views/application/edit.blade.php b/resources/views/application/edit.blade.php index f216be8..32f67fe 100644 --- a/resources/views/application/edit.blade.php +++ b/resources/views/application/edit.blade.php @@ -23,7 +23,7 @@
{{ __("app.preapplication.edit.description") }}
- {{ __('app.preapplication.passport_type') }}