forked from cehyman/BusSystemWebsite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccount.ejs
86 lines (77 loc) · 2.51 KB
/
account.ejs
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
<!DOCTYPE html>
<html>
<head>
<title>Routes</title>
<link rel="stylesheet" href="style.css" />
<script src="logOut.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<a href="/homePage">Home</a><br /><br />
<h1>Account</h1>
<p>Here you can look at the bookings you currently have</p>
<a href="/routes">Route Details TransportCo </a><br />
<a href="/book">Book a Ride</a><br /><br />
<a href="/rewards">Check your rewards</a><br /><br />
<a href="/passChange">Change Password</a><br /><br />
<label id="labelUsername"></label><br />
<input id="buttonLogOut" type="button" onclick="logOut();" value="Log Out" />
<br /><br /><br />
<h2>Bookings:</h2>
<table id="tableBookings"></table>
</body>
</html>
<script>
//function that is called when page is loaded to populate the dropdowns
function populateBookings() {
var labelUser = document.getElementById("labelUsername");
labelUser.innerHTML = 'Logged in as ' + sessionStorage.getItem('username');
var table = document.getElementById("tableBookings");
var dbData;
//get the list of bookings that the user has from database and add them to table here
$.ajax({
url: "http://localhost:8080/viewBookings",
type: "POST",
data: {
username: sessionStorage.getItem('username')
},
dataType: 'json',
success: function (result) {
const NONEMPTY = 0;
const EMPTY = 1;
if (result.code == NONEMPTY) {
dbData = result.bookings;
for (var i = 0; i < dbData.length; i++) {
row = table.insertRow(i);
col1 = row.insertCell(0);
col2 = row.insertCell(1);
col3 = row.insertCell(2);
col4 = row.insertCell(3);
col1.innerHTML = "" + dbData[i].route_id;
col2.innerHTML = "" + dbData[i].paid_price;
col3.innerHTML = "" + dbData[i].depart_time;
col4.innerHTML = "" + dbData[i].arrive_time;
}
var row = table.insertRow(0);
var col1 = row.insertCell(0);
var col2 = row.insertCell(1);
var col3 = row.insertCell(2);
var col4 = row.insertCell(3);
col1.innerHTML = "Route";
col2.innerHTML = "Price";
col3.innerHTML = "Depart Time";
col4.innerHTML = "Arrive Time";
} else if (result.code == EMPTY) {
var row = table.insertRow(0);
var col1 = row.insertCell(0);
col1.innerHTML = "No bookings."
} else {
var row = table.insertRow(0);
var col1 = row.insertCell(0);
col1.innerHTML = "Error fetching bookings.";
}
}
});
}
populateBookings();
</script>