1
0
forked from s421507/eOSP2

Możliwośc zmiany nazwy szkoleń/badań

This commit is contained in:
czup 2020-01-04 22:04:28 +01:00
parent 6a1804f158
commit d25c6c6b02
4 changed files with 86 additions and 12 deletions

View File

@ -2,6 +2,7 @@
namespace App\Http\Controllers;
use App\equipment;
use App\trainings;
use App\trainingsFirefighters;
use Illuminate\Http\Request;
@ -34,6 +35,24 @@ class trainingsController extends Controller
}
}
public function store(){
$this->validate(request(), [
'name' => 'required',
],
[
'required' => ':attribute jest wymagany(a).',
]);
$request = request();
$equipment = trainings::create([
'fireStationID' => auth()->user()->fireStationID,
'trainingName' => $request-> name,
]);
return redirect()->to('/szkolenia');
}
public function addForm(){
}
@ -143,4 +162,14 @@ class trainingsController extends Controller
return redirect()->to('/szkolenia');
}
public function trainingsRename(Request $request){
$validator = Validator::make($request->all(), [
'trainingID' => 'required',
'trainingName' => 'required',
]);
trainings::where('id', '=', $request->trainingID)
->update(['trainingName' => $request->trainingName]);
}
}

View File

@ -1,6 +1,11 @@
@extends('layout.app')
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<title>Add Edit Delete Table Row Example using JQuery - ItSolutionStuff.com</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" />
<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() }}">
@section('left-menu')
@parent
<ul>
@ -36,17 +41,22 @@
<td>Ilość z ukończonym</td>
<td>Akcje</td>
@foreach($trainings as $training)
<tr>
<form action="{{ route('trainings.destroy', $training->id)}}" method="post">
<tr id="{{$training->id}}">
<td id="name{{ $training->id }}">{{ $training->trainingName }}</td>
<td id="amount{{ $training->id }}">5</td>
<td><input type="button" onclick="showMoreInformation('{{$training->id}}')" id="more{{$training->id}}" value="Więcej">
<button class="btn btn-info" type="submit" onclick="renameTraining('{{$training->id}}')" id="{{$training->id}}">Zmień nazwę</button>
<a href="{{ URL::asset('szkolenia/addTrainingsFireFighters/'.$training->id) }}"><input type="button" onclick="" value="Zarządzaj"></a>
{{ csrf_field() }}
@method('DELETE')
<button class="btn btn-danger" type="submit">Usuń</button>
</td>
</form>
<td>
<form action="{{ route('trainings.destroy', $training->id)}}" method="post">
{{ csrf_field() }}
@method('DELETE')
<button class="btn btn-danger" type="submit">Usuń</button>
</form>
</td>
</tr>
<tr id="moreInformation{{$training->id}}" style="visibility:collapse;" bgcolor="#C0C0C0">
<td colspan="3">
@ -94,4 +104,42 @@
}
}
function renameTraining(trainingID){
swal.fire({
title: "Podaj nową nazwę",
width: 'auto',
input: 'text',
confirmButtonText: 'Tak',
cancelButtonText: 'Anuluj',
showCancelButton: true,
inputValidator: (value) => {
if (!value) {
return 'To pole nie może zostać puste'
}
}
}).then((result) => {
if(result.value){
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
type: 'post',
url: '/szkolenia/rename',
data: {
'trainingID': trainingID,
'trainingName': result.value,
},
success: function(data) {
$('.btn-info', '#'+trainingID).parents("tr").find("td:eq(0)").html(result.value);
}
});
}
}
)
}
</script>

View File

@ -129,6 +129,7 @@
}
function deleteButton(firefighterID){
swal.fire({
title: "Czy chcesz wyczyścić?",
@ -162,8 +163,3 @@
}
</script>

View File

@ -83,6 +83,7 @@ Route::resource('equipment', 'EquipmentController');
Route::get('/szkolenia', 'trainingsController@create');
Route::post('/szkolenia', 'trainingsController@store');
Route::post('/szkolenia/rename', 'trainingsController@trainingsRename');
Route::get('/szkolenia/addTrainingsFireFighters/{id}', 'trainingsController@addTrainingsFireFighters');
Route::post('/szkolenia/addTrainingsFireFighters/', 'trainingsController@ajaxRequest');
Route::post('/szkolenia/addTrainingsFireFighters/delete', 'trainingsController@deleteFireFighterTrainings');