/
app.js
90 lines (71 loc) · 2.02 KB
/
app.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
// budget controller
var budgetController = (function() {
var Expense = function(id, description, value) {
this.id = id;
this.description = description;
this.value = value;
}
var Incom = function(id, description, value) {
this.id = id;
this.description = description;
this.value = value;
}
var data = {
allItems: {
exp: [],
inc: []
},
totals: {
totalExp: 0,
totalInc: 0
}
}
}());
// UI
var UIController = (function() {
var DOMstring = {
inputType: '.add__type',
inputDescription: '.add__description',
inputValue: '.add__value',
inputButton: '.add__btn'
}
return {
getinput: function() {
return {
type: document.querySelector(DOMstring.inputType).value, //inc or exp
description: document.querySelector(DOMstring.inputDescription).value, //description text
value: document.querySelector(DOMstring.inputValue).value //value
}
},
getDOMstring: function() {
return DOMstring;
}
}
}());
// global controller
var controller = (function(budgetCtrl, UICtrl) {
var setupEventListeners = function() {
var DOM = UIController.getDOMstring();
document.querySelector(DOM.inputButton).addEventListener('click', ctrlAddItem);
document.addEventListener('keypress', function(event) {
if (event.charCode === 13) {
ctrlAddItem();
}
});
}
var ctrlAddItem = function() {
//1. get file data
var input = UIController.getinput();
//2. add item to the budget
//3. add item to UI
//4. calculate the budget
//5. display the budget on UI
}
return {
init: function() {
setupEventListeners();
console.log('ready start');
}
}
}(budgetController, UIController));
controller.init();