v0.9.14 - Made an `Do you want email` slider on settings site
This commit is contained in:
parent
c37645fe85
commit
45d1906497
|
@ -358,6 +358,42 @@ class UserController extends Controller
|
||||||
return redirect()->route("users.index");
|
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 */
|
/* Search and settings */
|
||||||
/*******************************************/
|
/*******************************************/
|
||||||
|
|
|
@ -97,13 +97,14 @@
|
||||||
<div>
|
<div>
|
||||||
<label class="switch">
|
<label class="switch">
|
||||||
@if(\App\User::query()->where('id', '=', auth()->user()->id)->first()->wants_emails == true)
|
@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
|
@else
|
||||||
<input type="checkbox">
|
<input type="checkbox" onclick="ajaxCall(this)">
|
||||||
@endif
|
@endif
|
||||||
<span class="slider round"></span>
|
<span class="slider round"></span>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
<div id="snackbar"></div>
|
||||||
</main>
|
</main>
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function (){
|
$(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>
|
</script>
|
||||||
@endsection
|
@endsection
|
||||||
|
|
|
@ -33,8 +33,10 @@ Route::get("/washing-reservationsapi", "WashingReservationController@api")->name
|
||||||
Route::get("/app/washing-reservations", "WashingReservationController@appindex")->name("washing-reservations.appindex");
|
Route::get("/app/washing-reservations", "WashingReservationController@appindex")->name("washing-reservations.appindex");
|
||||||
Route::get("/settings", "SettingsController@index")->name("settings.index");
|
Route::get("/settings", "SettingsController@index")->name("settings.index");
|
||||||
Route::post("/events/signup", "UserEventController@createajax")->name("userevents.createajax");
|
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::get("/about", "AboutController@index")->name("about.index");
|
||||||
Route::post("/events/cancelsignup", "UserEventController@createajaxcancel")->name("userevents.createajaxcancel");
|
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");
|
Route::delete("/notifications/delete", "EventController@deleteNotifications")->name("notifications.delete");
|
||||||
|
|
||||||
//Search/Filter
|
//Search/Filter
|
||||||
|
|
Loading…
Reference in New Issue