2017-07-06 07:48:32 +08:00
|
|
|
@section('scripts')
|
|
|
|
<script>
|
2018-03-06 12:10:00 +08:00
|
|
|
function setEditable() {
|
2018-03-13 14:48:47 +08:00
|
|
|
const csrf_token = $('meta[name="csrf-token"]').attr('content');
|
2018-03-13 14:55:14 +08:00
|
|
|
const api_key = $('meta[name="api-key"]').attr('content');
|
2018-03-13 14:48:47 +08:00
|
|
|
|
2018-03-06 12:10:00 +08:00
|
|
|
@if(isset($airport))
|
|
|
|
$('#airport-expenses a.text').editable({
|
|
|
|
emptytext: '0',
|
2018-03-13 06:58:12 +08:00
|
|
|
url: '{{ url('/admin/airports/'.$airport->id.'/expenses') }}',
|
2018-03-06 12:10:00 +08:00
|
|
|
title: 'Enter override value',
|
2018-03-13 14:48:47 +08:00
|
|
|
ajaxOptions: {
|
|
|
|
type: 'post',
|
|
|
|
headers: {
|
2018-03-13 14:55:14 +08:00
|
|
|
'x-api-key': api_key,
|
2018-03-13 14:48:47 +08:00
|
|
|
'X-CSRF-TOKEN': csrf_token
|
|
|
|
}
|
|
|
|
},
|
2018-03-06 12:10:00 +08:00
|
|
|
params: function (params) {
|
|
|
|
return {
|
2018-03-13 14:48:47 +08:00
|
|
|
_method: 'put',
|
2018-03-06 12:10:00 +08:00
|
|
|
expense_id: params.pk,
|
|
|
|
name: params.name,
|
|
|
|
value: params.value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#airport-expenses a.dropdown').editable({
|
|
|
|
type: 'select',
|
|
|
|
emptytext: '0',
|
2018-03-13 14:48:47 +08:00
|
|
|
source: {!! json_encode(list_to_editable(\App\Models\Enums\ExpenseType::select())) !!},
|
2018-03-13 06:58:12 +08:00
|
|
|
url: '{{ url('/admin/airports/'.$airport->id.'/expenses') }}',
|
2018-03-06 12:10:00 +08:00
|
|
|
title: 'Enter override value',
|
2018-03-13 14:48:47 +08:00
|
|
|
ajaxOptions: {
|
|
|
|
type: 'post',
|
|
|
|
headers: {
|
2018-03-13 14:55:14 +08:00
|
|
|
'x-api-key': api_key,
|
2018-03-13 14:48:47 +08:00
|
|
|
'X-CSRF-TOKEN': csrf_token
|
|
|
|
}
|
|
|
|
},
|
2018-03-06 12:10:00 +08:00
|
|
|
params: function (params) {
|
|
|
|
return {
|
2018-03-13 14:48:47 +08:00
|
|
|
_method: 'put',
|
2018-03-06 12:10:00 +08:00
|
|
|
expense_id: params.pk,
|
|
|
|
name: params.name,
|
|
|
|
value: params.value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
@endif
|
|
|
|
}
|
|
|
|
|
2017-07-06 07:48:32 +08:00
|
|
|
$(document).ready(function() {
|
2017-12-08 07:22:15 +08:00
|
|
|
|
2018-03-13 14:55:14 +08:00
|
|
|
const api_key = $('meta[name="api-key"]').attr('content');
|
2018-03-15 07:14:35 +08:00
|
|
|
const csrf_token = $('meta[name="csrf-token"]').attr('content');
|
2018-03-13 14:55:14 +08:00
|
|
|
|
2018-03-06 12:10:00 +08:00
|
|
|
setEditable();
|
|
|
|
|
2017-07-06 07:48:32 +08:00
|
|
|
$('#airports-table a.inline').editable({
|
|
|
|
type: 'text',
|
|
|
|
mode: 'inline',
|
|
|
|
emptytext: '0',
|
2018-03-13 06:58:12 +08:00
|
|
|
url: '{{ url('/admin/airports/fuel') }}',
|
2017-07-06 07:48:32 +08:00
|
|
|
title: 'Enter price per unit of fuel',
|
2018-03-13 14:48:47 +08:00
|
|
|
ajaxOptions: {
|
|
|
|
type: 'post',
|
|
|
|
headers: {
|
2018-03-13 14:55:14 +08:00
|
|
|
'x-api-key': api_key,
|
|
|
|
'X-CSRF-TOKEN': csrf_token
|
2018-03-13 14:48:47 +08:00
|
|
|
}
|
|
|
|
},
|
2017-07-06 07:48:32 +08:00
|
|
|
params: function(params) {
|
|
|
|
return {
|
2018-03-13 14:48:47 +08:00
|
|
|
_method: 'put',
|
2017-07-06 07:48:32 +08:00
|
|
|
id: params.pk,
|
|
|
|
name: params.name,
|
|
|
|
value: params.value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2017-12-08 07:22:15 +08:00
|
|
|
|
|
|
|
$('a.airport_data_lookup').click(function(e) {
|
|
|
|
e.preventDefault();
|
2018-02-11 06:10:19 +08:00
|
|
|
const icao = $("input#airport_icao").val();
|
2017-12-08 07:22:15 +08:00
|
|
|
if(icao === '') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-27 00:32:46 +08:00
|
|
|
phpvms.airport_lookup(icao, function(response) {
|
2018-03-29 12:04:53 +08:00
|
|
|
_.forEach(response.data, function(value, key) {
|
2017-12-08 07:22:15 +08:00
|
|
|
if(key === 'city') {
|
|
|
|
key = 'location';
|
|
|
|
}
|
|
|
|
|
|
|
|
$("#" + key).val(value);
|
|
|
|
|
2018-02-22 04:36:41 +08:00
|
|
|
if(key === 'tz') {
|
|
|
|
$("#timezone").val(value);
|
2018-02-07 00:59:31 +08:00
|
|
|
$("#timezone").trigger('change');
|
2017-12-08 07:22:15 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-03-06 12:10:00 +08:00
|
|
|
|
|
|
|
$(document).on('submit', 'form.modify_expense', function (event) {
|
|
|
|
event.preventDefault();
|
|
|
|
console.log(event);
|
|
|
|
$.pjax.submit(event, '#airport-expenses-wrapper', {push: false});
|
|
|
|
});
|
|
|
|
|
|
|
|
$(document).on('pjax:complete', function () {
|
2018-04-07 06:10:45 +08:00
|
|
|
initPlugins();
|
2018-03-06 12:10:00 +08:00
|
|
|
setEditable();
|
|
|
|
});
|
2017-07-06 07:48:32 +08:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
@endsection
|