2017-12-03 14:48:33 +08:00
|
|
|
@section('scripts')
|
|
|
|
<script>
|
2018-02-07 02:58:48 +08:00
|
|
|
const changeStatus = (values, fn) => {
|
|
|
|
console.log('Changing PIREP ' + values.pirep_id + ' to state ' + values.new_status);
|
2017-12-03 14:48:33 +08:00
|
|
|
$.ajax({
|
2018-01-03 00:59:44 +08:00
|
|
|
url: BASE_URL + '/admin/pireps/' + values.pirep_id + '/status',
|
2017-12-03 14:48:33 +08:00
|
|
|
data: values,
|
|
|
|
type: 'POST',
|
2018-01-03 00:50:41 +08:00
|
|
|
headers: {
|
|
|
|
'x-api-key': PHPVMS_USER_API_KEY
|
|
|
|
},
|
2017-12-03 14:48:33 +08:00
|
|
|
success: function (data) {
|
2018-02-07 02:58:48 +08:00
|
|
|
fn(data);
|
2017-12-03 14:48:33 +08:00
|
|
|
}
|
|
|
|
});
|
2018-02-07 02:58:48 +08:00
|
|
|
};
|
2017-12-03 14:48:33 +08:00
|
|
|
|
2018-03-06 03:07:10 +08:00
|
|
|
$(document).ready(() => {
|
2018-01-04 05:27:56 +08:00
|
|
|
|
2018-02-25 05:38:25 +08:00
|
|
|
const select_id = "select#aircraft_select";
|
|
|
|
const destContainer = $('#fares_container');
|
|
|
|
|
|
|
|
$(select_id).change((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': '{!! Auth::user()->api_key !!}'
|
|
|
|
},
|
|
|
|
success: (data) => {
|
|
|
|
console.log('returned new fares', data);
|
|
|
|
destContainer.html(data);
|
|
|
|
},
|
|
|
|
error: () => {
|
|
|
|
destContainer.html('');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-03-06 03:07:10 +08:00
|
|
|
$(document).on('submit', 'form.pjax_form', (event) => {
|
2018-01-04 05:27:56 +08:00
|
|
|
event.preventDefault();
|
|
|
|
$.pjax.submit(event, '#pirep_comments_wrapper', {push: false});
|
|
|
|
});
|
|
|
|
|
|
|
|
$(document).on('pjax:complete', function () {
|
|
|
|
$(".select2").select2();
|
|
|
|
});
|
|
|
|
|
2018-03-06 03:07:10 +08:00
|
|
|
/**
|
|
|
|
* Recalculate finances button is clicked
|
|
|
|
*/
|
|
|
|
$('button#recalculate-finances').on('click', (event) => {
|
|
|
|
event.preventDefault();
|
|
|
|
console.log('Sending recalculate finances request');
|
|
|
|
const pirep_id = $(event.currentTarget).attr('data-pirep-id');
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: BASE_URL + '/api/pireps/' + pirep_id + '/finances/recalculate',
|
|
|
|
type: 'POST',
|
|
|
|
headers: {
|
|
|
|
'x-api-key': PHPVMS_USER_API_KEY
|
|
|
|
},
|
|
|
|
success: (data) => {
|
|
|
|
console.log(data);
|
2018-03-06 03:15:47 +08:00
|
|
|
location.reload();
|
2018-03-06 03:07:10 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
$(document).on('submit', 'form.pirep_submit_status', (event) => {
|
2017-12-03 14:48:33 +08:00
|
|
|
event.preventDefault();
|
2018-01-04 10:39:24 +08:00
|
|
|
const values = {
|
2018-03-06 20:17:45 +08:00
|
|
|
pirep_id: $(event.currentTarget).attr('pirep_id'),
|
|
|
|
new_status: $(event.currentTarget).attr('new_status')
|
2017-12-03 14:48:33 +08:00
|
|
|
};
|
|
|
|
|
2018-03-06 20:17:45 +08:00
|
|
|
console.log('change status', values);
|
|
|
|
|
2018-02-07 02:58:48 +08:00
|
|
|
changeStatus(values, (data) => {
|
|
|
|
const destContainer = '#pirep_' + values.pirep_id + '_actionbar';
|
|
|
|
$(destContainer).html(data);
|
|
|
|
});
|
|
|
|
});
|
2017-12-03 14:48:33 +08:00
|
|
|
|
2018-03-06 03:07:10 +08:00
|
|
|
$(document).on('submit', 'form.pirep_change_status', (event) => {
|
2018-02-07 02:58:48 +08:00
|
|
|
event.preventDefault();
|
2018-03-06 20:17:45 +08:00
|
|
|
|
|
|
|
const values = {
|
|
|
|
pirep_id: $(event.currentTarget).attr('pirep_id'),
|
|
|
|
new_status: $(event.currentTarget).attr('new_status')
|
|
|
|
};
|
|
|
|
|
|
|
|
console.log('change status', values);
|
|
|
|
|
|
|
|
changeStatus(values, (data) => {
|
2018-02-07 02:58:48 +08:00
|
|
|
location.reload();
|
|
|
|
});
|
2017-12-03 14:48:33 +08:00
|
|
|
});
|
2018-02-07 02:58:48 +08:00
|
|
|
|
2018-01-03 00:53:25 +08:00
|
|
|
});
|
2017-12-03 14:48:33 +08:00
|
|
|
</script>
|
|
|
|
@endsection
|