Backend für Anträge; unnötiges location.reload() entfernt
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
<h1>{{ __("app.preapplication.edit.title") }}</h1>
|
||||
<p>{{ __("app.preapplication.edit.description") }}</p>
|
||||
|
||||
{{ __('app.preapplication.passport_type') }}<br />
|
||||
<b>{{ __('app.preapplication.passport_type') }}:</b><br />
|
||||
d = {{ __('app.preapplication.passport.standard') }}<br />
|
||||
k = {{ __('app.preapplication.passport.kid') }}
|
||||
<br /><br />
|
||||
@@ -41,16 +41,21 @@
|
||||
<th>{{ __('app.preapplication.actions') }}</th>
|
||||
</tr>
|
||||
@foreach($applications as $appl)
|
||||
<tr>
|
||||
<tr id="application_{{ $appl->id }}">
|
||||
<td>{{ $appl->event()->first()->name }}</td>
|
||||
<td>{{ $appl->reference_number }}</td>
|
||||
<td><input id="first_name_{{ $appl->id }}" type="text" value="{{ $appl->first_name }}"></td>
|
||||
<td><input id="last_name_{{ $appl->id }}" type="text" value="{{ $appl->last_name }}"></td>
|
||||
<td><input id="location_{{ $appl->id }}" type="text" value="{{ $appl->location }}"></td>
|
||||
<td><input id="email_{{ $appl->id }}" type="text" value="{{ $appl->email }}"></td>
|
||||
<td>{{ $appl->passport_type }}</td>
|
||||
<td><input id="first_name_{{ $appl->id }}" class="first-name-input" type="text" value="{{ $appl->first_name }}"></td>
|
||||
<td><input id="last_name_{{ $appl->id }}" class="last-name-input" type="text" value="{{ $appl->last_name }}"></td>
|
||||
<td><input id="location_{{ $appl->id }}" class="location-input" type="text" value="{{ $appl->location }}"></td>
|
||||
<td><input id="mail_{{ $appl->id }}" type="text" value="{{ $appl->email }}"></td>
|
||||
<td>
|
||||
<select id="passport_type_{{ $appl->id }}" class="passport-type-select">
|
||||
<option value="d"{{ ( $appl->passport_type == "d" ? " selected" : "" ) }}>d</option>
|
||||
<option value="k"{{ ( $appl->passport_type == "k" ? " selected" : "" ) }}>k</option>
|
||||
</select>
|
||||
</td>
|
||||
<td>{{ $appl->created_at }}</td>
|
||||
<td><button onclick="editApplication({{ $appl->id }})">{{ __('app.preapplication.edit.save') }}</button><button onclick="deleteApplication({{ $appl->id }})">{{ __('app.preapplication.edit.delete') }}</button></td>
|
||||
<td><button onclick="editApplication({{ $appl->id }})">{{ __('app.preapplication.edit.save') }}</button><button id="applicationDelete_{{ $appl->id }}" onclick="deleteApplication({{ $appl->id }})">{{ __('app.preapplication.edit.delete') }}</button></td>
|
||||
</tr>
|
||||
@endforeach
|
||||
<tr>
|
||||
@@ -62,11 +67,11 @@
|
||||
</select>
|
||||
</td>
|
||||
<td>{{ __('app.preapplication.edit.generated') }}</td>
|
||||
<td><input id="first_name_new" type="text"></td>
|
||||
<td><input id="last_name_new" type="text"></td>
|
||||
<td><input id="location_new" type="text"></td>
|
||||
<td><input id="email_new" type="text"></td>
|
||||
<td><select id="passport_type_new">
|
||||
<td><input id="first_name_new" class="first-name-input" type="text"></td>
|
||||
<td><input id="last_name_new" class="last-name-input" type="text"></td>
|
||||
<td><input id="location_new" class="location-input" type="text"></td>
|
||||
<td><input id="mail_new" type="text"></td>
|
||||
<td><select id="passport_type_new" class="passport-type-select">
|
||||
<option value="d">d</option>
|
||||
<option value="k">k</option>
|
||||
</select>
|
||||
|
||||
@@ -41,6 +41,6 @@ Route::delete('/intern/nachrichten/delete', [BlogController::class, 'deleteBlog'
|
||||
Route::put('/intern/nachrichten/edit', [BlogController::class, 'editBlog']);
|
||||
|
||||
Route::get('/intern/antraege', [WebsiteController::class, 'editApplications'])->name('editApplications');
|
||||
Route::post('/intern/antraege/add', [PreApplicationController::class, 'addApplication']);
|
||||
Route::delete('/intern/antraege/delete', [PreApplicationController::class, 'deleteApplication']);
|
||||
Route::put('/intern/antraege/edit', [PreApplicationController::class, 'editApplication']);
|
||||
Route::post('/intern/antraege/hinzufuegen', [PreApplicationController::class, 'addApplication']);
|
||||
Route::delete('/intern/antraege/loeschen', [PreApplicationController::class, 'deleteApplication']);
|
||||
Route::put('/intern/antraege/bearbeiten', [PreApplicationController::class, 'editApplication']);
|
||||
|
||||
Reference in New Issue
Block a user