-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
75 lines (63 loc) · 2.28 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
var textValue = document.getElementById("textTodo");
var ulli = document.createElement("ol");
ulli.setAttribute("id", "UlList");
var conttainerlist = document.getElementById("containerList");
conttainerlist.appendChild(ulli);
//----Geting Data From Database real time
firebase.database().ref('User Data').on('child_added', function(data) {
//---Create LI LIST IN UL----
var createLi = document.createElement("li");
var textLi = document.createTextNode(data.val().goal);
//----Create Delete Button------
var delBtn = document.createElement("button");
var delBtnText = document.createTextNode("Delete");
delBtn.setAttribute("onclick","deleteValue(this)");
delBtn.setAttribute("class","deleteItem");
delBtn.setAttribute("id",data.val().key)
//----create Update Button----
var updateBtn = document.createElement("button");
var textUpdate = document.createTextNode("Update");
updateBtn.setAttribute("onclick","editValue(this)")
updateBtn.setAttribute("class","editvalue")
updateBtn.setAttribute("id",data.val().key);
updateBtn.appendChild(textUpdate)
createLi.appendChild(textLi);
ulli.appendChild(createLi);
delBtn.appendChild(delBtnText);
createLi.appendChild(delBtn);
createLi.appendChild(updateBtn);
console.log(createLi)
})
function addList() {
//---User Get gaol and store in object.
let key = firebase.database().ref("User Data").push().key;
let userGaol = {
key: key,
goal: textValue.value
}
firebase.database().ref("User Data/" + key).set(userGaol);
textValue.value = "";
}
//-----Delete All Whole List -------
function deleteAll() {
firebase.database().ref("User Data").remove();
ulli.innerHTML = " ";
}
//-----Delete Specific List------
function deleteValue(e) {
//method 1
// firebase.database().ref("User Data").child(e.id).remove();
//method 2
firebase.database().ref("User Data/"+e.id).remove();
e.parentNode.remove()
}
//---Edit Each List ------
function editValue(e) {
var val = prompt("Enter You Update Vlaue ", e.parentNode.firstChild.nodeValue);
let editgoal={
key: e.id,
goal: val
}
firebase.database().ref('User Data').child(e.id).set(editgoal);
e.parentNode.firstChild.nodeValue = val
}