2017-12-03 14:48:33 +08:00
|
|
|
@section('scripts')
|
2020-02-09 02:29:34 +08:00
|
|
|
<script>
|
|
|
|
const changeStatus = async (values, fn) => {
|
|
|
|
console.log('Changing PIREP ' + values.pirep_id + ' to state ' + values.new_status);
|
2018-03-15 07:14:35 +08:00
|
|
|
|
2020-02-09 02:29:34 +08:00
|
|
|
const opts = {
|
2019-08-30 20:08:00 +08:00
|
|
|
method: 'POST',
|
2018-03-15 07:14:35 +08:00
|
|
|
url: '{{url('/admin/pireps')}}/' + values.pirep_id + '/status',
|
2017-12-03 14:48:33 +08:00
|
|
|
data: values,
|
2020-02-09 02:29:34 +08:00
|
|
|
};
|
2019-08-30 20:08:00 +08:00
|
|
|
|
2020-02-09 02:29:34 +08:00
|
|
|
const response = await phpvms.request(opts);
|
|
|
|
fn(response.data);
|
|
|
|
};
|
2017-12-03 14:48:33 +08:00
|
|
|
|
2020-02-09 02:29:34 +08:00
|
|
|
$(document).ready(() => {
|
|
|
|
const select_id = "select#aircraft_select";
|
|
|
|
const destContainer = $('#fares_container');
|
2018-02-25 05:38:25 +08:00
|
|
|
|
2020-02-09 02:29:34 +08:00
|
|
|
$(select_id).change(async (e) => {
|
2018-02-25 05:38:25 +08:00
|
|
|
const aircraft_id = $(select_id + " option:selected").val();
|
|
|
|
console.log('aircraft select change: ', aircraft_id);
|
|
|
|
|
2019-08-30 20:08:00 +08:00
|
|
|
const response = await phpvms.request("{{ url('/admin/pireps/fares') }}?aircraft_id=" + aircraft_id);
|
|
|
|
console.log('returned new fares', response.data);
|
|
|
|
destContainer.html(response.data);
|
2020-02-09 02:29:34 +08:00
|
|
|
});
|
2018-02-25 05:38:25 +08:00
|
|
|
|
2020-02-09 02:29:34 +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});
|
2020-02-09 02:29:34 +08:00
|
|
|
});
|
2018-01-04 05:27:56 +08:00
|
|
|
|
2020-02-09 02:29:34 +08:00
|
|
|
$(document).on('pjax:complete', function () {
|
2018-04-07 06:10:45 +08:00
|
|
|
initPlugins();
|
2020-02-09 02:29:34 +08:00
|
|
|
});
|
2018-01-04 05:27:56 +08:00
|
|
|
|
2020-02-09 02:29:34 +08:00
|
|
|
/**
|
|
|
|
* Recalculate finances button is clicked
|
|
|
|
*/
|
|
|
|
$('button#recalculate-finances').on('click', async (event) => {
|
2018-03-06 03:07:10 +08:00
|
|
|
event.preventDefault();
|
|
|
|
console.log('Sending recalculate finances request');
|
|
|
|
const pirep_id = $(event.currentTarget).attr('data-pirep-id');
|
|
|
|
|
2019-08-30 20:08:00 +08:00
|
|
|
const opts = {
|
2020-02-09 02:29:34 +08:00
|
|
|
method: 'POST',
|
|
|
|
url: '{{url('/api/pireps')}}/' + pirep_id + '/finances/recalculate',
|
2019-08-30 20:08:00 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const response = await phpvms.request(opts);
|
|
|
|
console.log(response.data);
|
|
|
|
location.reload();
|
2020-02-09 02:29:34 +08:00
|
|
|
});
|
2018-03-06 03:07:10 +08:00
|
|
|
|
2020-02-09 02:29:34 +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 = {
|
2020-02-09 02:29:34 +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) => {
|
2020-02-09 02:29:34 +08:00
|
|
|
const destContainer = '#pirep_' + values.pirep_id + '_actionbar';
|
|
|
|
$(destContainer).html(data);
|
2020-10-26 22:18:00 +08:00
|
|
|
|
|
|
|
const statusContainer = '#pirep_' + values.pirep_id + '_status_container';
|
|
|
|
let new_badge;
|
|
|
|
let new_badge_text;
|
|
|
|
|
|
|
|
if (values.new_status === '{{ App\Models\Enums\PirepState::ACCEPTED }}') {
|
|
|
|
new_badge = 'badge badge-success';
|
|
|
|
new_badge_text = 'Accepted'
|
|
|
|
}
|
|
|
|
|
|
|
|
if (values.new_status === '{{ App\Models\Enums\PirepState::REJECTED }}') {
|
|
|
|
new_badge = 'badge badge-danger';
|
|
|
|
new_badge_text = 'Rejected'
|
|
|
|
}
|
|
|
|
|
|
|
|
$(statusContainer).children(0).removeClass().addClass(new_badge);
|
|
|
|
$(statusContainer).children(0).html(new_badge_text);
|
2018-02-07 02:58:48 +08:00
|
|
|
});
|
2020-02-09 02:29:34 +08:00
|
|
|
});
|
2017-12-03 14:48:33 +08:00
|
|
|
|
2020-02-09 02:29:34 +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 = {
|
2020-02-09 02:29:34 +08:00
|
|
|
pirep_id: $(event.currentTarget).attr('pirep_id'),
|
|
|
|
new_status: $(event.currentTarget).attr('new_status')
|
2018-03-06 20:17:45 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
console.log('change status', values);
|
|
|
|
|
|
|
|
changeStatus(values, (data) => {
|
2020-02-09 02:29:34 +08:00
|
|
|
location.reload();
|
2018-02-07 02:58:48 +08:00
|
|
|
});
|
2020-02-09 02:29:34 +08:00
|
|
|
});
|
2018-02-07 02:58:48 +08:00
|
|
|
|
2020-02-09 02:29:34 +08:00
|
|
|
});
|
|
|
|
</script>
|
2017-12-03 14:48:33 +08:00
|
|
|
@endsection
|