v1.5.3 - Added Swal on all index pages
This commit is contained in:
@@ -35,7 +35,7 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach($contacts as $contact)
|
||||
<tr>
|
||||
<tr id="row_{{ $contact->id }}">
|
||||
<td>{{ $contact->contactname }}</td>
|
||||
<td>{{ $contact->title }}</td>
|
||||
<td>{{ $contact->email }}</td>
|
||||
@@ -44,12 +44,9 @@
|
||||
<td><a href="{{ route("contacts.edit", [ "contact" => $contact ]) }}"><img class="w-100" src="{{ asset('/images/icons/pencil-dark.svg') }}" alt="Update"></a></td>
|
||||
@endif
|
||||
@if(auth()->user()->can('contact.delete'))
|
||||
<td><form method="post" action="{{ route("contacts.destroy", [ "contact" => $contact ]) }}" class="w-100 nostyle">
|
||||
@csrf
|
||||
@method("delete")
|
||||
|
||||
<button class="w-100 nostyle" onclick="return confirm('Are you sure you want to delete?');" type="submit"><img class="w-100 cursor-pointer" src="{{ asset('/images/icons/trashcan-dark.svg') }}" alt="Delete"></button>
|
||||
</form>
|
||||
<td>
|
||||
@csrf
|
||||
<button class="w-100 nostyle" onclick="delete_contact({{ $contact->id }})"><img class="w-100 cursor-pointer" src="{{ asset('/images/icons/trashcan-dark.svg') }}" alt="Delete"></button>
|
||||
</td>
|
||||
@endif
|
||||
</tr>
|
||||
@@ -66,5 +63,40 @@
|
||||
]
|
||||
});
|
||||
});
|
||||
|
||||
function delete_contact(id) {
|
||||
var token = $("input[name='_token']").val();
|
||||
|
||||
Swal.fire({
|
||||
title: 'Er du sikker?',
|
||||
text: "Dette kan ikke blive ændret tilbage!",
|
||||
icon: 'warning',
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: '#3085d6',
|
||||
cancelButtonColor: '#d33',
|
||||
confirmButtonText: 'Slet Kontakten',
|
||||
cancelButtonText: 'Annuller'
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "contacts/"+id,
|
||||
data:{'_token':token, _method: 'DELETE'},
|
||||
success: function () {
|
||||
$('#table_id').DataTable().row($('#row_'+id)[0]).remove().draw();
|
||||
|
||||
Swal.fire(
|
||||
'Kontakten er slettet!',
|
||||
'',
|
||||
'success'
|
||||
)
|
||||
},
|
||||
error:function (data) {
|
||||
console.log(data);
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
</script>
|
||||
@endsection
|
||||
|
||||
Reference in New Issue
Block a user