diff options
| author | Maksymilian Jopek <maks@jopek.eu> | 2022-03-16 23:20:59 +0100 |
|---|---|---|
| committer | Maksymilian Jopek <maks@jopek.eu> | 2022-03-16 23:20:59 +0100 |
| commit | bf7852bccce954aff2d7c94161f4d301a0f29684 (patch) | |
| tree | fc3f2aac4f843990b02992e02903df22857a1928 /src/main.js | |
| download | mlos-bf7852bccce954aff2d7c94161f4d301a0f29684.tar.gz mlos-bf7852bccce954aff2d7c94161f4d301a0f29684.tar.zst mlos-bf7852bccce954aff2d7c94161f4d301a0f29684.zip | |
Initial commit w/ v1.0.0
Diffstat (limited to 'src/main.js')
| -rw-r--r-- | src/main.js | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/main.js b/src/main.js new file mode 100644 index 0000000..db9a00f --- /dev/null +++ b/src/main.js @@ -0,0 +1,83 @@ +//import './style.css'; +function edit(e) { + e.preventDefault(); + const tar = e.target; + const form = tar.parentNode; + form.onseeked; + const id = tar.dataset.id; + const tds = document.querySelectorAll(`[data-id="${id}"]`); + const names = ["name", "thumbnail", "author", "magazine",]; + tds.forEach((el, i) => { + if (el.tagName === "TD") { + const v = el.innerHTML; + el.innerHTML = `<input name="${names[i]}" value="${v}">`; + } + else if (el === tar) { + el.style.display = "none"; + } + else { + const iel = el; + if (iel.type !== "hidden") { + iel.value = "Save"; + el.onclick = e => save(e, tds); + } + } + }); +} +//@ts-expect-error +window.edit = edit; +async function save(e, tds) { + console.log(tds); + const tar = e.target; + const body = new FormData(); + e.preventDefault(); + let i = 0; + tds.forEach((el) => { + if (el.tagName === "TD") { + const v = el.firstChild.value; + + if (i === 3) + el.innerHTML = v; + else + el.innerText = v; + + switch (i) { + case 0: + body.append("name", v); + break; + case 1: + body.append("thumbnail", v); + break; + case 2: + body.append("author", v); + break; + case 3: + body.append("magazine", v); + break; + } + i++; + } + else if (el === tar) { + const iel = el; + iel.value = "Remove"; + iel.onclick = null; + } + else { + const iel = el; + if (iel.type === "hidden") { + body.append(iel.name, iel.value); + } + else { + iel.style.display = ""; + } + } + }); + console.log(await (await fetch("api/add.php", { + method: "POST", + headers: { + // "Content-Type": "multipart/form-data", + }, + body + })).text()); +} +//# sourceMappingURL=main.js.map |
