#11 integrate pjax scaffold for form reload for deleting fares
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Http\Controllers\Admin;
|
||||
use App\Http\Requests\CreateAircraftRequest;
|
||||
use App\Http\Requests\UpdateAircraftRequest;
|
||||
use App\Repositories\AircraftRepository;
|
||||
use App\Repositories\FareRepository;
|
||||
use Illuminate\Http\Request;
|
||||
use Flash;
|
||||
use Prettus\Repository\Criteria\RequestCriteria;
|
||||
@@ -13,10 +14,11 @@ use Response;
|
||||
class AircraftController extends BaseController
|
||||
{
|
||||
/** @var AircraftRepository */
|
||||
private $aircraftRepository;
|
||||
private $aircraftRepository, $fareRepository;
|
||||
|
||||
public function __construct(AircraftRepository $aircraftRepo)
|
||||
public function __construct(AircraftRepository $aircraftRepo, FareRepository $fareRepo)
|
||||
{
|
||||
$this->fareRepository = $fareRepo;
|
||||
$this->aircraftRepository = $aircraftRepo;
|
||||
}
|
||||
|
||||
@@ -65,7 +67,14 @@ class AircraftController extends BaseController
|
||||
return redirect(route('admin.aircraft.index'));
|
||||
}
|
||||
|
||||
return view('admin.aircraft.show')->with('aircraft', $aircraft);
|
||||
$attached_fares = $aircraft->fares;
|
||||
$all_fares = $this->fareRepository->all();
|
||||
$avail_fares = $all_fares->except($attached_fares->modelKeys());
|
||||
|
||||
return view('admin.aircraft.show')
|
||||
->with('aircraft', $aircraft)
|
||||
->with('attached_fares', $attached_fares)
|
||||
->with('avail_fares', $avail_fares);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -121,6 +130,18 @@ class AircraftController extends BaseController
|
||||
return redirect(route('admin.aircraft.index'));
|
||||
}
|
||||
|
||||
protected function return_fares_view($aircraft)
|
||||
{
|
||||
$attached_fares = $aircraft->fares;
|
||||
$all_fares = $this->fareRepository->all();
|
||||
$avail_fares = $all_fares->except($attached_fares->modelKeys());
|
||||
|
||||
return view('admin.aircraft.fares')
|
||||
->with('aircraft', $aircraft)
|
||||
->with('attached_fares', $attached_fares)
|
||||
->with('avail_fares', $avail_fares);
|
||||
}
|
||||
|
||||
public function fares(Request $request)
|
||||
{
|
||||
$id = $request->id;
|
||||
@@ -132,12 +153,11 @@ class AircraftController extends BaseController
|
||||
|
||||
// associate or dissociate the fare with this aircraft
|
||||
if ($request->isMethod('post') || $request->isMethod('put')) {
|
||||
|
||||
// add
|
||||
} elseif ($request->isMethod('delete')) {
|
||||
|
||||
print_r($request->request);
|
||||
}
|
||||
|
||||
return view('admin.aircraft.fares')
|
||||
->with('fare', $aircraft->fares);
|
||||
return $this->return_fares_view($aircraft);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,7 +143,8 @@ return [
|
||||
'View' => Illuminate\Support\Facades\View::class,
|
||||
'Form' => Collective\Html\FormFacade::class,
|
||||
'Html' => Collective\Html\HtmlFacade::class,
|
||||
'Flash' => Laracasts\Flash\Flash::class
|
||||
'Flash' => Laracasts\Flash\Flash::class,
|
||||
'Yaml' => Symfony\Component\Yaml\Yaml::class,
|
||||
],
|
||||
|
||||
];
|
||||
|
||||
@@ -1,22 +1,60 @@
|
||||
<table class="table table-responsive" id="aircraft-fares-table">
|
||||
<thead>
|
||||
<th></th>
|
||||
<th colspan="3">Action</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach($fares as $fare)
|
||||
<tr>
|
||||
<td><a href="{!! route('admin.aircraft.show', [$ac->id]) !!}">{!! $ac->icao !!}</a></td>
|
||||
<td>
|
||||
{!! Form::open(['route' => ['admin.aircraft.destroy', $ac->id], 'method' => 'delete']) !!}
|
||||
<div class='btn-group'>
|
||||
<a href="{!! route('admin.aircraft.show', [$ac->id]) !!}" class='btn btn-default btn-xs'><i class="glyphicon glyphicon-eye-open"></i></a>
|
||||
<a href="{!! route('admin.aircraft.edit', [$ac->id]) !!}" class='btn btn-default btn-xs'><i class="glyphicon glyphicon-edit"></i></a>
|
||||
{!! Form::button('<i class="glyphicon glyphicon-trash"></i>', ['type' => 'submit', 'class' => 'btn btn-danger btn-xs', 'onclick' => "return confirm('Are you sure?')"]) !!}
|
||||
</div>
|
||||
{!! Form::close() !!}
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
<div id="aircraft_fares_wrapper" class="dataTables_wrapper form-inline dt-bootstrap">
|
||||
<table id="aircraft_fares"
|
||||
class="table table-bordered table-hover dataTable"
|
||||
role="grid" aria-describedby="aircraft_fares_info">
|
||||
<thead>
|
||||
<tr role="row">
|
||||
<th class="sorting" tabindex="0" aria-controls="aircraft_fares"
|
||||
rowspan="1" colspan="1"
|
||||
aria-label="name: activate to sort column ascending">
|
||||
name
|
||||
</th>
|
||||
<th class="sorting_asc" tabindex="0"
|
||||
aria-controls="aircraft_fares" rowspan="1" colspan="1"
|
||||
aria-sort="ascending"
|
||||
aria-label="code: activate to sort column descending">
|
||||
code
|
||||
</th>
|
||||
<th class="sorting" tabindex="0" aria-controls="aircraft_fares"
|
||||
rowspan="1" colspan="1"
|
||||
aria-label="capacity: activate to sort column ascending">
|
||||
capacity
|
||||
</th>
|
||||
<th class="sorting" tabindex="0" aria-controls="aircraft_fares"
|
||||
rowspan="1" colspan="1"
|
||||
aria-label="price: activate to sort column ascending">
|
||||
price
|
||||
</th>
|
||||
<th class="sorting" tabindex="0" aria-controls="aircraft_fares"
|
||||
rowspan="1" colspan="1"
|
||||
aria-label="cost: activate to sort column ascending">
|
||||
cost
|
||||
</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach($attached_fares as $atf)
|
||||
<tr role="row" class="@if ($loop->iteration%2) even @else odd @endif">
|
||||
<td class="sorting_1">{!! $atf->name !!}</td>
|
||||
<td>{!! $atf->code !!}</td>
|
||||
<td>{!! $atf->capacity !!}</td>
|
||||
<td>{!! $atf->price !!}</td>
|
||||
<td>{!! $atf->cost !!}</td>
|
||||
<td style="text-align: right; width:3%;">
|
||||
<div class='btn-group'>
|
||||
{!! Form::open(['url' => '/admin/aircraft/'.$aircraft->id.'/fares', 'method' => 'delete', 'class' => 'rm_fare']) !!}
|
||||
{!! Form::hidden('fare_id', $atf->id) !!}
|
||||
{!! Form::button('<i class="glyphicon glyphicon-trash"></i>',
|
||||
['type' => 'submit',
|
||||
'class' => 'btn btn-danger btn-s']) !!}
|
||||
{!! Form::close() !!}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
<hr />
|
||||
{!! $avail_fares !!}
|
||||
</div>
|
||||
|
||||
@@ -24,11 +24,13 @@
|
||||
|
||||
<!-- Active Field -->
|
||||
<div class="form-group col-sm-6">
|
||||
{!! Form::label('active', 'Active:') !!}
|
||||
<label class="checkbox-inline">
|
||||
{!! Form::hidden('active', false) !!}
|
||||
{!! Form::checkbox('active', '1', true) !!}
|
||||
</label>
|
||||
<div class="checkbox">
|
||||
<label class="checkbox-inline">
|
||||
{!! Form::hidden('active', false) !!}
|
||||
{!! Form::checkbox('active', '1', true) !!}
|
||||
{!! Form::label('active', 'Active') !!}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Submit Field -->
|
||||
@@ -36,3 +38,8 @@
|
||||
{!! Form::submit('Save', ['class' => 'btn btn-primary']) !!}
|
||||
<a href="{!! route('admin.aircraft.index') !!}" class="btn btn-default">Cancel</a>
|
||||
</div>
|
||||
<script>
|
||||
jQuery('input#active').iCheck('check');
|
||||
//$(document).ready(function() {
|
||||
//})
|
||||
</script>
|
||||
|
||||
@@ -1,19 +1,34 @@
|
||||
@extends('admin.app')
|
||||
|
||||
@section('content')
|
||||
<section class="content-header">
|
||||
<h1>
|
||||
Aircraft
|
||||
</h1>
|
||||
</section>
|
||||
<div class="content">
|
||||
<div class="box box-primary">
|
||||
<div class="box-body">
|
||||
<div class="row" style="padding-left: 20px">
|
||||
@include('admin.aircraft.show_fields')
|
||||
<a href="{!! route('admin.aircraft.index') !!}" class="btn btn-default">Back</a>
|
||||
<section class="content-header"><h1>{!! $aircraft->name !!}</section>
|
||||
<section class="content">
|
||||
<div class="row">
|
||||
@include('admin.aircraft.show_fields')
|
||||
</div>
|
||||
<div class="box box-primary">
|
||||
<div class="box-body">
|
||||
<div class="row">
|
||||
<div class="col-xs-12">
|
||||
<hr/>
|
||||
<h3 class="box-header">fares</h3>
|
||||
<div class="box-body">
|
||||
@include('admin.aircraft.fares')
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
@endsection
|
||||
@section('scripts')
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$(document).on('submit', 'form.rm_fare', function(event) {
|
||||
console.log('saving!');
|
||||
event.preventDefault();
|
||||
$.pjax.submit(event, '#aircraft_fares_wrapper', {push: false});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@endsection
|
||||
|
||||
@@ -1,36 +1,43 @@
|
||||
<!-- Icao Field -->
|
||||
<div class="form-group col-sm-6">
|
||||
{!! Form::label('icao', 'ICAO:') !!}
|
||||
<p>{!! $aircraft->icao !!}</p>
|
||||
<div class="box box-solid">
|
||||
<div class="box-header with-border">
|
||||
{{--<i class="fa fa-text-width"></i>--}}
|
||||
<h3 class="box-title">{!! Form::label('icao', 'ICAO:') !!}</h3>
|
||||
</div>
|
||||
<div class="box-body"><p class="lead">{!! $aircraft->icao !!}</p></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Name Field -->
|
||||
<div class="form-group col-sm-6">
|
||||
{!! Form::label('name', 'Name:') !!}
|
||||
<p>{!! $aircraft->name !!}</p>
|
||||
<div class="box box-solid">
|
||||
<div class="box-header with-border">
|
||||
{{--<i class="fa fa-text-width"></i>--}}
|
||||
<h3 class="box-title">{!! Form::label('name', 'Name:') !!}</h3>
|
||||
</div>
|
||||
<div class="box-body"><p class="lead">{!! $aircraft->name !!}</p></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Registration Field -->
|
||||
<div class="form-group col-sm-6">
|
||||
{!! Form::label('registration', 'Registration:') !!}
|
||||
<p>{!! $aircraft->registration !!}</p>
|
||||
<div class="box box-solid">
|
||||
<div class="box-header with-border">
|
||||
{{--<i class="fa fa-text-width"></i>--}}
|
||||
<h3 class="box-title">{!! Form::label('registration', 'Registration:') !!}</h3>
|
||||
</div>
|
||||
<div class="box-body"><p class="lead">{!! $aircraft->registration !!}</p></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Active Field -->
|
||||
<div class="form-group col-sm-6">
|
||||
{!! Form::label('active', 'Active:') !!}
|
||||
<p>{!! $aircraft->active !!}</p>
|
||||
<div class="box box-solid">
|
||||
<div class="box-header with-border">
|
||||
{{--<i class="fa fa-text-width"></i>--}}
|
||||
<h3 class="box-title">{!! Form::label('active', 'Active:') !!}</h3>
|
||||
</div>
|
||||
<div class="box-body"><p class="lead">@if ($aircraft->active == '1') yes @else no @endif</p></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Created At Field -->
|
||||
<div class="form-group col-sm-6">
|
||||
{!! Form::label('created_at', 'Created At:') !!}
|
||||
<p>{!! $aircraft->created_at !!}</p>
|
||||
</div>
|
||||
|
||||
<!-- Updated At Field -->
|
||||
<div class="form-group col-sm-6">
|
||||
{!! Form::label('updated_at', 'Updated At:') !!}
|
||||
<p>{!! $aircraft->updated_at !!}</p>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -174,10 +174,11 @@
|
||||
@endif
|
||||
|
||||
<!-- jQuery 2.1.4 -->
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
|
||||
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.2/js/select2.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/iCheck/1.0.2/icheck.min.js"></script>
|
||||
<script src="/vendor/pjax/jquery.pjax.js"></script>
|
||||
|
||||
<!-- AdminLTE App -->
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/admin-lte/2.3.3/js/app.min.js"></script>
|
||||
|
||||
Reference in New Issue
Block a user