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