2019-12-23 06:25:58 +01:00
|
|
|
@extends('layout.app')
|
|
|
|
|
2019-12-25 22:35:20 +01:00
|
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
|
2020-01-03 05:13:22 +01:00
|
|
|
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@9"></script>
|
|
|
|
<meta name="csrf-token" content="{{ csrf_token() }}">
|
2019-12-25 22:35:20 +01:00
|
|
|
|
2019-12-23 06:25:58 +01:00
|
|
|
@section('left-menu')
|
|
|
|
@parent
|
|
|
|
<ul>
|
2020-01-05 14:36:21 +01:00
|
|
|
<a href="sprzet/add"><li>Dodaj<img src="/img/left_menu_icon/add.png"></li></a>
|
|
|
|
<li>Edytuj<img src="/img/left_menu_icon/edit.png"></li>
|
|
|
|
<li>Usuń<img src="/img/left_menu_icon/delete.png"></li>
|
2019-12-23 06:25:58 +01:00
|
|
|
</ul>
|
|
|
|
@stop
|
|
|
|
|
2019-12-25 22:35:20 +01:00
|
|
|
|
2019-12-23 06:25:58 +01:00
|
|
|
@section('center-area')
|
|
|
|
@parent
|
|
|
|
|
|
|
|
@if( auth()->check())
|
|
|
|
@if( auth()->user()->fireStationID == NULL)
|
|
|
|
Jednostka nie istnieje
|
|
|
|
@else
|
2019-12-25 22:35:20 +01:00
|
|
|
<center><h1>{{$training->trainingName}}</h1></center>
|
2020-01-29 01:57:19 +01:00
|
|
|
<table id="editableTable" class='table'>
|
2019-12-25 22:35:20 +01:00
|
|
|
|
|
|
|
<thead>
|
2020-01-29 01:57:19 +01:00
|
|
|
<th>Imię i Nazwisko</th>
|
|
|
|
<th>Ważne od:</th>
|
|
|
|
<th>Ważne do:</th>
|
|
|
|
<th>Akcje</th>
|
2019-12-25 22:35:20 +01:00
|
|
|
</thead>
|
|
|
|
|
|
|
|
<tbody>
|
|
|
|
@foreach($fireFighters as $fireFighter)
|
|
|
|
<tr id="{{$fireFighter->userID}}">
|
|
|
|
<td>{{$fireFighter->name}} {{$fireFighter->surname}}</td>
|
|
|
|
<td>{{$fireFighter->dateOfComplete}}</td>
|
|
|
|
<td>{{$fireFighter->dateOfExpiry}}</td>
|
2020-01-29 01:57:19 +01:00
|
|
|
<td>
|
|
|
|
<button class="btn btn-warning" type="submit" style="display:none" id="{{$fireFighter->userID}}" onclick="cancelButton('{{$fireFighter->userID}}', '{{$fireFighter->dateOfComplete}}', '{{$fireFighter->dateOfExpiry}}')">Anuluj</button>
|
|
|
|
<button class="btn btn-success" type="submit" style="display:none" id="{{$fireFighter->userID}}" onclick="updateButton('{{$fireFighter->userID}}', '{{$fireFighter->dateOfComplete}}', '{{$fireFighter->dateOfExpiry}}')">Zapisz</button>
|
|
|
|
<button class="btn btn-secondary" type="submit" id="{{$fireFighter->userID}}" onclick="editButton('{{$fireFighter->userID}}')">Edytuj</button>
|
|
|
|
<button class="btn btn-danger btn-delete" type="submit" id="{{$fireFighter->userID}}" onclick="deleteButton('{{$fireFighter->userID}}')">Usuń</button></td>
|
2019-12-25 22:35:20 +01:00
|
|
|
</tr>
|
|
|
|
@endforeach
|
|
|
|
</tbody>
|
|
|
|
</table>
|
2020-01-29 01:57:19 +01:00
|
|
|
{{ $fireFighters->links() }}
|
2019-12-23 06:25:58 +01:00
|
|
|
|
|
|
|
@endif
|
|
|
|
@else
|
|
|
|
Brak autoryzacji
|
|
|
|
@endif
|
|
|
|
|
|
|
|
@stop
|
|
|
|
|
2019-12-25 22:35:20 +01:00
|
|
|
<script type="text/javascript">
|
2019-12-23 06:25:58 +01:00
|
|
|
|
2019-12-25 22:35:20 +01:00
|
|
|
function editButton(firefighterID){
|
2020-01-29 01:57:19 +01:00
|
|
|
$('.btn-secondary', '#'+firefighterID).css('display', 'none');
|
2019-12-25 22:35:20 +01:00
|
|
|
$('.btn-warning', '#'+firefighterID).css('display', 'inline');
|
|
|
|
$('.btn-success', '#'+firefighterID).css('display', 'inline');
|
2020-01-29 01:57:19 +01:00
|
|
|
$('.btn-secondary', '#'+firefighterID).parents("tr").find("td:eq(1)").html('<input type="date" name="dateOfComplete">');
|
|
|
|
$('.btn-secondary', '#'+firefighterID).parents("tr").find("td:eq(2)").html('<input type="date" name="dateOfExpiry">');
|
2019-12-25 22:35:20 +01:00
|
|
|
}
|
2019-12-23 06:25:58 +01:00
|
|
|
|
|
|
|
|
2020-01-03 05:13:22 +01:00
|
|
|
function cancelButton(firefighterID, dateOfComplete, dateOfExpiry){
|
2020-01-29 01:57:19 +01:00
|
|
|
$('.btn-secondary', '#'+firefighterID).css('display', 'inline');
|
2019-12-25 22:35:20 +01:00
|
|
|
$('.btn-warning', '#'+firefighterID).css('display', 'none');
|
|
|
|
$('.btn-success', '#'+firefighterID).css('display', 'none');
|
2019-12-23 06:25:58 +01:00
|
|
|
|
2020-01-29 01:57:19 +01:00
|
|
|
$('.btn-secondary', '#'+firefighterID).parents("tr").find("td:eq(1)").html(dateOfComplete);
|
|
|
|
$('.btn-secondary', '#'+firefighterID).parents("tr").find("td:eq(2)").html(dateOfExpiry);
|
2019-12-25 22:35:20 +01:00
|
|
|
}
|
2019-12-23 06:25:58 +01:00
|
|
|
|
2020-01-03 05:13:22 +01:00
|
|
|
function updateButton(firefighterID, dateOfComplete, dateOfExpiry){
|
2019-12-25 22:35:20 +01:00
|
|
|
$.ajaxSetup({
|
|
|
|
headers: {
|
|
|
|
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
|
2019-12-23 06:25:58 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-12-25 22:35:20 +01:00
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
type: 'post',
|
2020-01-30 16:23:02 +01:00
|
|
|
url: '/szkolenia/addTrainingsFireFighters',
|
2019-12-25 22:35:20 +01:00
|
|
|
data: {
|
|
|
|
'firefighterID': firefighterID,
|
|
|
|
'trainingID': '{{$training->id}}',
|
|
|
|
'dateOfComplete': $('input[name=dateOfComplete]').val(),
|
|
|
|
'dateOfExpiry': $('input[name=dateOfExpiry]').val()
|
|
|
|
},
|
|
|
|
success: function(data) {
|
2020-01-29 01:57:19 +01:00
|
|
|
$('.btn-secondary', '#'+firefighterID).parents("tr").find("td:eq(1)").html($('input[name=dateOfComplete]').val());
|
|
|
|
$('.btn-secondary', '#'+firefighterID).parents("tr").find("td:eq(2)").html($('input[name=dateOfExpiry]').val());
|
2020-01-03 05:13:22 +01:00
|
|
|
|
2020-01-29 01:57:19 +01:00
|
|
|
$('.btn-secondary', '#'+firefighterID).css('display', 'inline');
|
2020-01-03 05:13:22 +01:00
|
|
|
$('.btn-warning', '#'+firefighterID).css('display', 'none');
|
|
|
|
$('.btn-success', '#'+firefighterID).css('display', 'none');
|
|
|
|
console.log('sukces')
|
|
|
|
},
|
|
|
|
error: function(jqXhr, json, errorThrown){// this are default for ajax errors
|
|
|
|
var errors = jqXhr.responseJSON;
|
|
|
|
var errorsHtml = '';
|
|
|
|
$.each(errors['errors'], function (index, value) {
|
|
|
|
errorsHtml += '<ul class="list-group"><li class="list-group-item alert alert-danger">' + value + '</li></ul>';
|
|
|
|
});
|
|
|
|
//I use SweetAlert2 for this
|
|
|
|
swal.fire({
|
|
|
|
title: "Error " + jqXhr.status + ': ' + errorThrown,// this will output "Error 422: Unprocessable Entity"
|
|
|
|
html: errorsHtml,
|
|
|
|
width: 'auto',
|
|
|
|
confirmButtonText: 'Spróbuj ponownie',
|
|
|
|
cancelButtonText: 'Anuluj Edycję',
|
|
|
|
showCancelButton: true,
|
|
|
|
}).then((result) => {
|
|
|
|
if(result.value){
|
|
|
|
console.log('spróbuj')
|
|
|
|
} else if(result.dismiss === Swal.DismissReason.cancel){
|
|
|
|
console.log('anuluj');
|
|
|
|
cancelButton(firefighterID, dateOfComplete, dateOfExpiry);
|
|
|
|
}
|
|
|
|
})
|
2019-12-25 22:35:20 +01:00
|
|
|
},
|
2020-01-03 05:13:22 +01:00
|
|
|
|
2019-12-23 06:25:58 +01:00
|
|
|
});
|
|
|
|
|
2020-01-03 05:13:22 +01:00
|
|
|
|
2019-12-25 22:35:20 +01:00
|
|
|
}
|
|
|
|
|
2020-01-04 22:04:28 +01:00
|
|
|
|
2020-01-03 05:13:22 +01:00
|
|
|
function deleteButton(firefighterID){
|
|
|
|
swal.fire({
|
|
|
|
title: "Czy chcesz wyczyścić?",
|
|
|
|
width: 'auto',
|
|
|
|
confirmButtonText: 'Tak',
|
|
|
|
cancelButtonText: 'Nie',
|
|
|
|
showCancelButton: true,
|
|
|
|
}).then((result) => {
|
|
|
|
if(result.value){
|
|
|
|
|
|
|
|
$.ajaxSetup({
|
|
|
|
headers: {
|
|
|
|
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
type: 'post',
|
2020-01-30 16:23:02 +01:00
|
|
|
url: '/szkolenia/addTrainingsFireFighters/delete',
|
2020-01-03 05:13:22 +01:00
|
|
|
data: {
|
|
|
|
'firefighterID': firefighterID,
|
|
|
|
'trainingID': '{{$training->id}}',
|
|
|
|
},
|
|
|
|
success: function(data) {
|
2020-01-29 01:57:19 +01:00
|
|
|
$('.btn-secondary', '#'+firefighterID).parents("tr").find("td:eq(1)").html('');
|
|
|
|
$('.btn-secondary', '#'+firefighterID).parents("tr").find("td:eq(2)").html('');
|
|
|
|
$('.btn-secondary', '#'+firefighterID).css('display', 'inline');
|
|
|
|
$('.btn-warning', '#'+firefighterID).css('display', 'none');
|
|
|
|
$('.btn-success', '#'+firefighterID).css('display', 'none');
|
|
|
|
|
|
|
|
|
2020-01-03 05:13:22 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
})
|
2019-12-25 22:35:20 +01:00
|
|
|
|
2020-01-03 05:13:22 +01:00
|
|
|
}
|
2019-12-25 22:35:20 +01:00
|
|
|
</script>
|