Add flight fields for templated fields on edit flight #213

This commit is contained in:
Nabeel Shahzad
2018-03-20 13:47:47 -05:00
parent 485c6e86bb
commit 25a299fb74
13 changed files with 337 additions and 53 deletions

View File

@@ -9,23 +9,27 @@
</thead>
@endif
<tbody>
@foreach($flight->field_values as $field)
@foreach($flight_fields as $field)
@php
$val_field = $flight->field_values->where('name', $field->name)->first();
@endphp
<tr>
<td>{{ $field->name }}</td>
<td>
<a class="inline" href="#" data-pk="{{ $field->id }}" data-name="{{ $field->name }}">{{ $field->value }}</a>
<a class="inline" href="#" data-pk="{{ $val_field['id'] ?? '' }}" data-name="{{ $field->name }}">
{{ $val_field['value'] ?? '' }}
</a>
</td>
<td style="width: 10%; text-align: center;" class="form-inline">
{{ Form::open(['url' => '/admin/flights/'.$flight->id.'/fields',
'method' => 'delete',
'class' => 'pjax_form pjax_flight_fields'
]) }}
{{ Form::hidden('field_id', $field->id) }}
{{ Form::hidden('field_id', $val_field['id'] ?? null) }}
<div class='btn-group'>
{{ Form::button('<i class="fa fa-times"></i>',
['type' => 'submit',
'class' => 'btn btn-danger btn-xs'])
}}
['type' => 'submit', 'class' => 'btn btn-sm btn-danger btn-icon',
'onclick' => "return confirm('Are you sure?')"]) }}
</div>
{{ Form::close() }}
</td>

View File

@@ -2,10 +2,11 @@
@section('title', 'Flights')
@section('actions')
<li><a href="{{ route('admin.flightfields.index') }}"><i class="ti-plus"></i>Fields</a></li>
<li>
<a href="{{ route('admin.flights.create') }}">
<i class="ti-plus"></i>
Add New</a>
Add Flight</a>
</li>
@endsection

View File

@@ -1,8 +1,8 @@
@section('scripts')
<script>
function setEditable() {
const setEditable = () =>
{
const api_key = $('meta[name="api-key"]').attr('content');
const csrf_token = $('meta[name="csrf-token"]').attr('content');
@@ -28,19 +28,17 @@ function setEditable() {
}
}
});
}
};
$(document).ready(function () {
const csrf_token = $('meta[name="csrf-token"]').attr('content');
const setFieldsEditable = () =>
{
const api_key = $('meta[name="api-key"]').attr('content');
setEditable();
const csrf_token = $('meta[name="csrf-token"]').attr('content');
$('#flight_fields_wrapper a.inline').editable({
type: 'text',
mode: 'inline',
emptytext: '0',
emptytext: 'no value',
url: '{{ url('/admin/flights/'.$flight->id.'/fields') }}',
ajaxOptions: {
type: 'post',
@@ -58,29 +56,32 @@ $(document).ready(function () {
}
}
});
};
$(document).ready(function () {
setEditable();
setFieldsEditable();
$(document).on('submit', 'form.pjax_flight_fields', function (event) {
event.preventDefault();
$.pjax.submit(event, '#flight_fields_wrapper', {push: false});
setEditable();
});
$(document).on('submit', 'form.pjax_subfleet_form', function (event) {
event.preventDefault();
$.pjax.submit(event, '#subfleet_flight_wrapper', {push: false});
setEditable();
});
$(document).on('submit', 'form.pjax_fares_form', function (event) {
event.preventDefault();
console.log(event);
$.pjax.submit(event, '#flight_fares_wrapper', {push: false});
setEditable();
});
$(document).on('pjax:complete', function () {
$(".select2").select2();
setEditable();
setFieldsEditable();
});
});
</script>