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
@@ -31,18 +31,15 @@
<tbody>
@foreach($reservations as $reservation)
@if(date('Y-m-d H:i:s', strtotime('-1 hour')) < $reservation->time)
<tr>
<tr id="row_{{ $reservation->id }}">
<td>{{ \App\Location::query()->find(\App\WashingMachine::query()->find($reservation->machine_id)->location_id)->name }}</td>
<td>{{ \App\WashingMachine::query()->find($reservation->machine_id)->name }}</td>
<td>{{ \Illuminate\Support\Facades\Date::createFromTimeStamp(strtotime($reservation->time))->format('d/m/Y \k\l\. H:i') }}</td>
<td>{{ ucfirst(\App\User::query()->find($reservation->user_id)->name_first) }} {{ ucfirst(\App\User::query()->find($reservation->user_id)->name_last) }}</td>
@if(auth()->user()->can('washing.machine.reservation.delete'))
<td><form method="post" action="{{ route('washing-reservations.destroy', ['washing_reservation' => $reservation]) }}" 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
<a class="w-100 nostyle" onclick="delete_reservation({{ $reservation->id }})"><img class="w-100 cursor-pointer" src="{{ asset('/images/icons/trashcan-dark.svg') }}" alt="Delete"></a>
</td>
@endif
</tr>
@@ -60,5 +57,40 @@
]
});
});
function delete_reservation(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 Reservationen',
cancelButtonText: 'Annuller'
}).then((result) => {
if (result.isConfirmed) {
$.ajax({
type: "POST",
url: "/washing-reservations/"+id,
data:{'_token':token, _method: 'DELETE'},
success: function () {
$('#table_id').DataTable().row($('#row_'+id)[0]).remove().draw();
Swal.fire(
'Reservationen er slettet!',
'',
'success'
)
},
error:function (data) {
console.log(data);
}
});
}
})
}
</script>
@endsection