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

View File

@@ -246,13 +246,12 @@ class FlightController extends BaseController
}
/**
* @param $id
* @param Request $request
* @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);
if (empty($flight)) {
Flash::error('Flight not found');

View File

@@ -10,3 +10,4 @@
</div>
</div>
@endsection
@include('admin.flights.scripts')

View File

@@ -11,47 +11,16 @@
</div>
</div>
<h3>custom fields</h3>
<div class="card border-blue-bottom">
<div class="content">
@include('admin.flights.flight_fields')
</div>
</div>
<h3>assigned subfleets</h3>
<div class="card border-blue-bottom">
<div class="content">
@include('admin.flights.subfleets')
</div>
</div>
@endsection
@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_form', function (event) {
event.preventDefault();
$.pjax.submit(event, '#flight_fields_wrapper', {push: false});
});
$(document).on('pjax:complete', function() {
$(".select2").select2();
});
});
</script>
@endsection
@include('admin.flights.scripts')

View File

@@ -1,5 +1,5 @@
<div class="row"> <div class="col-12">
<div id="flight_fields_wrapper">
<h3>custom fields</h3><br />
<table class="table table-responsive" id="flight-fields-table">
<thead>
<th>Name</th>
@@ -16,7 +16,7 @@
<td style="width: 10%; text-align: center;" class="form-inline">
{!! Form::open(['url' => '/admin/flights/'.$flight->id.'/fields',
'method' => 'delete',
'class' => 'pjax_form flight_fields'
'class' => 'pjax_form pjax_flight_fields'
]) !!}
{!! Form::hidden('field_id', $field->id) !!}
<div class='btn-group'>
@@ -32,27 +32,27 @@
</tbody>
</table>
<hr/>
<div class="row pull-right">
{!! Form::open([
'url' => '/admin/flights/'.$flight->id.'/fields',
'method' => 'post',
'class' => 'pjax_form form-inline'
])
!!}
<div class="row">
<div class="col-md-12">
<div class="text-right">
{!! Form::open([
'url' => '/admin/flights/'.$flight->id.'/fields',
'method' => 'post',
'class' => 'pjax_form form-inline pjax_flight_fields'
])
!!}
<div class="form-group col-xs-12 form-inline">
{!! Form::label('name', 'Name:') !!}
{!! Form::text('name', null, ['class' => 'form-control']) !!}
&nbsp;&nbsp;
{!! Form::label('value', 'Value:') !!}
{!! Form::text('value', null, ['class' => 'form-control']) !!}
&nbsp;&nbsp;
{!! Form::button('<i class="glyphicon glyphicon-plus"></i> add',
['type' => 'submit',
'class' => 'btn btn-success btn-s']) !!}
{!! Form::label('name', 'Name:') !!}
{!! Form::text('name', null, ['class' => 'form-control']) !!}
&nbsp;&nbsp;
{!! Form::label('value', 'Value:') !!}
{!! Form::text('value', null, ['class' => 'form-control']) !!}
&nbsp;&nbsp;
{!! Form::button('<i class="glyphicon glyphicon-plus"></i> add',
['type' => 'submit',
'class' => 'btn btn-success btn-s']) !!}
{!! Form::close() !!}
</div>
</div>
{!! Form::close() !!}
</div>
</div>
</div> </div>

View File

@@ -24,4 +24,4 @@
</div>
</div>
@endsection
@include('admin.flights.scripts')

View File

@@ -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

View File

@@ -1,50 +1,55 @@
<div id="subfleet_flight_wrapper">
<table class="table table-responsive" id="aircrafts-table">
<thead>
<th>Type</th>
<th>Name</th>
<th style="text-align: center;">Actions</th>
</thead>
<tbody>
@foreach($flight->subfleets as $sf)
<tr>
<td>{!! $sf->type !!}</td>
<td>{!! $sf->name !!}</td>
<td style="width: 10%; text-align: center;" class="form-inline">
{!! Form::open(['url' => '/admin/flights/'.$flight->id.'/subfleets', 'method' => 'delete', 'class' => 'flight_subfleet']) !!}
{!! Form::hidden('subfleet_id', $sf->id) !!}
<div class='btn-group'>
{!! Form::button('<i class="glyphicon glyphicon-trash"></i>',
['type' => 'submit',
'class' => 'btn btn-danger btn-xs'])
!!}
</div>
<h3>assigned subfleets</h3>
<br />
<table class="table table-responsive" id="aircrafts-table">
<thead>
<th>Type</th>
<th>Name</th>
<th style="text-align: center;">Actions</th>
</thead>
<tbody>
@foreach($flight->subfleets as $sf)
<tr>
<td>{!! $sf->type !!}</td>
<td>{!! $sf->name !!}</td>
<td style="width: 10%; text-align: center;" class="form-inline">
{!! Form::open(['url' => '/admin/flights/'.$flight->id.'/subfleets',
'method' => 'delete',
'class' => 'pjax_subfleet_form']) !!}
{!! Form::hidden('subfleet_id', $sf->id) !!}
<div class='btn-group'>
{!! Form::button('<i class="glyphicon glyphicon-trash"></i>',
['type' => 'submit',
'class' => 'btn btn-danger btn-xs'])
!!}
</div>
{!! Form::close() !!}
</td>
</tr>
@endforeach
</tbody>
</table>
<hr/>
<div class="row">
<div class="col-xs-12">
<div class="text-right">
{!! Form::open([
'url' => '/admin/flights/'.$flight->id.'/subfleets',
'method' => 'post',
'class' => 'pjax_form form-inline pjax_subfleet_form'
])
!!}
{!! Form::select('subfleet_id', $avail_subfleets, null, [
'placeholder' => 'Select Subfleet',
'class' => 'select2_dropdown form-control input-lg',
])
!!}
{!! Form::button('<i class="glyphicon glyphicon-plus"></i> add',
['type' => 'submit',
'class' => 'btn btn-success btn-s']) !!}
{!! Form::close() !!}
</td>
</tr>
@endforeach
</tbody>
</table>
<hr/>
<div class="row">
<div class="col-xs-12">
<div class="input-group input-group-lg pull-right">
{!! Form::open([
'url' => '/admin/flights/'.$flight->id.'/subfleets',
'method' => 'post',
'class' => 'pjax_form form-inline'
])
!!}
{!! Form::select('subfleet_id', $avail_subfleets, null, [
'placeholder' => 'Select Subfleet',
'class' => 'select2_dropdown form-control input-lg',
])
!!}
{!! Form::button('<i class="glyphicon glyphicon-plus"></i> add',
['type' => 'submit',
'class' => 'btn btn-success btn-s']) !!}
{!! Form::close() !!}
</div>
</div>
</div>
</div>
</div>