-
Notifications
You must be signed in to change notification settings - Fork 3
/
createEntry.js
127 lines (107 loc) · 3.9 KB
/
createEntry.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
// const { Entry } = require("./Classes.js");
////////////////////////////////////////////
// ZUTAT SPALTE
////////////////////////////////////////////
function createEntryField(listID, Dough, Entry, loaded = false){
var list = document.getElementById(listID);
var list_el = document.createElement('li');
list_el.setAttribute("style","transition: 0.5s;")
list_el.className = "doughLi"
list_el.id = Entry.id;
if (loaded == false){
Dough.addEntry(Entry)
}
var img = document.createElement( "img")
img.src = "./dragButton.png"
img.alt=""
img.className = "unselectable"
img.draggable = false
img.width="15"
img.style = "margin-right: 5px;"
img.height="15"
list_el.appendChild(img)
list_el.addEventListener('dragstart', dragStart);
list_el.addEventListener('dragover', dragOver);
list_el.addEventListener('dragleave', dragLeave);
list_el.addEventListener('drop', dragDrop);
var close = document.createElement("span")
close.className = "close"
close.innerHTML = "-"
close.addEventListener("click", function() {
Dough.removeEntry(list_el.id)
Dough.update()
Main.update()
});
var input = document.createElement("input");
input.type = "number";
input.className = "input-text-gram"; // set the CSS class
input.value = parseFloat(Entry.gram)
input.setAttribute("onClick","this.select();")
input.addEventListener ('keydown', function (event) {
if (event.which == 13) { //enter key
Dough.getEntry(list_el.id).updateGrams(this.value, true)
Dough.update(list_el.id)
Main.update(list_el.id)
} });
input.addEventListener ('focusout', function (event) {
Dough.getEntry(list_el.id).updateGrams(this.value, true)
Dough.update(list_el.id)
Main.update(list_el.id)
});
list_el.appendChild(input); // put it into the DOM
text = document.createElement("a")
text.innerHTML = " g "
text.setAttribute("style",'margin-right: 10px;')
text.className = "InfoTypeText"
list_el.appendChild(text)
var input = document.createElement("input");
input.type = "text";
input.className = "input-text-name"; // set the CSS class
input.value = Entry.name
input.setAttribute("style",'margin-right: 20px;')
input.setAttribute("onClick","this.select();")
input.addEventListener ('keydown', function (event) {
if (event.which == 13) { //enter key
Dough.getEntry(list_el.id).updateName(this.value, true)
Dough.update(list_el.id)
} });
input.addEventListener ('focusout', function (event) {
Dough.getEntry(list_el.id).updateName(this.value, true)
Dough.update(list_el.id)
});
list_el.appendChild(input); // put it into the DOM
var input = document.createElement("input");
input.type = "number";
input.className = "input-text-percent"; // set the CSS class
input.setAttribute("onClick","this.select();")
input.value = parseFloat(Entry.percent)
input.addEventListener("focusout", function(event){});
input.addEventListener ('keydown', function(event) {
if (event.which == 13) { //enter key
// only if value is different to old vlaue -> implement everything into an update funciton and a fetch function? or update with keyword arg
Dough.getEntry(list_el.id).updatePercent(this.value, true)
Dough.update(list_el.id)
Main.update(list_el.id)
} });
input.addEventListener ('focusout', function (event) {
Dough.getEntry(list_el.id).updatePercent(this.value, true)
Dough.update(list_el.id,"percent")
Main.update(list_el.id)
});
list_el.appendChild(input); // put it into the DOM
text = document.createElement("a")
text.className = "InfoTypeText"
text.innerHTML = "% "
text.setAttribute("style",'margin-right: 40px;')
list_el.appendChild(text)
var textType = document.createElement("a")
textType.innerHTML = Entry.type
textType.className = "InfoTypeText-transparent"
list_el.appendChild(textType)
list_el.appendChild(close)
list_el.draggable = true
list.appendChild(list_el);
Dough.update(list_el.id)
Main.update(list_el.id)
}
module.exports.createEntryField = createEntryField;