-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontacts.js
More file actions
177 lines (133 loc) · 4.78 KB
/
Copy pathcontacts.js
File metadata and controls
177 lines (133 loc) · 4.78 KB
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
var contacts = [];
var names = ["Jorge", "Madalena", "Daniela","Pedro", "João", "Nuno", "Sofia", "Soraia", "Matilde", "Alice", "Rui"];
function randomName () {
name = names[Math.floor((Math.random() * 10) + 1)];
return name;
}
function loadData (data) {
localStorage.setItem("Data", JSON.stringify(data));
}
function addFriend (name) {
var storedData = JSON.parse(localStorage.getItem("Data"));
if (storedData != null) {
storedData.push(name);
storedData.sort();
loadData(storedData);
}
else {
contacts.push(name);
loadData(contacts);
}
}
function showFriend (name) {
var btn = document.createElement("BUTTON");
var firstName = document.createTextNode(name);
btn.appendChild(firstName);
var att = document.createAttribute("class");
att.value = "menuButtons1";
btn.setAttributeNode(att);
btn.setAttribute('onclick', 'window.location.assign("personMap.html")');
var scrollbar = document.getElementsByClassName("scrollbar")[0];
scrollbar.appendChild(btn);
}
function showRemovingButton (name) {
var btn = document.createElement("BUTTON");
var firstName = document.createTextNode(name);
btn.appendChild(firstName);
var att = document.createAttribute("class");
att.value = "menuButtons1";
btn.setAttributeNode(att);
btn.setAttribute('onclick', 'changeVisibilityRemoving(\'' + name + '\');');
var scrollbar = document.getElementsByClassName("scrollbar")[0];
scrollbar.appendChild(btn);
}
function showAddingButton (name) {
var btn = document.createElement("BUTTON");
var firstName = document.createTextNode(name);
btn.appendChild(firstName);
var att = document.createAttribute("class");
att.value = "option1";
btn.setAttributeNode(att);
btn.setAttribute('onclick', 'changeVisibilityAdding(\'' + name + '\');');
var scrollbar = document.getElementsByClassName("scrollbar")[0];
scrollbar.appendChild(btn);
}
function changeVisibilityRemoving (name) {
var buttons = document.getElementsByClassName("scrollbar");
for (var i = 0; i < buttons.length; i++)
buttons[i].style.display = "none";
var removerButton = document.getElementById("remover");
if (removerButton.style.visibility == "hidden")
removerButton.style.visibility = "visible";
var yes = document.createElement("BUTTON");
yes.appendChild(document.createTextNode("Sim"));
var no = document.createElement("BUTTON");
no.appendChild(document.createTextNode("Não"));
var att1 = document.createAttribute("class");
att1.value = "option1";
yes.setAttributeNode(att1);
yes.setAttribute('onclick', ' removeFriend(\'' + name + '\'); window.location.assign("localizePeople.html");');
var att2 = document.createAttribute("class");
att2.value = "option2";
no.setAttributeNode(att2);
no.setAttribute('onclick', 'window.location.assign("localizePeople.html");');
var cont = document.getElementById("container");
cont.appendChild(removerButton);
cont.appendChild(yes);
cont.appendChild(no);
}
function changeVisibilityAdding (name) {
var buttons = document.getElementsByClassName("scrollbar");
for (var i = 0; i < buttons.length; i++)
buttons[i].style.display = "none";
var addButton = document.getElementById("adicionar");
if (addButton.style.visibility == "hidden")
addButton.style.visibility = "visible";
var yes = document.createElement("BUTTON");
yes.appendChild(document.createTextNode("Sim"));
var no = document.createElement("BUTTON");
no.appendChild(document.createTextNode("Não"));
var att1 = document.createAttribute("class");
att1.value = "option1";
yes.setAttributeNode(att1);
yes.setAttribute('onclick', ' addFriend(\'' + name + '\'); window.location.assign("localize.html");');
var att2 = document.createAttribute("class");
att2.value = "option2";
no.setAttributeNode(att2);
no.setAttribute('onclick', 'window.location.assign("localize.html");');
var cont = document.getElementById("container");
cont.appendChild(addButton);
cont.appendChild(yes);
cont.appendChild(no);
}
function showRemovingButtons() {
var len, name;
var storedData = JSON.parse(localStorage.getItem("Data"));
len = storedData.length;
for (i = 0; i < len; i++) {
name = storedData[i];
showRemovingButton(name);
}
}
function showAddingButtons() {
name = randomName();
showAddingButton(name);
}
function showAll () {
var len, name;
var storedData = JSON.parse(localStorage.getItem("Data"));
len = storedData.length;
for (i = 0; i < len; i++) {
name = storedData[i];
showFriend(name);
}
}
function removeFriend (name) {
var storedData = JSON.parse(localStorage.getItem("Data"));
var i, len;
len = storedData.length;
var index = storedData.indexOf(name);
storedData.splice(index,1);
//storedData.sort();
loadData(storedData);
}