Set the baseURL for ajax requests (#373)

* Set the baseURL for ajax requests

* Use async/await on AJAX calls

* Add mix_public() cache generated asset cache busting

* Move storage container into separate class

* Fix some styling
This commit is contained in:
Nabeel S
2019-08-27 15:08:42 -04:00
committed by GitHub
parent fd2f4f2150
commit 09f3e3cfdf
16 changed files with 335 additions and 145 deletions

View File

@@ -1,41 +1,26 @@
@section('scripts')
<script>
$(document).ready(function () {
$("button.save_flight").click(function (e) {
$("button.save_flight").click(async function (e) {
e.preventDefault();
const btn = $(this);
const class_name = btn.attr('x-saved-class'); // classname to use is set on the element
const flight_id = btn.attr('x-id');
let params = {
url: '{{ url('/api/user/bids') }}',
data: {
'flight_id': btn.attr('x-id')
}
};
if (!btn.hasClass(class_name)) {
await phpvms.bids.addBid(flight_id);
if (btn.hasClass(class_name)) {
params.method = 'DELETE';
console.log('successfully saved flight');
btn.addClass(class_name);
alert('@lang("flights.bidadded")');
} else {
params.method = 'POST';
await phpvms.bids.removeBid(flight_id);
console.log('successfully removed flight');
btn.removeClass(class_name);
alert('@lang("flights.bidremoved")');
}
axios(params).then(response => {
console.log('save bid response', response);
if(params.method === 'DELETE') {
console.log('successfully removed flight');
btn.removeClass(class_name);
alert('@lang("flights.bidremoved")');
} else {
console.log('successfully saved flight');
btn.addClass(class_name);
alert('@lang("flights.bidadded")');
}
})
.catch(error => {
console.error('Error saving bid status', params, error);
});
});
});
</script>