feat: ✨ Added Sweetalert confirmation over window.confirm
This commit is contained in:
parent
c436bdb4b9
commit
fe153fdc90
1 changed files with 29 additions and 13 deletions
|
@ -147,7 +147,7 @@
|
|||
<i class="fas fa-tools mr-2"></i>
|
||||
<span>{{ __('Manage') }}</span>
|
||||
</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">
|
||||
<i class="fas fa-trash mr-2"></i>
|
||||
<span>{{ __('Delete') }}</span>
|
||||
|
@ -162,21 +162,37 @@
|
|||
<!-- END CONTENT -->
|
||||
|
||||
<script>
|
||||
const handleSubmit = () => {
|
||||
return confirm('Are you sure you want to delete this server?');
|
||||
const confirmSubmit = (serverId, handleServerDelete) => {
|
||||
// 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) => {
|
||||
if (handleSubmit()) {
|
||||
fetch("{{ route('servers.destroy', '') }}" + '/' + serverId, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
'X-CSRF-TOKEN': '{{ csrf_token() }}'
|
||||
}
|
||||
}).then(() => {
|
||||
window.location.reload();
|
||||
});
|
||||
}
|
||||
// Delete server
|
||||
fetch("{{ route('servers.destroy', '') }}" + '/' + serverId, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
'X-CSRF-TOKEN': '{{ csrf_token() }}'
|
||||
}
|
||||
}).then(() => {
|
||||
window.location.reload();
|
||||
});
|
||||
}
|
||||
</script>
|
||||
@endsection
|
||||
|
|
Loading…
Add table
Reference in a new issue