-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
291 lines (253 loc) · 11.1 KB
/
index.html
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE-edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Lista Regali</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<style>
.labs{
display: inline-block;
width: 100px;
}
</style>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f0f8ff; /* Background azzurrino */
margin: 20px;
}
table {
border-collapse: collapse;
width: 100%;
margin-top: 20px;
}
th, td {
border: 2px solid #281bde49;
padding: 10px;
text-align: left;
}
th {
background-color: #4CAF50;
color: white;
}
input {
width: inline-block;
}
button {
background-color: #4CAF50;
color: white;
padding: 8px 16px;
border: none;
border-radius: 4px;
cursor: pointer;
}
</style>
</head>
<body>
<div class="container mt-3">
<table class="table">
<thead>
<th>N.</th>
<th>Nome</th>
<th>Regalo 1</th>
<th>Regalo 2</th>
<th>Regalo 3</th>
<th>Regalo 4</th>
<th>Regalo 5</th>
<th>Pulsanti di Controllo</th>
</thead>
<tbody id="tbody1">
</tbody>
</table>
</div>
<!-- Modal -->
<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Pannello di Controllo</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<label class="labs">Nome: </label>
<input type="text" id="NameMod"> <br>
<label class="labs">Regalo1: </label>
<input type="text" id="Regalo1Mod"> <br>
<label class="labs">Regalo2: </label>
<input type="text" id="Regalo2Mod"> <br>
<label class="labs">Regalo3: </label>
<input type="text" id="Regalo3Mod"> <br>
<label class="labs">Regalo4: </label>
<input type="text" id="Regalo4Mod"> <br>
<label class="labs">Regalo5: </label>
<input type="text" id="Regalo5Mod"> <br>
</div>
<div class="modal-footer">
<button id="AddModBtn" type="button" class="btn btn-primary" onclick="AddStd()">Inserisci</button>
<button id="UpdModBtn" type="button" class="btn btn-success" onclick="UpdStd()">Aggiorna</button>
<button id="DelModBtn" type="button" class="btn btn-danger" onclick="DelStd()">Elimina</button>
</div>
</div>
</div>
</div>
</div>
<script src="https://www.gstatic.com/firebasejs/10.7.1/firebase-app-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/10.7.1/firebase-auth-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/10.7.1/firebase-database-compat.js"></script>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<script id="MainScript">
var firebaseConfig = {
apiKey: "AIzaSyCwgPN8vLh2-WByAzLZB0hvw7T-AV1DiQY",
authDomain: "lista-2-3133b.firebaseapp.com",
databaseURL: "https://lista-2-3133b-default-rtdb.europe-west1.firebasedatabase.app",
projectId: "lista-2-3133b",
storageBucket: "lista-2-3133b.appspot.com",
messagingSenderId: "412019034412",
appId: "1:412019034412:web:c50ad3aab6fc0a5aa28489"
};
firebase.initializeApp(firebaseConfig);
var studentNo;
function Select_AllData(){
document.getElementById("tbody1").innerHTML="";
studentNo=0;
firebase.database().ref('student').once('value', function (snapshot) {
snapshot.forEach(function (childsnapshot) {
var name = childsnapshot.val().Nome;
var regalo1 = childsnapshot.val().Regalo1;
var regalo2 = childsnapshot.val().Regalo2;
var regalo3 = childsnapshot.val().Regalo3;
var regalo4 = childsnapshot.val().Regalo4;
var regalo5 = childsnapshot.val().Regalo5;
AddItemToTable(name,regalo1,regalo2,regalo3,regalo4,regalo5);
});
});
}
window.onload = Select_AllData;
var stdList =[];
function AddItemToTable(name,regalo1,regalo2,regalo3,regalo4,regalo5){
var tbody = document.getElementById('tbody1');
var trow = document.createElement('tr');
var td0 = document.createElement('td');
var td1 = document.createElement('td');
var td2 = document.createElement('td');
var td3 = document.createElement('td');
var td4 = document.createElement('td');
var td5 = document.createElement('td');
var td6 = document.createElement('td');
stdList.push([name,regalo1,regalo2,regalo3,regalo4,regalo5]);
td0.innerHTML= ++studentNo;
td1.innerHTML= name;
td2.innerHTML= regalo1;
td3.innerHTML= regalo2;
td4.innerHTML= regalo3;
td5.innerHTML= regalo4;
td6.innerHTML= regalo5;
trow.appendChild(td0);
trow.appendChild(td1);
trow.appendChild(td2);
trow.appendChild(td3);
trow.appendChild(td4);
trow.appendChild(td5);
trow.appendChild(td6);
var ControlDiv = document.createElement("div");
// ControlDiv.innerHTML = '<button type="button" class="btn btn-primary my-2" data-toggle="modal" data-target="#exampleModalCenter" onclick="FillTboxes(null)">Inserisci</button>'
ControlDiv.innerHTML += '<button type="button" class="btn btn-primary my-2 ml-2" data-toggle="modal" data-target="#exampleModalCenter" onclick="FillTboxes('+studentNo+')">Modifica</button>'
trow.appendChild(ControlDiv);
tbody1.appendChild(trow);
}
var ModName = document.getElementById('NameMod');
var ModRegalo1 = document.getElementById('Regalo1Mod');
var ModRegalo2 = document.getElementById('Regalo2Mod');
var ModRegalo3 = document.getElementById('Regalo3Mod');
var ModRegalo4 = document.getElementById('Regalo4Mod');
var ModRegalo5 = document.getElementById('Regalo5Mod');
var BTNmodAdd = document.getElementById('AddModBtn');
var BTNmodUpd = document.getElementById('UpdModBtn');
var BTNmodDel = document.getElementById('DelModBtn');
function FillTboxes(index){
if(index==null){
ModName.value = "";
ModRegalo1.value = "";
ModRegalo2.value = "";
ModRegalo3.value = "";
ModRegalo4.value = "";
ModRegalo5.value = "";
BTNmodAdd.style.display='inline-block';
BTNmodUpd.style.display='none';
BTNmodDel.style.display='none';
}
else{
--index;
ModName.value = stdList[index][0];
ModRegalo1.value = stdList[index][1];
ModRegalo2.value = stdList[index][2];
ModRegalo3.value = stdList[index][3];
ModRegalo4.value = stdList[index][4];
ModRegalo5.value = stdList[index][5];
BTNmodAdd.style.display='none';
BTNmodUpd.style.display='inline-block';
BTNmodDel.style.display='inline-block';
}
}
function AddStd(){
firebase.database().ref("student/"+ModName.value).set(
{
Nome: ModName.value,
Regalo1: ModRegalo1.value,
Regalo2: ModRegalo2.value,
Regalo3: ModRegalo3.value,
Regalo4: ModRegalo4.value,
Regalo5: ModRegalo5.value
},
(error) =>{
if(error){
alert("record was not added, there was some problem");
}
else{
alert("record was added");
Select_AllData();
$("#exampleModalCenter").modal('hide');
}
}
)
}
function UpdStd(){
firebase.database().ref("student/"+ModName.value).update(
{
Nome: ModName.value,
Regalo1: ModRegalo1.value,
Regalo2: ModRegalo2.value,
Regalo3: ModRegalo3.value,
Regalo4: ModRegalo4.value,
Regalo5: ModRegalo5.value
},
(error) =>{
if(error){
alert("recrd was not updated, there was some problem");
}
else{
alert("record was updated");
Select_AllData();
$("#exampleModalCenter").modal('hide');
}
}
)
}
function DelStd(){
firebase.database().ref("student/"+ModName.value).remove().then(
function(){
alert("record was deleted");
Select_AllData();
$("#exampleModalCenter").modal('hide');
}
)
}
</script>
</body>
</html>