-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
148 lines (124 loc) · 4.23 KB
/
index.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
document.querySelector(".submit").addEventListener("mouseover", () => {
document.querySelector(".submit").style.background = "#E6B90D";
});
document.querySelector(".submit").addEventListener("mouseout", () => {
document.querySelector(".submit").style.background = "#67C1EC";
});
document.querySelector(".submit").addEventListener("mouseover", () => {
document.querySelector(".imj").style.visibility = "visible";
});
document.querySelector(".submit").addEventListener("mouseout", () => {
document.querySelector(".imj").style.visibility = "hidden";
});
const contenedor = document.querySelector(".cuerpo");
function formulario() {
document.querySelector(".hijito").style.display = "block";
}
let titulo = document.getElementById("size_1");
let descrip = document.getElementById("size_2");
let verificacion = "";
function guardar() {
if (verificacion !== "") {
editar();
verificacion = "";
return;
}
let headd = {
id: Date.now(),
titulo: titulo.value,
descrip: descrip.value,
};
let formu = JSON.parse(localStorage.getItem("escrito"))
? JSON.parse(localStorage.getItem("escrito"))
: [];
console.log(headd);
formu.push(headd);
console.log(formu);
console.log(JSON.stringify(formu));
localStorage.setItem("escrito", JSON.stringify(formu));
document.getElementById("size_2").value = "";
document.getElementById("size_1").value = "";
renderisar();
}
let agregarcont = document.getElementById("contenido_tareas");
//DELEGACION DE EVENTOS
agregarcont.addEventListener("click", (e) => {
console.log(e.target.dataset.id)
if (e.target.matches(".editar")) {
titulo.value = e.target.parentElement.children[0].textContent;
descrip.value = e.target.parentElement.children[1].textContent;
formulario();
verificacion = e.target.dataset.id;
return;
}
});
function renderisar() {
console.log(localStorage.getItem("usuarios"));
let agregarcont = document.getElementById("contenido_tareas");
let formu = JSON.parse(localStorage.getItem("escrito"))
? JSON.parse(localStorage.getItem("escrito"))
: [];
agregarcont.innerHTML = "";
console.log(formu);
formu.forEach((index) => {
agregarcont.innerHTML += `
<div class="reg">
<h3 id="editar" class="mismo">${index.titulo}</h3>
<p class="mismo">${index.descrip}</p>
<button onclick="eliminar(${index.id})" class="xddd">eliminar</button>
<button class="kk editar" data-id=${index.id}>editar</button>
</div>`;
});
ocultar();
}
renderisar();
function eliminar(id) {
//me trae los elementos del local storage
const getdata = JSON.parse(localStorage.getItem("escrito"));
//nos filtra, y devulve todos los elemetos del local storage que sean diferentes al id que le estoy enviando COMO TAL EXCLUYE DEJANDO TODO MENOS LO QUE COINCIDE
let filterdata = getdata.filter((parametro) => parametro.id !== Number(id));
console.log(filterdata);
//INSErta el nuevo dato con los elemntos que ya excluyo
localStorage.setItem("escrito", JSON.stringify(filterdata));
//me muetra el html con las coassa
renderisar();
//let formu = JSON.parse(localStorage.getItem('escrito')) ? JSON.parse(localStorage.getItem('escrito')) :
//[]
//console.log(formu)
//
//formu.splice(formu, 1)
//
//localStorage.removeItem("escrito")
//
//agregarcont.innerHTML = ''
//console.log(formu)
}
function editar() {
///CREO UN NUEVO OBJETO
let headd = {
id: Date.now(),
titulo: titulo.value, //CAPTURA EL VALOR DEL FORM
descrip: descrip.value,
};
if (titulo.value === "" && descrip.value === "") {
alert("campos vacios");
return;
}
const getdata = JSON.parse(localStorage.getItem("escrito")); //INSERTANTO/RECUPERANDO LOS DATOS
let ub = getdata.map((item) =>
item.id === parseInt(verificacion) ? headd : item
); //SI CONINCIDE REMPLAZA EL OBJETO ENCONTARDO POR EL QUE TENGO
localStorage.setItem("escrito", JSON.stringify(ub)); //INSERTA EL NUEVO DATO
renderisar();
}
function ocultar() {
document.querySelector(".hijito").style.display = "none";
document.getElementById("cud").reset();
}
const valor = document.querySelector(".mismo");
console.log(valor);
/* function seteditable(element){
edit.contentEditable = "true";
edit.setAttribute("contenteditable", "true")
console.log('editable')
} */