Events erstellen
This commit is contained in:
79
app/Http/Controllers/EventController.php
Normal file
79
app/Http/Controllers/EventController.php
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Models\ChaosEvents;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
|
||||||
|
class EventController extends Controller
|
||||||
|
{
|
||||||
|
public static function eventsPaginated(){
|
||||||
|
return ChaosEvents::paginate(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addEvent(Request $request) {
|
||||||
|
if(Auth::check()){
|
||||||
|
$name = $request->input('name');
|
||||||
|
$shortname = $request->input('shortname');
|
||||||
|
$from_date_internal = $request->input('from_date_internal');
|
||||||
|
$to_date_internal = $request->input('to_date_internal');
|
||||||
|
$from_date_visible = $request->input('from_date_visible');
|
||||||
|
$to_date_visible = $request->input('to_date_visible');
|
||||||
|
$active = $request->input('active');
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
$event = new ChaosEvents();
|
||||||
|
$event->name = $name;
|
||||||
|
$event->shortname = $shortname;
|
||||||
|
$event->from_date_internal = $from_date_internal;
|
||||||
|
$event->to_date_internal = $to_date_internal;
|
||||||
|
$event->from_date_visible = $from_date_visible;
|
||||||
|
$event->to_date_visible = $to_date_visible;
|
||||||
|
$event->active = $active;
|
||||||
|
|
||||||
|
$event->save();
|
||||||
|
return ['messageStatus' => 'success', 'errorMessage' => ''];
|
||||||
|
} catch (\Illuminate\Database\QueryException $e) {
|
||||||
|
return ['messageStatus' => 'failure', 'errorMessage' => __("controller_messages.EventController.error_occurred", ["error" => $e->getMessage()])];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
abort(404);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteEvent(Request $request) {
|
||||||
|
if(Auth::check()){
|
||||||
|
try {
|
||||||
|
$event = ChaosEvents::find($request->input('id'));
|
||||||
|
if ($event) {
|
||||||
|
$event->delete();
|
||||||
|
return ['messageStatus' => 'success', 'errorMessage' => ''];
|
||||||
|
} else {
|
||||||
|
return ['messageStatus' => 'failure', 'errorMessage' => __("controller_messages.EventController.error_occurred", ["error" => "Event not found"])];
|
||||||
|
}
|
||||||
|
} catch (\Illuminate\Database\QueryException $e) {
|
||||||
|
return ['messageStatus' => 'failure', 'errorMessage' => __("controller_messages.EventController.error_occurred", ["error" => $e->getMessage()])];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
abort(404);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setActivity(Request $request) {
|
||||||
|
if(Auth::check()) {
|
||||||
|
try {
|
||||||
|
$event = ChaosEvents::find($request->input('id'));
|
||||||
|
if ($event) {
|
||||||
|
$event->active = $request->input('active');
|
||||||
|
$event->save();
|
||||||
|
return ['messageStatus' => 'success', 'errorMessage' => ''];
|
||||||
|
} else {
|
||||||
|
return ['messageStatus' => 'failure', 'errorMessage' => __("controller_messages.EventController.error_occurred", ["error" => "Event not found"])];
|
||||||
|
}
|
||||||
|
} catch (\Illuminate\Database\QueryException $e) {
|
||||||
|
return ['messageStatus' => 'failure', 'errorMessage' => __("controller_messages.EventController.error_occurred", ["error" => $e->getMessage()])];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
abort(404);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -82,4 +82,13 @@ class WebsiteController extends Controller
|
|||||||
abort(404);
|
abort(404);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function editEvents(){
|
||||||
|
if(Auth::check()){
|
||||||
|
return response()
|
||||||
|
->view('events.edit', ['events' => EventController::eventsPaginated()])
|
||||||
|
->header('Cache-Control', 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
|
||||||
|
}
|
||||||
|
abort(404);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ return [
|
|||||||
'editTicker' => 'Ticker bearbeiten',
|
'editTicker' => 'Ticker bearbeiten',
|
||||||
'editNews' => 'Neuigkeiten bearbeiten',
|
'editNews' => 'Neuigkeiten bearbeiten',
|
||||||
'editApplications' => 'Anträge bearbeiten',
|
'editApplications' => 'Anträge bearbeiten',
|
||||||
|
'events' => 'C3Gov-Termine',
|
||||||
'logout' => 'Abmelden'
|
'logout' => 'Abmelden'
|
||||||
],
|
],
|
||||||
'index' => [
|
'index' => [
|
||||||
@@ -165,4 +166,19 @@ return [
|
|||||||
'delete_success' => 'Löschen erfolgreich!',
|
'delete_success' => 'Löschen erfolgreich!',
|
||||||
'insert_success' => 'Einfügen erfolgreich!',
|
'insert_success' => 'Einfügen erfolgreich!',
|
||||||
],
|
],
|
||||||
|
'events' => [
|
||||||
|
'description' => 'Hier können Sie Termine hinzufügen oder löschen.',
|
||||||
|
'add' => 'Termin hinzufügen',
|
||||||
|
'delete' => 'Löschen',
|
||||||
|
'active' => 'Aktiv',
|
||||||
|
'name' => 'Name',
|
||||||
|
'list' => 'Termine',
|
||||||
|
'setActivity' => 'Aktiv-Status ändern',
|
||||||
|
'shortname' => 'Namenscode',
|
||||||
|
'from_date_internal' => 'Fristanfang',
|
||||||
|
'to_date_internal' => 'Fristende',
|
||||||
|
'from_date_visible' => 'Terminstart',
|
||||||
|
'to_date_visible' => 'Terminende',
|
||||||
|
|
||||||
|
]
|
||||||
];
|
];
|
||||||
|
|||||||
87
public/js/events/events.js
Normal file
87
public/js/events/events.js
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
function addEvent(){
|
||||||
|
let data = {};
|
||||||
|
data.name = $("#name").val();
|
||||||
|
data.shortname = $("#shortname").val();
|
||||||
|
data.from_date_internal = $("#from_date_internal").val();
|
||||||
|
data.to_date_internal = $("#to_date_internal").val();
|
||||||
|
data.from_date_visible = $("#from_date_visible").val();
|
||||||
|
data.to_date_visible = $("#to_date_visible").val();
|
||||||
|
data.active = $("#active").is(":checked") ? "1" : "0";
|
||||||
|
|
||||||
|
if(window.confirm(i18n.blog.confirm_save)) {
|
||||||
|
$.ajax({
|
||||||
|
type: 'POST',
|
||||||
|
url: '/intern/events/hinzufuegen',
|
||||||
|
data: data,
|
||||||
|
dataType: 'json',
|
||||||
|
success: function (r) {
|
||||||
|
if (r.messageStatus === "success") {
|
||||||
|
$('#name').val("");
|
||||||
|
$('#shortname').val("");
|
||||||
|
$('#from_date_internal').val("");
|
||||||
|
$('#to_date_internal').val("");
|
||||||
|
$('#from_date_visible').val("");
|
||||||
|
$('#to_date_visible').val("");
|
||||||
|
$('#active').prop('checked', false);
|
||||||
|
location.reload();
|
||||||
|
} else {
|
||||||
|
alert(r.errorMessage);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function (r, a, e) {
|
||||||
|
alert(i18n.common.error_occurred + e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function setActivity(id) {
|
||||||
|
let data = {};
|
||||||
|
data.id = id;
|
||||||
|
data.active = $("#active_" + id).is(":checked") ? "1" : "0";
|
||||||
|
|
||||||
|
if(window.confirm(i18n.blog.confirm_save)) {
|
||||||
|
$.ajax({
|
||||||
|
type: 'PATCH',
|
||||||
|
url: '/intern/events/setActivity',
|
||||||
|
data: data,
|
||||||
|
dataType: 'json',
|
||||||
|
success: function (r) {
|
||||||
|
if (r.messageStatus === "success") {
|
||||||
|
location.reload();
|
||||||
|
} else {
|
||||||
|
alert(r.errorMessage);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function (r, a, e) {
|
||||||
|
alert(i18n.common.error_occurred + e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteEvent(id) {
|
||||||
|
let data = {};
|
||||||
|
data.id = id;
|
||||||
|
|
||||||
|
if(window.confirm(i18n.blog.confirm_delete)) {
|
||||||
|
$.ajax({
|
||||||
|
type: 'DELETE',
|
||||||
|
url: '/intern/events/loeschen',
|
||||||
|
data: data,
|
||||||
|
dataType: 'json',
|
||||||
|
success: function (r) {
|
||||||
|
if (r.messageStatus === "success") {
|
||||||
|
$('#delete_' + id).closest('#eingabemaske_' + id).fadeOut(300, function () {
|
||||||
|
$(this).remove();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
alert(r.errorMessage);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function (r, a, e) {
|
||||||
|
alert(i18n.common.error_occurred + e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
97
resources/views/events/edit.blade.php
Normal file
97
resources/views/events/edit.blade.php
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
@extends('layout.app')
|
||||||
|
@section('scripts')
|
||||||
|
<script>
|
||||||
|
const i18n = {
|
||||||
|
common: {
|
||||||
|
error_occurred: "{{ __('app.common.error_occurred') }}"
|
||||||
|
},
|
||||||
|
blog: {
|
||||||
|
confirm_save: "{{ __('app.blog.confirm_save') }}",
|
||||||
|
confirm_delete: "{{ __('app.blog.confirm_delete') }}"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
<script src="{{ asset('js/events/events.js') }}"></script>
|
||||||
|
@endsection
|
||||||
|
@section('content')
|
||||||
|
<h1>{{ __('app.nav.events') }}</h1>
|
||||||
|
<p>{{ __('app.events.description') }}</p>
|
||||||
|
|
||||||
|
<h2>{{ __('app.events.add') }}</h2>
|
||||||
|
|
||||||
|
<div class="eingabemaske">
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td>{{ __('app.events.name') }}:</td>
|
||||||
|
<td><input type="text" id="name"></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>{{ __('app.events.shortname') }}:</td>
|
||||||
|
<td><input type="text" id="shortname"></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>{{ __('app.events.from_date_internal') }}:</td>
|
||||||
|
<td><input type="date" id="from_date_internal"></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>{{ __('app.events.to_date_internal') }}:</td>
|
||||||
|
<td><input type="date" id="to_date_internal"></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>{{ __('app.events.from_date_visible') }}:</td>
|
||||||
|
<td><input type="date" id="from_date_visible"></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>{{ __('app.events.to_date_visible') }}:</td>
|
||||||
|
<td><input type="date" id="to_date_visible"></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>{{ __('app.events.active') }}:</td>
|
||||||
|
<td><input type="checkbox" id="active"></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<button id="add" onclick="addEvent()">{{ __('app.events.add') }}</button>
|
||||||
|
</div>
|
||||||
|
<br /><br />
|
||||||
|
|
||||||
|
<h2>{{ __('app.events.list') }}</h2>
|
||||||
|
@foreach($events as $event)
|
||||||
|
<div id="eingabemaske_{{ $event->id }}" class="eingabemaske">
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td>{{ __('app.events.name') }}:</td>
|
||||||
|
<td>{{ $event->name }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>{{ __('app.events.shortname') }}:</td>
|
||||||
|
<td>{{ $event->shortname }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>{{ __('app.events.from_date_internal') }}:</td>
|
||||||
|
<td>{{ $event->from_date_internal->format('Y-m-d') }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>{{ __('app.events.to_date_internal') }}:</td>
|
||||||
|
<td>{{ $event->to_date_internal->format('Y-m-d') }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>{{ __('app.events.from_date_visible') }}:</td>
|
||||||
|
<td>{{ $event->from_date_visible->format('Y-m-d') }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>{{ __('app.events.to_date_visible') }}:</td>
|
||||||
|
<td>{{ $event->to_date_visible->format('Y-m-d') }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>{{ __('app.events.active') }}:</td>
|
||||||
|
<td><input type="checkbox" id="active_{{ $event->id }}" @if($event->active) checked @endif></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<button id="setActivity_{{ $event->id }}" onclick="setActivity({{ $event->id }})">{{ __('app.events.setActivity') }}</button>
|
||||||
|
<button id="delete_{{ $event->id }}" onclick="deleteEvent({{ $event->id }})">{{ __('app.events.delete') }}</button>
|
||||||
|
</div>
|
||||||
|
<br /><br />
|
||||||
|
@endforeach
|
||||||
|
|
||||||
|
{{ $events->links() }}
|
||||||
|
@endsection
|
||||||
@@ -49,6 +49,7 @@
|
|||||||
<li><a href="{{ route('editTicker') }}">{{ __('app.nav.editTicker') }}</a></li>
|
<li><a href="{{ route('editTicker') }}">{{ __('app.nav.editTicker') }}</a></li>
|
||||||
<li><a href="{{ route('editNews') }}">{{ __('app.nav.editNews') }}</a></li>
|
<li><a href="{{ route('editNews') }}">{{ __('app.nav.editNews') }}</a></li>
|
||||||
<li><a href="{{ route('editApplications') }}">{{ __('app.nav.editApplications') }}</a></li>
|
<li><a href="{{ route('editApplications') }}">{{ __('app.nav.editApplications') }}</a></li>
|
||||||
|
<li><a href="{{ route('editEvents') }}">{{ __('app.nav.events') }}</a></li>
|
||||||
<li><a href="{{ route('logout') }}">{{ __('app.nav.logout') }}</a></li>
|
<li><a href="{{ route('logout') }}">{{ __('app.nav.logout') }}</a></li>
|
||||||
@endauth
|
@endauth
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ use App\Http\Controllers\LoginController;
|
|||||||
use App\Http\Controllers\PreApplicationController;
|
use App\Http\Controllers\PreApplicationController;
|
||||||
use App\Http\Controllers\WebsiteController;
|
use App\Http\Controllers\WebsiteController;
|
||||||
use App\Http\Controllers\TickerController;
|
use App\Http\Controllers\TickerController;
|
||||||
|
use App\Http\Controllers\EventController;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
|
|
||||||
@@ -45,3 +46,8 @@ Route::get('/intern/antraege', [WebsiteController::class, 'editApplications'])->
|
|||||||
Route::post('/intern/antraege/hinzufuegen', [PreApplicationController::class, 'addApplication']);
|
Route::post('/intern/antraege/hinzufuegen', [PreApplicationController::class, 'addApplication']);
|
||||||
Route::delete('/intern/antraege/loeschen', [PreApplicationController::class, 'deleteApplication']);
|
Route::delete('/intern/antraege/loeschen', [PreApplicationController::class, 'deleteApplication']);
|
||||||
Route::put('/intern/antraege/bearbeiten', [PreApplicationController::class, 'editApplication']);
|
Route::put('/intern/antraege/bearbeiten', [PreApplicationController::class, 'editApplication']);
|
||||||
|
|
||||||
|
Route::get('/intern/events', [WebsiteController::class, 'editEvents'])->name('editEvents');
|
||||||
|
Route::post('/intern/events/hinzufuegen', [EventController::class, 'addEvent']);
|
||||||
|
Route::delete('/intern/events/loeschen', [EventController::class, 'deleteEvent']);
|
||||||
|
Route::patch('/intern/events/setActivity', [EventController::class, 'setActivity']);
|
||||||
|
|||||||
Reference in New Issue
Block a user