/
scripts.blade.php
128 lines (116 loc) · 5.98 KB
/
scripts.blade.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
@section('scripts')
@if (setting('bids.block_aircraft', false))
<script>
$(document).ready(function() {
let aircrafts = [{
id: 0,
text: 'Loading Aircrafts...'
}];
let sel = $('#aircraft_select');
$("button.save_flight").click(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');
$('#aircraft_select').attr('x-saved-class', class_name)
$('#aircraft_select').attr('x-id', flight_id)
if (!btn.hasClass(class_name)) {
$('#bidModal').modal();
$.ajax({
headers: {
'X-API-KEY': $('meta[name="api-key"]').attr('content')
},
url: '{{ Config::get('app.url') }}/api/flights/' + flight_id +
'/aircraft'
}).then((response) => {
aircrafts = [];
const results = response.map(ac => {
const text =
`[${ac.icao}] ${ac.registration} ${ac.registration !== ac.name ? ` ${ac.name}` : ''}`;
aircrafts.push({
id: ac.id,
text: text
})
});
$('#aircraft_select option').remove();
sel.select2({
dropdownParent: $('#bidModal'),
data: aircrafts
});
});
} else {
phpvms.bids.removeBid(flight_id).then(() => {
console.log('successfully removed flight');
btn.removeClass(class_name);
alert('@lang('flights.bidremoved')');
}).catch((error) => {
if (error.response && error.response.data)
alert(`Error removing bid: ${error.response.data.details}`)
else alert(`Error removing bid: ${error.message}`)
});
}
});
$('#with_aircraft').click(() => {
const ac_id = $('#aircraft_select').val()
const flight_id = $('#aircraft_select').attr('x-id');
const class_name = $('#aircraft_select').attr('x-saved-class')
phpvms.bids.addBid(flight_id, ac_id).then(() => {
console.log('successfully saved flight');
$('button.save_flight[x-id="' + flight_id + '"]').addClass(class_name);
alert('@lang('flights.bidadded')');
}).catch((error) => {
if (error.response && error.response.data)
alert(`Error adding bid: ${error.response.data.details}`)
else alert(`Error adding bid: ${error.message}`)
});
});
$('#without_aircraft').click(async () => {
const flight_id = $('#aircraft_select').attr('x-id');
const class_name = $('#aircraft_select').attr('x-saved-class')
phpvms.bids.addBid(flight_id).then(() => {
console.log('successfully saved flight');
$('button.save_flight[x-id="' + flight_id + '"]').addClass(class_name);
alert('@lang('flights.bidadded')');
}).catch((error) => {
if (error.response && error.response.data) alert(
`Error adding bid: ${error.response.data.details}`)
else alert(`Error adding bid: ${error.message}`)
});
});
});
</script>
@else
<script>
$(document).ready(function() {
$("button.save_flight").click(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');
if (!btn.hasClass(class_name)) {
phpvms.bids.addBid(flight_id).then(() => {
console.log('successfully saved flight');
btn.addClass(class_name)
alert('@lang('flights.bidadded')');
}).catch((error) => {
if (error.response && error.response.data)
alert(`Error adding bid: ${error.response.data.details}`)
else alert(`Error adding bid: ${error.message}`)
});
} else {
phpvms.bids.removeBid(flight_id).then(() => {
console.log('successfully removed flight');
btn.removeClass(class_name);
alert('@lang('flights.bidremoved')');
}).catch((error) => {
if (error.response && error.response.data)
alert(`Error removing bid: ${error.response.data.details}`)
else alert(`Error removing bid: ${error.message}`)
});
}
});
});
</script>
@endif
@include('scripts.airport_search')
@endsection