v1.5.3 - Added Swal on all index pages

This commit is contained in:
Anders
2020-12-01 12:05:18 +01:00
parent f42d401ac7
commit dc9c1bf113
20 changed files with 1813 additions and 1429 deletions
@@ -33,19 +33,16 @@
</thead>
<tbody>
@foreach($roles as $role)
<tr>
<tr id="row_{{ $role->id }}">
<td>{{ $role->name }}</td>
<td>{{ $role->description }}</td>
@if(auth()->user()->can('roles.edit'))
<td><a href="{{ route("roles.edit", [ "role" => $role->id ]) }}"><img class="w-100" src="{{ asset('/images/icons/pencil-dark.svg') }}" alt="Update"></a></td>
@endif
@if(auth()->user()->can('roles.delete'))
<td><form method="post" action="{{ route("roles.destroy", [ "role" => $role ]) }}" class="w-100 nostyle">
<td>
@csrf
@method("delete")
<button onclick="return confirm('Are you sure you want to delete?');" class="w-100 nostyle" type="submit"><img class="w-100 cursor-pointer" src="{{ asset('/images/icons/trashcan-dark.svg') }}" alt="Delete"></button>
</form>
<a class="w-100 nostyle" onclick="delete_role({{ $role->id }})"><img class="w-100 cursor-pointer" src="{{ asset('/images/icons/trashcan-dark.svg') }}" alt="Delete"></a>
</td>
@endif
</tr>
@@ -62,5 +59,54 @@
]
});
});
function delete_role(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 Rollen',
cancelButtonText: 'Annuller'
}).then((result) => {
if (result.isConfirmed) {
$.ajax({
type: "POST",
url: "roles/"+id,
data:{'_token':token, _method: 'DELETE'},
success: function () {
if (id == 1) {
Swal.fire(
'Administrator rollen kan ikke slettes',
'',
'warning'
)
} else if (id == 2) {
Swal.fire(
'Bruger rollen kan ikke slette',
'',
'warning'
)
} else {
$('#table_id').DataTable().row($('#row_'+id)[0]).remove().draw();
Swal.fire(
'Rollen er slettet!',
'',
'success'
)
}
},
error:function (data) {
console.log(data);
}
});
}
})
}
</script>
@endsection