phpvms/resources/views/admin/airports/script.blade.php

133 lines
3.5 KiB
PHP
Raw Normal View History

2017-07-06 07:48:32 +08:00
@section('scripts')
<script>
function setEditable() {
const csrf_token = $('meta[name="csrf-token"]').attr('content');
const api_key = $('meta[name="api-key"]').attr('content');
@if(isset($airport))
$('#airport-expenses a.text').editable({
emptytext: '0',
url: '{{ url('/admin/airports/'.$airport->id.'/expenses') }}',
title: 'Enter override value',
ajaxOptions: {
type: 'post',
headers: {
'x-api-key': api_key,
'X-CSRF-TOKEN': csrf_token
}
},
params: function (params) {
return {
_method: 'put',
expense_id: params.pk,
name: params.name,
value: params.value
}
}
});
$('#airport-expenses a.dropdown').editable({
type: 'select',
emptytext: '0',
source: {!! json_encode(list_to_editable(\App\Models\Enums\ExpenseType::select())) !!},
url: '{{ url('/admin/airports/'.$airport->id.'/expenses') }}',
title: 'Enter override value',
ajaxOptions: {
type: 'post',
headers: {
'x-api-key': api_key,
'X-CSRF-TOKEN': csrf_token
}
},
params: function (params) {
return {
_method: 'put',
expense_id: params.pk,
name: params.name,
value: params.value
}
}
});
@endif
}
function phpvms_vacentral_airport_lookup(icao, callback) {
2018-03-29 12:04:53 +08:00
let params = {
method: 'GET',
2018-03-30 21:12:11 +08:00
url: '{{ url('/api/airports/') }}/' + icao + '/lookup',
2018-03-29 12:04:53 +08:00
};
2018-07-11 21:06:07 +08:00
axios(params)
.then(response => {
console.log(response);
callback(response.data);
});
}
2017-07-06 07:48:32 +08:00
$(document).ready(function() {
const api_key = $('meta[name="api-key"]').attr('content');
const csrf_token = $('meta[name="csrf-token"]').attr('content');
setEditable();
2017-07-06 07:48:32 +08:00
$('#airports-table a.inline').editable({
type: 'text',
mode: 'inline',
emptytext: '0',
url: '{{ url('/admin/airports/fuel') }}',
2017-07-06 07:48:32 +08:00
title: 'Enter price per unit of fuel',
ajaxOptions: {
type: 'post',
headers: {
'x-api-key': api_key,
'X-CSRF-TOKEN': csrf_token
}
},
2017-07-06 07:48:32 +08:00
params: function(params) {
return {
_method: 'put',
2017-07-06 07:48:32 +08:00
id: params.pk,
name: params.name,
value: params.value
}
}
});
$('a.airport_data_lookup').click(function(e) {
e.preventDefault();
const icao = $("input#airport_icao").val();
if(icao === '') {
return;
}
2018-03-29 12:04:53 +08:00
phpvms_vacentral_airport_lookup(icao, function(response) {
_.forEach(response.data, function(value, key) {
if(key === 'city') {
key = 'location';
}
$("#" + key).val(value);
if(key === 'tz') {
$("#timezone").val(value);
2018-02-07 00:59:31 +08:00
$("#timezone").trigger('change');
}
});
});
});
$(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();
setEditable();
});
2017-07-06 07:48:32 +08:00
});
</script>
@endsection