feat: ✨ Added Sweetalert confirmation over window.confirm
This commit is contained in:
parent
c436bdb4b9
commit
fe153fdc90
|
@ -147,7 +147,7 @@
|
||||||
<i class="fas fa-tools mr-2"></i>
|
<i class="fas fa-tools mr-2"></i>
|
||||||
<span>{{ __('Manage') }}</span>
|
<span>{{ __('Manage') }}</span>
|
||||||
</a>
|
</a>
|
||||||
<button onclick="handleServerDelete('{{ $server->id }}');" target="__blank"
|
<button onclick="confirmSubmit('{{ $server->id }}', handleServerDelete);" target="__blank"
|
||||||
class="btn btn-danger mx-3 w-100 align-items-center justify-content-center d-flex">
|
class="btn btn-danger mx-3 w-100 align-items-center justify-content-center d-flex">
|
||||||
<i class="fas fa-trash mr-2"></i>
|
<i class="fas fa-trash mr-2"></i>
|
||||||
<span>{{ __('Delete') }}</span>
|
<span>{{ __('Delete') }}</span>
|
||||||
|
@ -162,12 +162,29 @@
|
||||||
<!-- END CONTENT -->
|
<!-- END CONTENT -->
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
const handleSubmit = () => {
|
const confirmSubmit = (serverId, handleServerDelete) => {
|
||||||
return confirm('Are you sure you want to delete this server?');
|
// Confirm delete submit with sweetalert
|
||||||
|
Swal.fire({
|
||||||
|
title: '{{ __('Are you sure?') }}',
|
||||||
|
text: "{{ __('This is an irreversible action, all files of this server will be removed.') }}",
|
||||||
|
icon: 'warning',
|
||||||
|
confirmButtonColor: '#d9534f',
|
||||||
|
showCancelButton: true,
|
||||||
|
confirmButtonText: 'Yes, delete it!',
|
||||||
|
cancelButtonText: 'No, cancel!',
|
||||||
|
reverseButtons: true
|
||||||
|
}).then((result) => {
|
||||||
|
if (result.value) {
|
||||||
|
console.log('confirmed');
|
||||||
|
handleServerDelete(serverId);
|
||||||
|
return
|
||||||
|
}
|
||||||
|
Swal.fire('Canceled ...', `Deletion has been canceled.`, 'info');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleServerDelete = (serverId) => {
|
const handleServerDelete = (serverId) => {
|
||||||
if (handleSubmit()) {
|
// Delete server
|
||||||
fetch("{{ route('servers.destroy', '') }}" + '/' + serverId, {
|
fetch("{{ route('servers.destroy', '') }}" + '/' + serverId, {
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -177,6 +194,5 @@
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
@endsection
|
@endsection
|
||||||
|
|
Loading…
Reference in a new issue