MCPcopy Create free account
hub / github.com/Vishal-raj-1/Awesome-JavaScript-Projects / UI

Class UI

assets/js/Budget.js:1–150  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1class UI {
2 constructor() {
3 this.budgetFeedback = document.querySelector(".budget-feedback");
4 this.expenseFeedback = document.querySelector(".expense-feedback");
5 this.budgetForm = document.getElementById("budget-form");
6 this.budgetInput = document.getElementById("budget-input");
7 this.budgetAmount = document.getElementById("budget-amount");
8 this.expenseAmount = document.getElementById("expense-amount");
9 this.balance = document.getElementById("balance");
10 this.balanceAmount = document.getElementById("balance-amount");
11 this.expenseForm = document.getElementById("expense-form");
12 this.expenseInput = document.getElementById("expense-input");
13 this.amountInput = document.getElementById("amount-input");
14 this.expenseList = document.getElementById("expense-list");
15 this.itemList = [];
16 this.itemID = 0;
17 }
18
19 //submit budget method
20 submitBudgetForm(){
21 const value = this.budgetInput.value;
22 if(value === '' || value < 0){
23 this.budgetFeedback.classList.add('showItem');
24 this.budgetFeedback.innerHTML = `<p>value cannot be empty or negative</p>`;
25 const self = this;
26 setTimeout(function(){
27 self.budgetFeedback.classList.remove('showItem');
28 }, 3000);
29 } else {
30 this.budgetAmount.textContent = value;
31 this.budgetInput.value = '';
32 this.showBalance();
33 }
34 }
35
36 //show balance
37 showBalance(){
38 const expense = this.totalExpense();
39 const total = parseInt(this.budgetAmount.textContent) - expense;
40 this.balanceAmount.textContent = total;
41 if(total < 0){
42 this.balance.classList.remove('showGreen', 'showBlack');
43 this.balance.classList.add('showRed');
44 } else if(total > 0){
45 this.balance.classList.remove('showRed', 'showBlack');
46 this.balance.classList.add('showGreen');
47 } else if(total === 0){
48 this.balance.classList.remove('showRed', 'showGreen');
49 this.balance.classList.add('showBlack');
50 }
51 }
52 //submit expense form
53 submitExpenseForm(){
54 const expenseValue = this.expenseInput.value;
55 const amountValue = this.amountInput.value;
56 if(expenseValue === '' || amountValue === '' || amountValue < 0){
57 this.expenseFeedback.classList.add('showItem');
58 this.expenseFeedback.innerHTML = `<p>values cannot be empty or negative</p>`;
59 const self = this;
60 setTimeout(function(){

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected