2018-02-23 01:34:57 +08:00
|
|
|
@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
|
2018-02-23 01:34:57 +08:00
|
|
|
|
|
|
|
let params = {
|
2018-03-14 23:40:57 +08:00
|
|
|
url: '{{ url('/api/user/bids') }}',
|
2018-02-23 01:34:57 +08:00
|
|
|
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') {
|
2018-02-23 01:34:57 +08:00
|
|
|
console.log('successfully removed flight');
|
|
|
|
btn.removeClass(class_name);
|
|
|
|
alert('Your bid was removed');
|
2018-03-13 14:26:27 +08:00
|
|
|
} else {
|
2018-02-23 01:34:57 +08:00
|
|
|
console.log('successfully saved flight');
|
|
|
|
btn.addClass(class_name);
|
|
|
|
alert('Your bid was added');
|
|
|
|
}
|
2018-03-13 14:26:27 +08:00
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.error('Error saving bid status', params, error);
|
|
|
|
});
|
2018-02-23 01:34:57 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
@endsection
|