1
0
forked from s421507/eOSP2

Wyjazdy - dodano dodawanie kilku kierowcow

This commit is contained in:
czup 2019-11-25 01:10:46 +01:00
parent c503cec90d
commit f137fb0759
4 changed files with 119 additions and 23 deletions

View File

@ -28,9 +28,9 @@ class VehiclesController extends Controller
}
public function addForm(){
if(auth()->user() != null && auth()->user()->fireStationID != null ){
if(auth()->user() != null && auth()->user()->fireStationID != null ){
return view('vehiclesAdd');
} else return view("login");
}
@ -43,14 +43,14 @@ class VehiclesController extends Controller
//$fireStationCreatorId = DB::table('fireStations')->where("id", $userFireStation)->value('creatorID');
$vehicle = DB::table('vehicles')->where("id", $id)->first();
return view('vehiclesEdit', ["vehicle" => $vehicle]);
}
}
else
return "Brak dostepu";
}
public function store(){
@ -76,7 +76,7 @@ class VehiclesController extends Controller
$vehicle = vehicle::create([
'fireStationID' => auth()->user()->fireStationID,
'name' => $request-> name,
'codename' => $request-> codename,
'codename' => $request-> codename,
'brand' => $request-> brand,
'registrationNumber' => $request-> registrationNumber,
'productionYear' => $request-> productionYear,
@ -123,7 +123,7 @@ class VehiclesController extends Controller
$request = request();
$vehicle = vehicle::find( $request->vehicleID);
$vehicle-> name = $request-> name;
$vehicle-> codename = $request-> codename;
$vehicle-> codename = $request-> codename;
$vehicle-> brand = $request-> brand;
$vehicle-> registrationNumber = $request-> registrationNumber;
$vehicle-> productionYear = $request-> productionYear;

View File

@ -6,6 +6,7 @@ namespace App\Http\Controllers;
use App\User;
use App\operations;
use App\operationsMembers;
use App\vehicle;
use App\operationsDrivers;
use Illuminate\Http\Request;
@ -28,7 +29,9 @@ class operationsController extends Controller
//$fireStationID = auth()->user()->fireStationID;
// $fireFighters = User::pluck('fireStationID', $fireStationID);
$fireFighters = DB::table('users')->where("fireStationID", "=", auth()->user()->fireStationID )->get();
return view("operationAdd", ["fireFighters" => $fireFighters]);
$vehicles = DB::table('vehicles')->where("fireStationID", '=', auth()->user()->fireStationID)
->get();
return view("operationAdd", ["fireFighters" => $fireFighters], ["vehicles" => $vehicles]);
} else return view("unit");
}
@ -60,7 +63,6 @@ class operationsController extends Controller
'dangerType' => $request-> operationDangerType,
'description' => $request-> operationDescription,
'commanderID' => $request-> operationLeader,
'driverID' => $request-> operationDriver,
]);
return operationsController::create();

View File

@ -1,5 +1,6 @@
@extends('layout.app')
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
@section('left-menu')
@parent<ul>
<a href="?addOperation"><li>Dodaj<img src="img/left_menu_icon/add.png"></li></a>
@ -11,8 +12,7 @@
@section('center-area')
@parent
Strona w budowie - dodawanie
<form method="POST" action="/wyjazdy">
<form method="POST" action="/wyjazdy" id="dynamic_form">
{{ csrf_field() }}
<div class="form-group">
<label for="date">Data wyjazdu: </label>
@ -49,19 +49,113 @@
</select>
</div>
<div class=form-group">
<label for="location">Kierowca:</label>
<select name="operationDriver" class="form-control">
<option value="">--- Wybierz kierowcę ---</option>
@foreach ($fireFighters as $fireFighter)
<option value="{{$fireFighter->id}}">{{ $fireFighter->name }} {{$fireFighter->surname }}</option>
@endforeach
</select>
<div class="form-group">
<button style="cursor:pointer" type="submit" class="btn btn-primary">Dodaj</button>
<div class=form-group">
<div id="drivers">
<label for="location">Kierowca:</label>
<select name="operationDriver" class="form-control">
<option value="">--- Wybierz kierowcę ---</option>
@foreach ($fireFighters as $fireFighter)
<option value="{{$fireFighter->id}}">{{ $fireFighter->name }} {{$fireFighter->surname }}</option>
@endforeach
</select>
<label for="location">Pojazd:</label>
<select name="operationVehicle" class="form-control">
<option value="">--- Wybierz pojazd ---</option>
@foreach ($vehicles as $vehicle)
<option value="{{$vehicle->id}}">{{ $vehicle->name }} {{$vehicle->codename }} {{$vehicle->registrationNumber }}</option>
@endforeach
</select>
</div>
</div>
<div class="form-group">
<button style="cursor:pointer" type="submit" class="btn btn-primary">Zapisz</button>
</div>
@include('inc.formerrors')
</form>
@stop
<script>
$(document).ready(function(){
var count = 1;
dynamic_field(count);
function dynamic_field(number)
{
html = '<div id="singleDriver"><label for="location">Kierowca:</label>';
html += '<select name="operationDriver[]" class="form-control">';
html += '<option value="">--- Wybierz kierowcę ---</option>';
html += '@foreach ($fireFighters as $fireFighter)';
html += '<option value="{{$fireFighter->id}}">{{ $fireFighter->name }} {{$fireFighter->surname }}</option>';
html += '@endforeach';
html += '</select>';
html += '<label for="location">Pojazd:</label>';
html += '<select name="operationVehicle[]" class="form-control">';
html += '<option value="">--- Wybierz pojazd ---</option>';
html += '@foreach ($vehicles as $vehicle)';
html += '<option value="{{$vehicle->id}}">{{ $vehicle->name }} {{$vehicle->codename }} {{$vehicle->registrationNumber }}</option>';
html += '@endforeach';
html += '</select>';
if(number > 1)
{
html += '<button type="button" name="remove" id="" class="btn btn-danger remove">Usuń</button></br></div>';
$('#drivers').append(html);
}
else
{
html += '<button type="button" name="add" id="add" class="btn btn-success">Dodaj</button></br></div>';
$('#drivers').html(html);
}
}
$(document).on('click', '#add', function(){
count++;
dynamic_field(count);
});
$(document).on('click', '.remove', function(){
count--;
$(this).closest("#singleDriver").remove();
});
{{--$('#dynamic_form').on('submit', function(event){--}}
{{-- event.preventDefault();--}}
{{-- $.ajax({--}}
{{-- url:'{{ route("operationController.store") }}',--}}
{{-- method:'post',--}}
{{-- data:$(this).serialize(),--}}
{{-- dataType:'json',--}}
{{-- beforeSend:function(){--}}
{{-- $('#save').attr('disabled','disabled');--}}
{{-- },--}}
{{-- success:function(data)--}}
{{-- {--}}
{{-- if(data.error)--}}
{{-- {--}}
{{-- var error_html = '';--}}
{{-- for(var count = 0; count < data.error.length; count++)--}}
{{-- {--}}
{{-- error_html += '<p>'+data.error[count]+'</p>';--}}
{{-- }--}}
{{-- $('#result').html('<div class="alert alert-danger">'+error_html+'</div>');--}}
{{-- }--}}
{{-- else--}}
{{-- {--}}
{{-- dynamic_field(1);--}}
{{-- $('#result').html('<div class="alert alert-success">'+data.success+'</div>');--}}
{{-- }--}}
{{-- $('#save').attr('disabled', false);--}}
{{-- }--}}
{{-- })--}}
{{--});--}}
});
</script>

View File

@ -32,7 +32,7 @@ Route::get('/pojazdy', function(){
Route::get('/wyjazdy', 'operationsController@create');
Route::get('/wyjazdy/add/', 'operationsController@addForm');
Route::post('/wyjazdy', 'operationsController@store');
Route::post('/wyjazdy', 'operationsController@store')->name('operationController.store');
Route::get('/register', 'RegistrationController@create');
Route::post('/register', 'RegistrationController@store');