This repository has been archived by the owner on May 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
JomLetsGo.html
575 lines (562 loc) · 31.7 KB
/
JomLetsGo.html
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Jom Let's Go</title>
<!-- Include Vue.js -->
<script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
<!-- Include Axios -->
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<!--Include Bootstrap-->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<style>
#map {
height: 400px; /* The height is 400 pixels */
width: 100%; /* The width is the width of the web page */
}
</style>
</head>
<body class="m-0">
<div id="app">
<nav class="navbar navbar-expand-lg" style="background-color: lightblue;">
<div class="container-fluid">
<a class="navbar-brand" href="#">JomLet'sGo</a>
<div class="vr me-2"></div>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<button type="button" class="nav-link active" @click="page='carSearch';selectedCar=null">Car Search</button>
</li>
<li class="nav-item">
<button type="button" class="nav-link active" @click="page='bookingDetails'; console.log(page)">Booking Details</button>
</li>
</div>
</div>
</nav>
<div v-if="page == 'carSearch'">
<div class="ps-3 pt-3">
<button class="btn btn-primary" @click="searchForNearestCar" v-if="carsList.length == 0">Search for car</button>
<button class="btn btn-primary" @click="searchForNearestCar" v-else>Refresh cars list</button> <!--v-if="!carsList"-->
</div>
<hr>
<div class="ps-3 pt-1 mb-4" v-if="carsList.length > 0">
<div class="mb-3">
<div id="map" class="mb-3"></div>
<h5 class="d-inline">Cars Found:</h5>
<button class="btn btn-sm btn-secondary ms-3" @click="showFilter">Filter</button>
<button class="btn btn-primary dropdown-toggle btn-sm float-end me-5" type="button" data-bs-toggle="dropdown" aria-expanded="false">
Sort by
</button>
<ul class="dropdown-menu">
<li><button class="dropdown-item" type="button" @click="applySort('price', 'ascending')">Price ascending</button></li>
<li><button class="dropdown-item" type="button" @click="applySort('price', 'descending')">Price descending</button></li>
<li><button class="dropdown-item" type="button" @click="applySort('distance', 'ascending')">Closest</button></li>
<li><button class="dropdown-item" type="button" @click="applySort('distance', 'descending')">Furthest</button></li>
</ul>
</div>
<hr>
<div v-if="filter" class="mb-3">
<div class="dropdown">
<button class="btn btn-warning dropdown-toggle btn-sm mb-3" type="button" data-bs-toggle="dropdown" aria-expanded="false">
Brand
</button>
<ul class="dropdown-menu">
<li v-for="option in brandOptions">
<button type="button" class="dropdown-item" @click="applyFilter('brand',option)">{{option}} <span v-if="selectedBrand == option" class="float-end"><svg style="color:green" xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-check2" viewBox="0 0 16 16">
<path d="M13.854 3.646a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708 0l-3.5-3.5a.5.5 0 1 1 .708-.708L6.5 10.293l6.646-6.647a.5.5 0 0 1 .708 0"/>
</svg></span></button>
</li>
</ul>
<button class="btn btn-warning dropdown-toggle btn-sm mb-3" type="button" data-bs-toggle="dropdown" aria-expanded="false">
Type
</button>
<ul class="dropdown-menu">
<li v-for="option in typeOptions">
<button type="button" class="dropdown-item" @click="applyFilter('type',option)">{{option}} <span v-if="selectedType == option" class="float-end"><svg style="color:green" xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-check2" viewBox="0 0 16 16">
<path d="M13.854 3.646a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708 0l-3.5-3.5a.5.5 0 1 1 .708-.708L6.5 10.293l6.646-6.647a.5.5 0 0 1 .708 0"/>
</svg></span></button>
</li>
</ul>
<button class="btn btn-warning dropdown-toggle btn-sm mb-3" type="button" data-bs-toggle="dropdown" aria-expanded="false">
Available?
</button>
<ul class="dropdown-menu">
<li v-for="option in statusOptions">
<button type="button" class="dropdown-item" @click="applyFilter('status',option)">{{option}} <span v-if="selectedStatus == option" class="float-end"><svg style="color:green" xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-check2" viewBox="0 0 16 16">
<path d="M13.854 3.646a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708 0l-3.5-3.5a.5.5 0 1 1 .708-.708L6.5 10.293l6.646-6.647a.5.5 0 0 1 .708 0"/>
</svg></span></button>
</li>
</ul>
<button class="btn btn-secondary mb-3" style="--bs-btn-padding-y: .2rem; --bs-btn-padding-x: .4rem; --bs-btn-font-size: .6rem;" @click="clearFilters" type="button">
Clear filter and sort
</button>
</div>
</div>
<table class="table">
<thead>
<tr>
<th>Car ID</th>
<th>Car</th>
<th>Type</th>
<th>Available?</th>
<th>Price per hour</th>
<th>Distance (in km)</th>
<th>Select Car</th> <!-- Placeholder -->
</tr>
</thead>
<tbody>
<tr v-for="car in filteredData" :key="car.vehicle_id">
<td>{{ car.vehicle_id }}</td>
<td>{{ car.brand + " " + car.model }}</td>
<td>{{ car.cartype }}</td>
<td>{{ car.availability }}</td>
<td>{{ car.per_hr_price }}</td>
<td>{{ (Math.round((car.distance/1000) * 100) / 100).toFixed(2) }}</td>
<td><button class="btn btn-success" @click="selectedCar = car; page = 'carSelected'">Select</button></td>
</tr>
</tbody>
</table>
</div>
</div>
<div v-else-if="page == 'carSelected'" class="ms-2 mt-3">
<div class="ps-3 pt-1">
<h5>You have selected the following car:</h5>
<p>ID: {{selectedCar.vehicle_id}}</p>
<p>Brand: {{selectedCar.brand}}</p>
<p>Type: {{selectedCar.cartype}}</p>
<p>Price per hour: {{selectedCar.per_hr_price}}</p>
<p>Distance (in km): {{(Math.round((selectedCar.distance/1000) * 100) / 100).toFixed(2)}}</p>
<h6 v-if="selectedCar.availability == 'Booked'"> The car is <span class="text-danger">currently booked.</span> Would you like to receive an email when it becomes available?</h6>
<button class="btn btn-primary mt-3" v-if="selectedCar.availability == 'Booked'" @click="requestNotification" data-bs-toggle="modal" data-bs-target="#notifModal">Notify me when the car is available</button>
<button class="btn btn-primary mt-2" v-else @click="bookCar" data-bs-toggle="modal" data-bs-target="#bookingModal" >Book car</button>
<div class="modal fade" id="notifModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5">Request for notification result</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body" id="notifModalBody">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">OK</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="bookingModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5">Booking result</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body" id="bookingModalBody">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal" @click="page='carSearch'">OK</button>
</div>
</div>
</div>
</div>
</div>
</div>
<div v-else>
<div v-if="bookedCar == null" class="ms-2 mt-3">
<div>
<h5>No booking found</h5>
</div>
</div>
<div v-else class="ms-3 mt-4">
<div>
<h5>Your booking details are as follows: </h5>
<p>Brand: {{bookedCar.brand}}</p>
<p>Type: {{bookedCar.cartype}}</p>
<p>Price per hour: {{bookedCar.per_hr_price}}</p>
<p>Latitude: {{bookedCar.latitude}}</p> <!-- Placeholder-->
<p>Longitude: {{bookedCar.longitude}}</p> <!-- Placeholder -->
<p>Address: {{bookedCar.address}}</p> <!-- Placeholder -->
<p>Booking Date and Time: {{bookedCar.bookingTime}}</p>
</div>
<div v-if="reportStarted == false" class="mt-4">
<h5 class=>Have any issues with the car?</h5>
<button class="btn btn-primary ms-3" @click="reportStarted=true">Create damage report</button>
</div>
<!--If car selected and booked for report-->
<div v-else-if="reportMade == false && reportStarted == true">
<h2 class="mb-4">Report</h2>
<div class="mb-4" v-for="damage in damages" :key="damage.id">
<label :for="'damage' + damage.id + 'Description'" style="display: block; margin-bottom: 5px;">Damage {{damage.id}}</span> Description:</label>
<textarea :id="'damage' + damage.id + 'Description'" :v-model="damage.desc" style="width: 30%; padding: 8px; border: 1px solid #ccc; border-radius: 5px; resize: vertical;"></textarea>
</div>
Have more damages? <button class="btn btn-secondary ms-3" @click="addDamage">Add row</button>
<button class="btn btn-primary ms-3" @click="reportCar">Submit report</button>
</div>
<div class="modal fade" id="reportModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5">Report result</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body" id="bookingModalBody">
Your report was successfully sent. Would you like to cancel your booking?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" @click="cancelBooking" data-bs-dismiss="modal">Yes</button>
<button type="button" class="btn btn-danger" @click="reportStarted=false; reportMade=false" data-bs-dismiss="modal">No</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="reportFailedModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5">Report result</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
Your report could not be submitted
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">OK</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="cancelModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5">Cancellation result</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
Your booking has been cancelled. Thank you.
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">OK</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
<script>
(g=>{var h,a,k,p="The Google Maps JavaScript API",c="google",l="importLibrary",q="__ib__",m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=>h||(h=new Promise(async(f,n)=>{await (a=m.createElement("script"));e.set("libraries",[...r]+"");for(k in g)e.set(k.replace(/[A-Z]/g,t=>"_"+t[0].toLowerCase()),g[k]);e.set("callback",c+".maps."+q);a.src=`https://maps.${c}apis.com/maps/api/js?`+e;d[q]=f;a.onerror=()=>h=n(Error(p+" could not load."));a.nonce=m.querySelector("script[nonce]")?.nonce||"";m.head.append(a)}));d[l]?console.warn(p+" only loads once. Ignoring:",g):d[l]=(f,...n)=>r.add(f)&&u().then(()=>d[l](f,...n))})({
key: "AIzaSyBYUJ8kdbJv3zpxq5OGaKo4ogRmxf8RU5g",
v: "weekly",
// Use the 'v' parameter to indicate the version to use (weekly, beta, alpha, etc.).
// Add other bootstrap parameters as needed, using camel case.
});
</script>
<script>
new Vue({
el: '#app',
data: {
carsList: [],
filter: false,
userId: 6, // assume we know userId
distanceSortOrder: 'ascending',
priceSortOrder: "",
typeOptions: [],
statusOptions: [],
brandOptions: [],
selectedCar: null,
bookedCar: null,
reportDate: '',
damageDescription: '',
reportStarted: false,
reportMade: false,
selectedBrand: "",
selectedType: "",
selectedStatus: "",
page: 'carSearch',
map: null,
markers: [],
infowindow: null,
damages: [{"id":1, "desc": ""}]
},
computed: {
filteredData() {
let filtered = this.carsList;
// Apply type and status filters
if (this.selectedType) {
filtered = filtered.filter(item => item.cartype === this.selectedType);
}
if (this.selectedStatus) {
filtered = filtered.filter(item => item.availability === this.selectedStatus);
}
if (this.selectedBrand) {
filtered = filtered.filter(item => item.brand === this.selectedBrand);
}
// Apply distance and price sorting
if (this.priceSortOrder === 'ascending') {
filtered.sort((a, b) => a.per_hr_price - b.per_hr_price);
} else if (this.priceSortOrder === 'descending'){
filtered.sort((a, b) => b.per_hr_price - a.per_hr_price);
}
if (this.distanceSortOrder === 'ascending') {
filtered.sort((a, b) => a.distance - b.distance);
} else if (this.distanceSortOrder === 'descending'){
filtered.sort((a, b) => b.distance - a.distance);
}
return filtered;
}
},
mounted(){
},
methods: {
addDamage(){
let currLen = this.damages.length
this.damages.push({"id": currLen+1, "desc": ""})
},
async initMarkers(){
const {Geocoder} = await google.maps.importLibrary("geocoding");
const { InfoWindow } = await google.maps.importLibrary("maps");
const { AdvancedMarkerElement, PinElement } = await google.maps.importLibrary("marker");
var geocoder = new Geocoder();
this.infowindow = new InfoWindow({
content: ""
})
for (let i=0;i<this.carsList.length;i++){
let car = this.carsList[i];
geocoder.geocode({'location' : {lat: car.latitude, lng: car.longitude}}, function(results, status) {
if (status === 'OK') {
car.address = results[0].formatted_address
}
})
const pinStyle = new PinElement({
scale: 1,
background: "lightblue",
borderColor: "blue",
glyphColor: "blue"
});
let marker = new AdvancedMarkerElement({
map: this.map,
title: car.vehicle_id.toString(),
position: {lat: car.latitude, lng: car.longitude},
content: pinStyle.element
})
marker.addListener("click", () => {
this.infowindow.setContent("<h5 class='h5'> Vehicle ID: " + car.vehicle_id + ", Vehicle: " + car.brand + " " + car.model + "</h5> <hr class='black'>" + "<div style='color:black;'> Address (if exists): " + car.address + "<br> Coordinates: " + car.latitude + "," + car.longitude + "</div>")
this.infowindow.open({
anchor: marker,
});
});
}
},
async initMap(userLoc) {
// The location of Uluru
const position = { lat: userLoc.latitude, lng: userLoc.longitude};
// Request needed libraries.
//@ts-ignore
const { Map } = await google.maps.importLibrary("maps");
const { AdvancedMarkerElement } = await google.maps.importLibrary("marker");
// The map, centered at User's location
this.map = new Map(document.getElementById("map"), {
zoom: 11,
center: position,
mapId: 'ff540a478a073267',
});
// User marker
const marker = new AdvancedMarkerElement({
map: this.map,
position: position,
title: "User Location",
});
marker.addListener("click", () => {
this.infowindow.setContent("<h5 class='h5'>" + "User Location" + "</h5>")
this.infowindow.open({
anchor: marker,
map,
});
});
},
applySort(metric, order){
if (metric == "price"){
this.distanceSortOrder = ''
this.priceSortOrder = order
}else{
this.priceSortOrder = ''
this.distanceSortOrder = order
}
},
applyFilter(field, option){
if (field == "brand"){
this.selectedBrand = option
}
if (field == "type"){
this.selectedType = option
}
if (field == "status"){
this.selectedStatus = option
}
},
showFilter(){
if (this.filter){
this.filter = false;
}else{
this.filter= true;
}
},
searchForNearestCar() {
// Get user's location using Geolocation API
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(position => {
var xhr = new XMLHttpRequest();
var ref = this
xhr.open("POST", "http://localhost:8000/jomletsgo/searchcar");
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
let carsList = JSON.parse(xhr.response).data.cars.CarList;
for (let i=0;i<carsList.length; i++){
let car = carsList[i];
car.latitude = parseFloat(car.latitude)
car.longitude = parseFloat(car.longitude)
car.per_hr_price = parseFloat(car.per_hr_price)
car.distance = parseFloat(car.distance)
}
ref.carsList = carsList
ref.extractOptions();
ref.initMap(position.coords);
ref.initMarkers();
}
};
xhr.send(JSON.stringify({
"lat": position.coords.latitude,
"long": position.coords.longitude
}));
})
}
},
extractOptions() {
this.typeOptions = [...new Set(this.carsList.map(car => car.cartype))];
this.statusOptions = [...new Set(this.carsList.map(car => car.availability))];
this.brandOptions = [...new Set(this.carsList.map(car => car.brand))];
},
selectCar(car) {
this.selectedCar = car;
console.log(this.selectedCar)
},
bookCar(){
var xhr = new XMLHttpRequest();
var ref = this
xhr.open("POST", "http://localhost:8000/jomletsgo/bookcar");
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 201) {
console.log("Booking successful");
response = JSON.parse(xhr.response)
ref.bookedCar = ref.selectedCar
ref.bookedCar.bookingTime = response.data["Rental Log"].data.log_time
ref.selectedCar = null
document.getElementById('bookingModalBody').innerText = "Booking successful! You may view your booking details later under the Booking Details page."
}
else if(xhr.readyState === 4 && xhr.status === 401){
document.getElementById('bookingModalBody').innerText = "Booking unsuccessful. The car has already been booked."
ref.selectedCar = null
}
};
xhr.send(JSON.stringify({
"user_id": this.userId,
"vehicle_id" : this.selectedCar.vehicle_id
}))
},
clearFilters() {
this.selectedType = '';
this.selectedStatus = '';
this.selectedBrand = '';
this.priceSortOrder = 'ascending';
},
requestNotification(){
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://localhost:8000/jomletsgo/sendnotification");
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
console.log("Request for notification successful");
document.getElementById('notifModalBody').innerText = "You have been added to the waiting list and will receive an email when the car is ready"
}else if (xhr.readyState === 4 && xhr.status !== 200){
document.getElementById('notifModalBody').innerText = "Notification failed"
}
};
xhr.send(JSON.stringify({
"user_id": this.userId,
"vehicle_id": this.selectedCar.vehicle_id
}));
},
reportCar() {
// Construct report data
damages = []
reportDate = new Date().toString();
for (let i=0;i<this.damages.length;i++){
damages.push(this.damages[i].desc)
}
const reportData = {
'user_id': this.userId,
'vehicle_id': this.bookedCar.vehicle_id,
'date': reportDate,
'damages': damages
};
var xhr = new XMLHttpRequest();
var ref = this
xhr.open("POST", "http://localhost:8000/jomletsgo/reportcar");
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 201) {
console.log("Car reported successfully");
response = JSON.parse(xhr.response)
console.log(response)
ref.reportDate = '';
ref.damageDescription = '';
ref.reportMade = true;
const myModal = new bootstrap.Modal('#reportModal')
myModal.show()
}else if (xhr.readyState === 4 && xhr.status !== 201){
const myModal = new bootstrap.Modal('#reportFailedModal')
myModal.show()
}
};
xhr.send(JSON.stringify(reportData))
},
//cancel booking after report is created
cancelBooking(){
const report = {
vehicle_id: this.bookedCar.vehicle_id,
}
var xhr = new XMLHttpRequest();
var ref = this
xhr.open("POST", "http://localhost:8000/jomletsgo/cancelcar");
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
console.log("Car booking cancelled");
response = JSON.parse(xhr.response)
console.log(response)
ref.bookedCar = null;
ref.reportMade = false;
const myModal = new bootstrap.Modal('#cancelModal')
myModal.show()
}
};
xhr.send(JSON.stringify(report))
}
}
});
</script>
</body>
</html>