v0.9.14 - Made an Do you want email slider on settings site

This commit is contained in:
Anders
2020-08-14 10:17:52 +02:00
parent c37645fe85
commit 45d1906497
3 changed files with 75 additions and 2 deletions
@@ -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