-
Notifications
You must be signed in to change notification settings - Fork 1
/
rewards.ejs
76 lines (64 loc) · 2.14 KB
/
rewards.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
<!DOCTYPE html>
<html>
<head>
<a href="/homePage">Home</a><br /><br />
<title>Rewards</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>
<h1>Welcome to the Rewards page.</h1>
<p>Here will be where you can look at the rewards you have earned!</p>
<h2>Your discount is:</h2>
<table id="tableRewards"></table>
<br /><br />
<label id="labelUsername"></label><br />
<input id="buttonMyAcc" type="button" onclick="location.href = '/account';" value="My Account" />
<input id="buttonLogOut" type="button" onclick="logOut();" value="Log Out" />
<br /><br /><br />
</body>
</html>
<script>
function populateRewards() {
var labelUser = document.getElementById("labelUsername");
labelUser.innerHTML = 'Logged in as ' + sessionStorage.getItem('username');
var table = document.getElementById("tableRewards");
var dbData;
//get the list of rewards that the user has from database and add them to table here
$.ajax({
url: "http://localhost:8080/viewRewards",
type: "POST",
data: {
username: sessionStorage.getItem('username')
},
dataType: 'json',
success: function (result) {
const NONEMPTY = 0;
const EMPTY = 1;
if (result.code == NONEMPTY) {
dbData = result.rewards;
var row = table.insertRow(0);
var col1 = row.insertCell(0);
var col2 = row.insertCell(1);
col1.innerHTML = "User";
col2.innerHTML = "Discount";
row = table.insertRow(1);
col1 = row.insertCell(0);
col2 = row.insertCell(1);
col1.innerHTML = "" + dbData[0].username;
col2.innerHTML = "$" + dbData[0].discount;
} else if (result.code == EMPTY) {
var row = table.insertRow(0);
var col1 = row.insertCell(0);
col1.innerHTML = "No discount available."
} else {
var row = table.insertRow(0);
var col1 = row.insertCell(0);
col1.innerHTML = "Error fetching discount.";
}
}
});
}
populateRewards();
</script>