* Refactor all JS API calls #360 * Remove unused imports * Lint JS * Fix doubled api key * Formatting * Added extra logging to distance lookup * Remove the .editorconfig file in distrib * shell check fixes * Remove the .editorconfig file in distrib
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
@section('scripts')
|
||||
<script>
|
||||
function setEditable() {
|
||||
|
||||
const token = $('meta[name="csrf-token"]').attr('content');
|
||||
const api_key = $('meta[name="api-key"]').attr('content');
|
||||
|
||||
|
||||
@@ -54,7 +54,6 @@ function setEditable() {
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
|
||||
const api_key = $('meta[name="api-key"]').attr('content');
|
||||
const csrf_token = $('meta[name="csrf-token"]').attr('content');
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ const changeParamDescription = (award_class) => {
|
||||
};
|
||||
|
||||
$(document).ready(() => {
|
||||
|
||||
const select_id = "select#award_class_select";
|
||||
console.log('award descriptions', award_descriptions);
|
||||
$(select_id).change((e) => {
|
||||
|
||||
@@ -30,8 +30,7 @@ const setEditable = () =>
|
||||
});
|
||||
};
|
||||
|
||||
const setFieldsEditable = () =>
|
||||
{
|
||||
const setFieldsEditable = () => {
|
||||
const api_key = $('meta[name="api-key"]').attr('content');
|
||||
const csrf_token = $('meta[name="csrf-token"]').attr('content');
|
||||
|
||||
@@ -59,11 +58,10 @@ const setFieldsEditable = () =>
|
||||
};
|
||||
|
||||
$(document).ready(function () {
|
||||
$("select#days_of_week").select2();
|
||||
|
||||
$("select#days_of_week").select2();
|
||||
|
||||
setEditable();
|
||||
setFieldsEditable();
|
||||
setEditable();
|
||||
setFieldsEditable();
|
||||
|
||||
const start_date_picker = new Pikaday({
|
||||
field: document.getElementById('start_date'),
|
||||
@@ -75,47 +73,49 @@ $(document).ready(function () {
|
||||
minDate: new Date(),
|
||||
});
|
||||
|
||||
$(document).on('submit', 'form.pjax_flight_fields', function (event) {
|
||||
event.preventDefault();
|
||||
$.pjax.submit(event, '#flight_fields_wrapper', {push: false});
|
||||
});
|
||||
$(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('submit', 'form.pjax_subfleet_form', function (event) {
|
||||
event.preventDefault();
|
||||
$.pjax.submit(event, '#subfleet_flight_wrapper', {push: false});
|
||||
});
|
||||
|
||||
$(document).on('submit', 'form.pjax_fares_form', function (event) {
|
||||
event.preventDefault();
|
||||
$.pjax.submit(event, '#flight_fares_wrapper', {push: false});
|
||||
});
|
||||
$(document).on('submit', 'form.pjax_fares_form', function (event) {
|
||||
event.preventDefault();
|
||||
$.pjax.submit(event, '#flight_fares_wrapper', {push: false});
|
||||
});
|
||||
|
||||
$(document).on('pjax:complete', function () {
|
||||
initPlugins();
|
||||
setEditable();
|
||||
setFieldsEditable();
|
||||
});
|
||||
$(document).on('pjax:complete', function () {
|
||||
initPlugins();
|
||||
setEditable();
|
||||
setFieldsEditable();
|
||||
});
|
||||
|
||||
$('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();
|
||||
if (fromIcao === '' || toIcao === '') {
|
||||
return;
|
||||
}
|
||||
$('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 + '"');
|
||||
|
||||
console.log(`Calculating from ${fromIcao} to ${toIcao}`);
|
||||
let response;
|
||||
if (fromIcao === '' || toIcao === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
response = await phpvms.calculate_distance(fromIcao, toIcao);
|
||||
} catch (e) {
|
||||
console.log('Error calculating distance:', e);
|
||||
return;
|
||||
}
|
||||
console.log(`Calculating from ${fromIcao} to ${toIcao}`);
|
||||
let response;
|
||||
|
||||
$("#distance").val(response.data.distance.nmi);
|
||||
});
|
||||
try {
|
||||
response = await phpvms.calculate_distance(fromIcao, toIcao);
|
||||
} catch (e) {
|
||||
console.log('Error calculating distance:', e);
|
||||
return;
|
||||
}
|
||||
|
||||
$("#distance").val(response.data.distance.nmi);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@endsection
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<td>{{ $fare->name }} ({{ $fare->code }})</td>
|
||||
<td>
|
||||
<div class="form-group">
|
||||
@if($pirep->read_only)
|
||||
@if(isset($pirep) && $pirep->read_only)
|
||||
<p>{{ $pirep->{'fare_'.$fare->id} }}</p>
|
||||
{{ Form::hidden('fare_'.$fare->id) }}
|
||||
@else
|
||||
@@ -19,7 +19,7 @@
|
||||
'class' => 'form-control',
|
||||
'min' => 0,
|
||||
'step' => '0.01',
|
||||
'readonly' => $pirep->read_only]) }}
|
||||
]) }}
|
||||
@endif
|
||||
</div>
|
||||
</td>
|
||||
|
||||
@@ -1,53 +1,29 @@
|
||||
@section('scripts')
|
||||
<script>
|
||||
const changeStatus = (values, fn) => {
|
||||
|
||||
const api_key = $('meta[name="api-key"]').attr('content');
|
||||
const token = $('meta[name="csrf-token"]').attr('content');
|
||||
|
||||
const changeStatus = async (values, fn) => {
|
||||
console.log('Changing PIREP ' + values.pirep_id + ' to state ' + values.new_status);
|
||||
|
||||
$.ajax({
|
||||
const opts = {
|
||||
method: 'POST',
|
||||
url: '{{url('/admin/pireps')}}/' + values.pirep_id + '/status',
|
||||
data: values,
|
||||
type: 'POST',
|
||||
headers: {
|
||||
'x-api-key': api_key,
|
||||
'X-CSRF-TOKEN': token,
|
||||
},
|
||||
success: function (data) {
|
||||
fn(data);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const response = await phpvms.request(opts);
|
||||
fn(response.data);
|
||||
};
|
||||
|
||||
$(document).ready(() => {
|
||||
|
||||
const api_key = $('meta[name="api-key"]').attr('content');
|
||||
const token = $('meta[name="csrf-token"]').attr('content');
|
||||
|
||||
const select_id = "select#aircraft_select";
|
||||
const destContainer = $('#fares_container');
|
||||
|
||||
$(select_id).change((e) => {
|
||||
$(select_id).change(async (e) => {
|
||||
const aircraft_id = $(select_id + " option:selected").val();
|
||||
console.log('aircraft select change: ', aircraft_id);
|
||||
|
||||
$.ajax({
|
||||
url: "{{ url('/admin/pireps/fares') }}?aircraft_id=" + aircraft_id,
|
||||
type: 'GET',
|
||||
headers: {
|
||||
'x-api-key': api_key,
|
||||
'X-CSRF-TOKEN': token,
|
||||
},
|
||||
success: (data) => {
|
||||
console.log('returned new fares', data);
|
||||
destContainer.html(data);
|
||||
},
|
||||
error: () => {
|
||||
destContainer.html('');
|
||||
}
|
||||
});
|
||||
const response = await phpvms.request("{{ url('/admin/pireps/fares') }}?aircraft_id=" + aircraft_id);
|
||||
console.log('returned new fares', response.data);
|
||||
destContainer.html(response.data);
|
||||
});
|
||||
|
||||
$(document).on('submit', 'form.pjax_form', (event) => {
|
||||
@@ -62,23 +38,19 @@ $(document).ready(() => {
|
||||
/**
|
||||
* Recalculate finances button is clicked
|
||||
*/
|
||||
$('button#recalculate-finances').on('click', (event) => {
|
||||
$('button#recalculate-finances').on('click', async (event) => {
|
||||
event.preventDefault();
|
||||
console.log('Sending recalculate finances request');
|
||||
const pirep_id = $(event.currentTarget).attr('data-pirep-id');
|
||||
|
||||
$.ajax({
|
||||
const opts = {
|
||||
method: 'POST',
|
||||
url: '{{url('/api/pireps')}}/' + pirep_id + '/finances/recalculate',
|
||||
type: 'POST',
|
||||
headers: {
|
||||
'x-api-key': api_key,
|
||||
'X-CSRF-TOKEN': token,
|
||||
},
|
||||
success: (data) => {
|
||||
console.log(data);
|
||||
location.reload();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const response = await phpvms.request(opts);
|
||||
console.log(response.data);
|
||||
location.reload();
|
||||
});
|
||||
|
||||
$(document).on('submit', 'form.pirep_submit_status', (event) => {
|
||||
|
||||
Reference in New Issue
Block a user