This commit is contained in:
frederikpyt 2020-08-14 11:20:18 +02:00
commit 3461803b25
4 changed files with 76 additions and 4 deletions

View File

@ -358,6 +358,42 @@ class UserController extends Controller
return redirect()->route("users.index");
}
public function createajax() {
// Check the UserEvent table if there is a row that has the user_id AND the event_id
$User = User::query()->where('id', '=', auth()->user()->id);
// If you are in the Event, then remove yourself.
if (count($User->get()) > 0) {
// If not, then it keeps going and saves and shows a success message
$User->update([ "wants_emails" => true ]);
if (request()->cookie('languagesSetting') == "dk")
return '<p class="text-center"><b>Du får nu mails, når der kommer nyheder!</b></p>';
if (request()->cookie('languagesSetting') == "en")
return "<p class='text-center'><b>You'll now receive a mail when there's news!</b></p>";
return '<p class="text-center"><b>Du får nu mails, når der kommer nyheder!</b></p>';
}
}
public function createajaxcancel() {
// Check the UserEvent table if there is a row that has the user_id AND the event_id
$User = User::query()->where('id', '=', auth()->user()->id);
// If you are in the Event, then remove yourself.
if (count($User->get()) > 0) {
// If not, then it keeps going and saves and shows a success message
$User->update([ "wants_emails" => false ]);
if (request()->cookie('languagesSetting') == "dk")
return '<p class="text-center"><b>Du får ikke mails mere, når kommer nyheder!</b></p>';
if (request()->cookie('languagesSetting') == "en")
return "<p class='text-center'><b>You'll no longer receive a mail when there's news!</b></p>";
return '<p class="text-center"><b>Du får ikke mails mere, når kommer nyheder!</b></p>';
}
}
/*******************************************/
/* Search and settings */
/*******************************************/

View File

@ -51,11 +51,10 @@
<div class="header">
<h3>{{ $userevent->name }}</h3>
<p class="text-center mt-0">{{__('msg.af')}}: {{ $userevent->accountable }}</p>
<p class="text-center mt-0">{{ \Illuminate\Support\Facades\Date::createFromTimeStamp(strtotime($event->date))->format('d/m/Y \k\l\. H:i') }}</p>
<p class="text-center mt-0">{{ \Illuminate\Support\Facades\Date::createFromTimeStamp(strtotime($userevent->date))->format('d/m/Y \k\l\. H:i') }}</p>
</div>
@endif
<div class="container">
{!! \App\Helpers::closetags(substr($userevent->description, 0, 300) )!!}
<div class="row" style="justify-content: space-between;">
@if (count(\App\UserEvent::query()->where('event_id', '=', $userevent->id)->where('user_id', '=', Auth::user()->id)->get()) > 0)
<a style="margin: 0; padding: 0; font-weight: 700;" class="sde-blue text-center" href="javascript:void(0);" onclick="ajaxCall({{ $userevent->id }}, this)" id="t">{{__('msg.afmeld')}}</a>

View File

@ -97,13 +97,14 @@
<div>
<label class="switch">
@if(\App\User::query()->where('id', '=', auth()->user()->id)->first()->wants_emails == true)
<input type="checkbox" checked>
<input type="checkbox" onclick="ajaxCall(this)" checked>
@else
<input type="checkbox">
<input type="checkbox" onclick="ajaxCall(this)">
@endif
<span class="slider round"></span>
</label>
</div>
<div id="snackbar"></div>
</main>
<script>
$(document).ready(function (){
@ -142,5 +143,39 @@
})
function snackbar(data) {
var x = document.getElementById("snackbar");
x.innerHTML = data;
x.className = "show";
setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
}
function ajaxCall(el) {
if (el.hasAttribute('checked')) {
axios.post("{{ route("users.createajaxcancel") }}", {}
).then(function (response) {
var data = response.data;
snackbar(data);
el.removeAttribute('checked');
}).catch(function (error) {
console.log(error);
});
} else {
axios.post("{{ route("users.createajax") }}", {}
).then(function (response) {
var data = response.data;
snackbar(data);
el.setAttribute('checked', 'checked');
}).catch(function (error) {
console.log(error);
});
}
}
</script>
@endsection

View File

@ -33,8 +33,10 @@ Route::get("/washing-reservationsapi", "WashingReservationController@api")->name
Route::get("/app/washing-reservations", "WashingReservationController@appindex")->name("washing-reservations.appindex");
Route::get("/settings", "SettingsController@index")->name("settings.index");
Route::post("/events/signup", "UserEventController@createajax")->name("userevents.createajax");
Route::post("/account/mailwants", "UserController@createajax")->name("users.createajax");
Route::get("/about", "AboutController@index")->name("about.index");
Route::post("/events/cancelsignup", "UserEventController@createajaxcancel")->name("userevents.createajaxcancel");
Route::post("/account/cancelmailwants", "UserController@createajaxcancel")->name("users.createajaxcancel");
Route::delete("/notifications/delete", "EventController@deleteNotifications")->name("notifications.delete");
//Search/Filter