2018-01-07 22:58:57 +08:00
|
|
|
@section('scripts')
|
|
|
|
<script>
|
2018-01-08 00:38:16 +08:00
|
|
|
|
2018-03-21 02:47:47 +08:00
|
|
|
const setEditable = () =>
|
|
|
|
{
|
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-01-08 00:38:16 +08:00
|
|
|
$('#flight_fares a').editable({
|
|
|
|
type: 'text',
|
|
|
|
mode: 'inline',
|
|
|
|
emptytext: 'inherited',
|
2018-03-13 06:58:12 +08:00
|
|
|
url: '{{ url('/admin/flights/'.$flight->id.'/fares') }}',
|
2018-01-08 00:38:16 +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,
|
|
|
|
'X-CSRF-TOKEN': csrf_token
|
2018-03-13 14:48:47 +08:00
|
|
|
}
|
|
|
|
},
|
2018-01-08 00:38:16 +08:00
|
|
|
params: function (params) {
|
|
|
|
return {
|
2018-03-13 14:48:47 +08:00
|
|
|
_method: 'put',
|
2018-01-08 00:38:16 +08:00
|
|
|
fare_id: params.pk,
|
|
|
|
name: params.name,
|
|
|
|
value: params.value
|
2018-01-07 22:58:57 +08:00
|
|
|
}
|
2018-01-08 00:38:16 +08:00
|
|
|
}
|
|
|
|
});
|
2018-03-21 02:47:47 +08:00
|
|
|
};
|
2018-01-07 22:58:57 +08:00
|
|
|
|
2019-08-30 20:08:00 +08:00
|
|
|
const setFieldsEditable = () => {
|
2018-03-13 14:55:14 +08:00
|
|
|
const api_key = $('meta[name="api-key"]').attr('content');
|
2018-03-21 02:47:47 +08:00
|
|
|
const csrf_token = $('meta[name="csrf-token"]').attr('content');
|
2018-01-08 00:38:16 +08:00
|
|
|
|
|
|
|
$('#flight_fields_wrapper a.inline').editable({
|
|
|
|
type: 'text',
|
|
|
|
mode: 'inline',
|
2018-03-21 02:47:47 +08:00
|
|
|
emptytext: 'no value',
|
2018-03-15 07:14:35 +08:00
|
|
|
url: '{{ url('/admin/flights/'.$flight->id.'/fields') }}',
|
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
|
|
|
}
|
|
|
|
},
|
2018-01-08 00:38:16 +08:00
|
|
|
params: function (params) {
|
|
|
|
return {
|
2018-03-13 14:48:47 +08:00
|
|
|
_method: 'put',
|
2018-01-08 00:38:16 +08:00
|
|
|
field_id: params.pk,
|
|
|
|
name: params.name,
|
|
|
|
value: params.value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2018-03-21 02:47:47 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
$(document).ready(function () {
|
2019-08-30 20:08:00 +08:00
|
|
|
$("select#days_of_week").select2();
|
2018-03-21 02:47:47 +08:00
|
|
|
|
2019-08-30 20:08:00 +08:00
|
|
|
setEditable();
|
|
|
|
setFieldsEditable();
|
2018-01-07 22:58:57 +08:00
|
|
|
|
2018-04-10 08:32:38 +08:00
|
|
|
const start_date_picker = new Pikaday({
|
|
|
|
field: document.getElementById('start_date'),
|
|
|
|
minDate: new Date(),
|
|
|
|
});
|
2018-03-24 04:02:26 +08:00
|
|
|
|
2018-04-10 08:32:38 +08:00
|
|
|
const end_date_picker = new Pikaday({
|
|
|
|
field: document.getElementById('end_date'),
|
|
|
|
minDate: new Date(),
|
|
|
|
});
|
2018-03-24 03:10:18 +08:00
|
|
|
|
2019-08-30 20:08:00 +08:00
|
|
|
$(document).on('submit', 'form.pjax_flight_fields', function (event) {
|
|
|
|
event.preventDefault();
|
|
|
|
$.pjax.submit(event, '#flight_fields_wrapper', {push: false});
|
|
|
|
});
|
2018-01-08 00:38:16 +08:00
|
|
|
|
2019-08-30 20:08:00 +08:00
|
|
|
$(document).on('submit', 'form.pjax_subfleet_form', function (event) {
|
|
|
|
event.preventDefault();
|
|
|
|
$.pjax.submit(event, '#subfleet_flight_wrapper', {push: false});
|
|
|
|
});
|
2018-01-08 00:38:16 +08:00
|
|
|
|
2019-08-30 20:08:00 +08:00
|
|
|
$(document).on('submit', 'form.pjax_fares_form', function (event) {
|
|
|
|
event.preventDefault();
|
|
|
|
$.pjax.submit(event, '#flight_fares_wrapper', {push: false});
|
|
|
|
});
|
2018-01-07 22:58:57 +08:00
|
|
|
|
2019-08-30 20:08:00 +08:00
|
|
|
$(document).on('pjax:complete', function () {
|
|
|
|
initPlugins();
|
|
|
|
setEditable();
|
|
|
|
setFieldsEditable();
|
|
|
|
});
|
2019-08-27 00:32:46 +08:00
|
|
|
|
2019-08-30 20:08:00 +08:00
|
|
|
$('a.airport_distance_lookup').click(async function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
const fromIcao = $("select#dpt_airport_id option:selected").val();
|
|
|
|
const toIcao = $("select#arr_airport_id option:selected").val();
|
|
|
|
console.log('fromIcao="' + fromIcao + '", toIcao="' + toIcao + '"');
|
2019-08-27 00:32:46 +08:00
|
|
|
|
2019-08-30 20:08:00 +08:00
|
|
|
if (fromIcao === '' || toIcao === '') {
|
|
|
|
return;
|
|
|
|
}
|
2019-08-28 03:08:42 +08:00
|
|
|
|
2019-08-30 20:08:00 +08:00
|
|
|
console.log(`Calculating from ${fromIcao} to ${toIcao}`);
|
|
|
|
let response;
|
2019-08-28 03:08:42 +08:00
|
|
|
|
2019-08-30 20:08:00 +08:00
|
|
|
try {
|
|
|
|
response = await phpvms.calculate_distance(fromIcao, toIcao);
|
|
|
|
} catch (e) {
|
|
|
|
console.log('Error calculating distance:', e);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$("#distance").val(response.data.distance.nmi);
|
|
|
|
});
|
2018-01-08 00:38:16 +08:00
|
|
|
});
|
2018-01-07 22:58:57 +08:00
|
|
|
</script>
|
|
|
|
@endsection
|