-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
154 lines (103 loc) · 4.58 KB
/
main.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
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
//window.addEventListener("load", actualizarPagina);
// function actualizarPagina () { }
//Evento boton
const formulario = document.getElementById('form');
const listaDeCuentas = document.getElementById('listaActividades');
let datosInput = [];
const crearItem = (nombre,fecha,tipo,pass,email) => {
let item = {
nombre: nombre,
fecha: fecha,
tipo: tipo,
pass: pass,
email: email
}
datosInput.push(item);
return item;
}
const guardarLS = () => {
localStorage.setItem('listas', JSON.stringify(datosInput));
imprimirLS();
}
const imprimirLS = () => {
listaDeCuentas.innerHTML = "";
datosInput = JSON.parse(localStorage.getItem('listas'));
if (datosInput === null) {
datosInput = [];
} else {
datosInput.forEach(element => {
listaDeCuentas.innerHTML += `
<div id="size" class="card-body table-responsive">
<table class="table table-hover">
<tbody>
<tr>
<td scope="col">${element.nombre}</td>
<td scope="col">${element.fecha}</td>
<td class="bg-danger" scope="col" style="color:white; cursor:pointer; text-align: center; width:10%; border-radius:10px;">Borrar</td>
</tr>
<tr>
<td class="bgt" scope="col">${element.tipo}</td>
<td scope="col">${element.pass}</td>
<td scope="col">${element.email}</td>
</tr>
</tbody>
</table>
</div>`});
}
}
const borrarLS = (nombre,fecha,tipo,pass,email) => {
let indexArreglo;
datosInput.forEach((element, index) => {
if (element.nombre === nombre && element.fecha === fecha && element.tipo === tipo && element.pass === pass && element.email === email) {
indexArreglo = index;
}
});
datosInput.splice(indexArreglo, 1)
guardarLS();
}
const boton = document.getElementById('btn');
boton.addEventListener('click', () => {
let inputs = document.querySelectorAll('input');
let date = new Date()
let año = date.getFullYear();
let mes = date.getMonth();
let dia = date.getDate();
let fechaActual = [];
fechaActual.push(año)
fechaActual.push(mes)
fechaActual.push(dia)
fechaActual.toString();
console.log(fechaActual)
//fechaActual.replace(',','-');
let superFecha = fechaActual.toLocaleString();
let final = superFecha.replace(/,/g, "-");
console.log(final)
let nombre = inputs[0].value;
let fecha = final;
let tipo = inputs[2].value;
let pass = inputs[3].value;
let email = inputs[4].value;
if (nombre ==="" && fecha ==="" && tipo ==="" && pass ==="" && email ==="") {
console.log("campos vacios")
inputs.forEach(element => {
inputs[0].focus();
});
} else {
crearItem(nombre, fecha, tipo, pass, email);
guardarLS();
inputs.forEach(element => {
element.value = "";
});
}
} );
document.addEventListener('DOMContentLoaded', imprimirLS)
listaDeCuentas.addEventListener('click', (e) => {
let textoUno = e.path[1].children[0].innerHTML;
let textoDos = e.path[1].children[1].innerHTML;
let textoTres = e.path[2].children[1].children[0].innerHTML;
let textoCuatro = e.path[2].children[1].children[1].innerHTML;
let textoCinco = e.path[2].children[1].children[2].innerHTML;
if (e.target.innerHTML === "Borrar") {
borrarLS(textoUno, textoDos, textoTres, textoCuatro, textoCinco);
}
});