Fix for subfleet add/remove on flight page #124

This commit is contained in:
Nabeel Shahzad
2018-01-07 08:58:57 -06:00
parent 6fdecc571a
commit c69e2c0cc8
7 changed files with 112 additions and 103 deletions
@@ -246,13 +246,12 @@ class FlightController extends BaseController
} }
/** /**
* @param $id
* @param Request $request * @param Request $request
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
*/ */
public function subfleets(Request $request) public function subfleets($id, Request $request)
{ {
$id = $request->id;
$flight = $this->flightRepo->findWithoutFail($id); $flight = $this->flightRepo->findWithoutFail($id);
if (empty($flight)) { if (empty($flight)) {
Flash::error('Flight not found'); Flash::error('Flight not found');
@@ -10,3 +10,4 @@
</div> </div>
</div> </div>
@endsection @endsection
@include('admin.flights.scripts')
+1 -32
View File
@@ -11,47 +11,16 @@
</div> </div>
</div> </div>
<h3>custom fields</h3>
<div class="card border-blue-bottom"> <div class="card border-blue-bottom">
<div class="content"> <div class="content">
@include('admin.flights.flight_fields') @include('admin.flights.flight_fields')
</div> </div>
</div> </div>
<h3>assigned subfleets</h3>
<div class="card border-blue-bottom"> <div class="card border-blue-bottom">
<div class="content"> <div class="content">
@include('admin.flights.subfleets') @include('admin.flights.subfleets')
</div> </div>
</div> </div>
@endsection @endsection
@section('scripts') @include('admin.flights.scripts')
<script>
$(document).ready(function () {
$('#flight_fields_wrapper a.inline').editable({
type: 'text',
mode: 'inline',
emptytext: '0',
url: '/admin/flights/{!! $flight->id !!}/fields',
ajaxOptions: {'type': 'put'},
params: function(params) {
return {
field_id: params.pk,
name: params.name,
value: params.value
}
}
});
$(document).on('submit', 'form.pjax_form', function (event) {
event.preventDefault();
$.pjax.submit(event, '#flight_fields_wrapper', {push: false});
});
$(document).on('pjax:complete', function() {
$(".select2").select2();
});
});
</script>
@endsection
@@ -1,5 +1,5 @@
<div class="row"> <div class="col-12">
<div id="flight_fields_wrapper"> <div id="flight_fields_wrapper">
<h3>custom fields</h3><br />
<table class="table table-responsive" id="flight-fields-table"> <table class="table table-responsive" id="flight-fields-table">
<thead> <thead>
<th>Name</th> <th>Name</th>
@@ -16,7 +16,7 @@
<td style="width: 10%; text-align: center;" class="form-inline"> <td style="width: 10%; text-align: center;" class="form-inline">
{!! Form::open(['url' => '/admin/flights/'.$flight->id.'/fields', {!! Form::open(['url' => '/admin/flights/'.$flight->id.'/fields',
'method' => 'delete', 'method' => 'delete',
'class' => 'pjax_form flight_fields' 'class' => 'pjax_form pjax_flight_fields'
]) !!} ]) !!}
{!! Form::hidden('field_id', $field->id) !!} {!! Form::hidden('field_id', $field->id) !!}
<div class='btn-group'> <div class='btn-group'>
@@ -32,16 +32,16 @@
</tbody> </tbody>
</table> </table>
<hr/> <hr/>
<div class="row pull-right"> <div class="row">
<div class="col-md-12">
<div class="text-right">
{!! Form::open([ {!! Form::open([
'url' => '/admin/flights/'.$flight->id.'/fields', 'url' => '/admin/flights/'.$flight->id.'/fields',
'method' => 'post', 'method' => 'post',
'class' => 'pjax_form form-inline' 'class' => 'pjax_form form-inline pjax_flight_fields'
]) ])
!!} !!}
<div class="form-group col-xs-12 form-inline">
{!! Form::label('name', 'Name:') !!} {!! Form::label('name', 'Name:') !!}
{!! Form::text('name', null, ['class' => 'form-control']) !!} {!! Form::text('name', null, ['class' => 'form-control']) !!}
&nbsp;&nbsp; &nbsp;&nbsp;
@@ -51,8 +51,8 @@
{!! Form::button('<i class="glyphicon glyphicon-plus"></i> add', {!! Form::button('<i class="glyphicon glyphicon-plus"></i> add',
['type' => 'submit', ['type' => 'submit',
'class' => 'btn btn-success btn-s']) !!} 'class' => 'btn btn-success btn-s']) !!}
</div>
{!! Form::close() !!} {!! Form::close() !!}
</div> </div>
</div> </div>
</div> </div> </div>
</div>
@@ -24,4 +24,4 @@
</div> </div>
</div> </div>
@endsection @endsection
@include('admin.flights.scripts')
@@ -0,0 +1,35 @@
@section('scripts')
<script>
$(document).ready(function () {
$('#flight_fields_wrapper a.inline').editable({
type: 'text',
mode: 'inline',
emptytext: '0',
url: '/admin/flights/{!! $flight->id !!}/fields',
ajaxOptions: {'type': 'put'},
params: function (params) {
return {
field_id: params.pk,
name: params.name,
value: params.value
}
}
});
$(document).on('submit', 'form.pjax_flight_fields', function (event) {
event.preventDefault();
$.pjax.submit(event, '#flight_fields_wrapper', {push: false});
});
$(document).on('submit', 'form.pjax_subfleet_form', function (event) {
event.preventDefault();
$.pjax.submit(event, '#subfleet_flight_wrapper', {push: false});
});
$(document).on('pjax:complete', function () {
$(".select2").select2();
});
});
</script>
@endsection
@@ -1,4 +1,7 @@
<div id="subfleet_flight_wrapper"> <div id="subfleet_flight_wrapper">
<h3>assigned subfleets</h3>
<br />
<table class="table table-responsive" id="aircrafts-table"> <table class="table table-responsive" id="aircrafts-table">
<thead> <thead>
<th>Type</th> <th>Type</th>
@@ -11,7 +14,9 @@
<td>{!! $sf->type !!}</td> <td>{!! $sf->type !!}</td>
<td>{!! $sf->name !!}</td> <td>{!! $sf->name !!}</td>
<td style="width: 10%; text-align: center;" class="form-inline"> <td style="width: 10%; text-align: center;" class="form-inline">
{!! Form::open(['url' => '/admin/flights/'.$flight->id.'/subfleets', 'method' => 'delete', 'class' => 'flight_subfleet']) !!} {!! Form::open(['url' => '/admin/flights/'.$flight->id.'/subfleets',
'method' => 'delete',
'class' => 'pjax_subfleet_form']) !!}
{!! Form::hidden('subfleet_id', $sf->id) !!} {!! Form::hidden('subfleet_id', $sf->id) !!}
<div class='btn-group'> <div class='btn-group'>
{!! Form::button('<i class="glyphicon glyphicon-trash"></i>', {!! Form::button('<i class="glyphicon glyphicon-trash"></i>',
@@ -28,11 +33,11 @@
<hr/> <hr/>
<div class="row"> <div class="row">
<div class="col-xs-12"> <div class="col-xs-12">
<div class="input-group input-group-lg pull-right"> <div class="text-right">
{!! Form::open([ {!! Form::open([
'url' => '/admin/flights/'.$flight->id.'/subfleets', 'url' => '/admin/flights/'.$flight->id.'/subfleets',
'method' => 'post', 'method' => 'post',
'class' => 'pjax_form form-inline' 'class' => 'pjax_form form-inline pjax_subfleet_form'
]) ])
!!} !!}
{!! Form::select('subfleet_id', $avail_subfleets, null, [ {!! Form::select('subfleet_id', $avail_subfleets, null, [