-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
163 lines (138 loc) · 4.19 KB
/
main.js
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
const lgSubmit = document.querySelector("#lgsubmit");
const lgUser = document.querySelector("#lguser");
const lgPword = document.querySelector("#lgpword");
const lgPage = document.querySelector(".login");
const pPage = document.querySelector(".profile");
const tPage = document.querySelector(".transact");
const nPage = document.querySelector(".nav");
const fPage = document.querySelector(".footer");
const pgBtnTrs = document.querySelector(".pgbtntrs");
const pgBtnLgO = document.querySelector(".pgbtnlgo");
const welcome = document.querySelector(".welcome");
const pgDisAmt = document.querySelector(".pgdisamt");
const trsDisAmt = document.querySelector(".trsdisamt");
const witBtn = document.querySelector(".witbtn");
const depBtn = document.querySelector(".depbtn");
const bakBtn = document.querySelector(".bakbtn");
const trsAmtBox = document.querySelector("#trsamtbox");
const historyUl = document.querySelector(".history ul");
let userName = "";
let passWord = "";
let acctBalance = 0;
acctBalance = acctBalance.toFixed(2);
let amount = 0;
let transType = "";
//login button handler
lgSubmit.onclick = (e) => {
e.preventDefault();
//Validate input
if(lgUser.value == ""){
alert("Please fill in the username")
}
else{
alert("Login successful");
userName = lgUser.value;
passWord = lgPword.value;
lgUser.value = "";
lgPword.value = "";
disPpage();
}
};
//Prodile page Transaction button handler
pgBtnTrs.onclick = () => {
disTpage();
};
//Profilepapge Log out button handler
pgBtnLgO.onclick = () => {
if (confirm("Are you sure you want to Log out")) {
disLpage();
}
};
//Transapge withdraw button handler
witBtn.onclick = () => {
if (trsAmtBox.value == "") {
alert("Please enter an amount in the input box");
}
else {
if (acctBalance < trsAmtBox.value) {
alert("You don't have sufficient Balance to make this witdrawal");
trsAmtBox.value = "";
}
else {
if (confirm("This transaction is not reversible! Are you sure you want to withdraw.")
) {
acctBalance -= trsAmtBox.value;
trsDisAmt.innerText = acctBalance;
transType = "withdrawal";
//Add to transaction history
updateTransHistory();
} else {
alert("You have cancelled the Transaction");
trsAmtBox.value = "";
}
}
}
};
//Transapge deposit button handler
depBtn.onclick = () => {
if (trsAmtBox.value == "") {
alert("Please enter an amount in the input box");
} else {
if (
confirm(
"This transaction is not reversible! Are you sure you want to Deposit."
)
) {
acctBalance = parseFloat(acctBalance);
acctBalance += parseFloat(trsAmtBox.value);
trsDisAmt.innerText = parseFloat(acctBalance).toFixed(2);
transType = "deposit";
//Add to transaction history
updateTransHistory();
} else {
alert("You have cancelled the Transaction.");
}
}
};
//Add to transaction history
updateTransHistory = () => {
let d = new Date();
let day = d.getDate() + "-" + (d.getMonth()+1) + "-" + d.getFullYear().toString().substring(2,4);;
historyUl.innerHTML += `<div class="title"><span>${day}</span><Span>${transType}</Span><span>${trsAmtBox.value}</span> <span>${acctBalance}</span> </div>`;
trsAmtBox.value = "";
transType = "";
}
//Transaction page Back button handler
bakBtn.onclick = () => {
disPpage();
};
disLpage = () => {
nPage.style.display = "block";
lgPage.style.display = "block";
pPage.style.display = "none";
tPage.style.display = "none";
fPage.style.disPage = "block";
};
disPpage = () => {
nPage.style.display = "none";
lgPage.style.display = "none";
pPage.style.display = "block";
tPage.style.display = "none";
fPage.style.disPage = "none";
//Lood user data
welcome.innerText = "Welcome, " + userName;
pgDisAmt.innerText = acctBalance.toLocaleString();
};
disTpage = () => {
nPage.style.display = "none";
lgPage.style.display = "none";
pPage.style.display = "none";
tPage.style.display = "block";
fPage.style.disPage = "none";
//Lood user data
trsDisAmt.innerText = acctBalance.toLocaleString();
};
//Dashboard function icons
document.querySelector('.dbicon1').onclick = () => {
disTpage();
}