phpvms/resources/views/layouts/default/flights/scripts.blade.php

43 lines
1.2 KiB
PHP
Raw Normal View History

@section('scripts')
<script>
$(document).ready(function () {
$("button.save_flight").click(function (e) {
e.preventDefault();
const btn = $(this);
2018-03-13 14:26:27 +08:00
const class_name = btn.attr('x-saved-class'); // classname to use is set on the element
let params = {
url: '{{ url('/api/user/bids') }}',
data: {
'flight_id': btn.attr('x-id')
}
};
if (btn.hasClass(class_name)) {
params.method = 'DELETE';
2018-03-13 14:26:27 +08:00
} else {
params.method = 'POST';
}
axios(params).then(response => {
console.log('save bid response', response);
if(params.method === 'DELETE') {
console.log('successfully removed flight');
btn.removeClass(class_name);
2018-05-18 06:03:30 +08:00
alert('@lang("frontend.flights.bidremoved")');
2018-03-13 14:26:27 +08:00
} else {
console.log('successfully saved flight');
btn.addClass(class_name);
2018-05-18 06:03:30 +08:00
alert('@lang("frontend.flights.bidadded")');
}
2018-03-13 14:26:27 +08:00
})
.catch(error => {
console.error('Error saving bid status', params, error);
});
});
});
</script>
@endsection