From 0c45adc72d0f5c276509f2a6c5971be5dc7679aa Mon Sep 17 00:00:00 2001 From: LarsVomMars Date: Wed, 27 Jan 2021 22:16:22 +0100 Subject: Hm --- profile/public/script.js | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'profile/public/script.js') diff --git a/profile/public/script.js b/profile/public/script.js index b927f9f..ba2284b 100644 --- a/profile/public/script.js +++ b/profile/public/script.js @@ -2,6 +2,21 @@ const fs = document.querySelector("fieldset"); const form = document.querySelector("form"); let init = true; +const popup = document.querySelector(".popup"); +const popupImage = document.querySelector("#popup-img"); +const cropper = new Cropper(popupImage, { // ration 2/3 + dragMode: 'move', + aspectRatio: 2 / 3, + autoCropArea: 0.65, + restore: false, + guides: false, + center: false, + highlight: false, + cropBoxMovable: false, + cropBoxResizable: false, + toggleDragModeOnDblclick: false, +}); + function updateHeading(user) { document.getElementById("username").textContent = `Steckbrief: ${user.name} ${user.middlename || ""} ${user.surname}`; } @@ -28,7 +43,22 @@ function appendQuestions(question) { field.value = question.answer || ""; field.placeholder = question.question; field.type = question.type; - if (question.type === "file") field.accept = "image/*"; + if (question.type === "file") { + field.accept = "image/*"; + field.addEventListener("input", e => { + const file = e.target.files[0]; + popupImage.file = file; + const reader = new FileReader(); + reader.onload = (function (aImg) { + return function (e) { + aImg.src = e.target.result; + }; + })(popupImage); + reader.readAsDataURL(file); + popupImage.style.display = "block !important"; + console.log(cropper); + }); + } div.appendChild(field); fs.insertBefore(div, fs.querySelector("button")); -- cgit v1.2.3 From 08adc7079833e15f5caf4594037bbf580644411b Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Thu, 28 Jan 2021 14:15:46 +0100 Subject: ez --- profile/index.js | 20 ++++++++++---- profile/public/index.html | 70 +++++++++++++++++++++++++---------------------- profile/public/script.js | 39 +++++++++++++++----------- 3 files changed, 75 insertions(+), 54 deletions(-) (limited to 'profile/public/script.js') diff --git a/profile/index.js b/profile/index.js index ee81632..d9ee068 100644 --- a/profile/index.js +++ b/profile/index.js @@ -182,10 +182,10 @@ app.delete("/api/comment", async (req, res) => { // Char API app.get("/api/char/:uid", async (req, res) => { const uid = req.params.uid; - const char = await db.query( - "SELECT txt FROM profile_char WHERE profile_id = ? AND user_id = ?", - [uid, req.session.uid], - ); + const char = await db.query("SELECT txt FROM profile_char WHERE profile_id = ? AND user_id = ?", [ + uid, + req.session.uid, + ]); res.json(char.length > 0 ? char[0] : {}); }); @@ -194,7 +194,11 @@ app.post("/api/char/:uid", async (req, res) => { const { char } = req.body; if (!char || char.length > 255) return res.json({ success: false }); try { - await db.query("INSERT INTO profile_char (profile_id, user_id, txt) VALUE (?,?,?)", [uid, req.session.uid, char]); + await db.query("INSERT INTO profile_char (profile_id, user_id, txt) VALUE (?,?,?)", [ + uid, + req.session.uid, + char, + ]); res.json({ success: true }); } catch (e) { console.error(e); @@ -207,7 +211,11 @@ app.put("/api/char/:uid", async (req, res) => { const { char } = req.body; if (!char || char.length > 255) return res.json({ success: false }); try { - await db.query("UPDATE profile_char SET txt = ? WHERE profile_id = ? AND user_id = ?", [char, uid, req.session.uid]); + await db.query("UPDATE profile_char SET txt = ? WHERE profile_id = ? AND user_id = ?", [ + char, + uid, + req.session.uid, + ]); res.json({ success: true }); } catch (e) { console.error(e); diff --git a/profile/public/index.html b/profile/public/index.html index f8fdee5..e6f2e6c 100644 --- a/profile/public/index.html +++ b/profile/public/index.html @@ -1,40 +1,46 @@ -
- - - + + + - - - -