eOSP2/resources/views/trainingsAddFireFighters.blade.php

171 lines
7.2 KiB
PHP
Raw Normal View History

@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>
<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
@section('left-menu')
@parent
<ul>
2020-01-30 21:19:05 +01:00
<a href="/strazacy"><li>Strażacy<img src="/img/left_menu_icon/more.png"></li></a>
<a href="/szkolenia"><li><font size="-2">Badania/Szkolenia</font><img src="/img/left_menu_icon/more.png"></li></a>
</ul>
@stop
2019-12-25 22:35:20 +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>
<table id="editableTable" class='table'>
2019-12-25 22:35:20 +01:00
<thead>
<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>
<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>
{{ $fireFighters->links() }}
@endif
@else
Brak autoryzacji
@endif
@stop
2019-12-25 22:35:20 +01:00
<script type="text/javascript">
2019-12-25 22:35:20 +01:00
function editButton(firefighterID){
$('.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');
$('.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
}
function cancelButton(firefighterID, dateOfComplete, dateOfExpiry){
$('.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');
$('.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
}
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-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) {
$('.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());
$('.btn-secondary', '#'+firefighterID).css('display', 'inline');
$('.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
},
});
2019-12-25 22:35:20 +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',
data: {
'firefighterID': firefighterID,
'trainingID': '{{$training->id}}',
},
success: function(data) {
$('.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');
}
});
}
})
2019-12-25 22:35:20 +01:00
}
2019-12-25 22:35:20 +01:00
</script>