aboutsummaryrefslogtreecommitdiff
path: root/profile/public
diff options
context:
space:
mode:
authorLarsVomMars2020-10-10 18:36:57 +0200
committerLarsVomMars2020-10-10 18:36:57 +0200
commit44dd49a479e0b1a034f87317c910cd693ee7f8f9 (patch)
tree2f011c3e7bbc4130961c6fdbd8f15784c310740d /profile/public
parent5ad5d0968b8f7948bf076567b5f42f9a8bdb3cc0 (diff)
Answer types
I think
Diffstat (limited to 'profile/public')
-rw-r--r--profile/public/script.js27
-rw-r--r--profile/public/style.css7
-rw-r--r--profile/public/uploads/.gitkeep0
3 files changed, 24 insertions, 10 deletions
diff --git a/profile/public/script.js b/profile/public/script.js
index b0434fa..a386f56 100644
--- a/profile/public/script.js
+++ b/profile/public/script.js
@@ -12,6 +12,14 @@ function appendQuestions(question) {
const label = document.createElement("label");
label.for = "id_" + question.id;
label.textContent = question.question;
+ div.appendChild(label);
+
+ if (question.type === "file" && question.answer) {
+ const img = document.createElement("img");
+ img.src = "uploads/" + question.answer;
+ img.alt = "Image";
+ div.appendChild(img);
+ }
const field = document.createElement("input");
field.id = "id_" + question.id;
@@ -19,8 +27,10 @@ function appendQuestions(question) {
if (question.answer !== undefined) init = false;
field.value = question.answer;
field.placeholder = question.question;
+ field.type = question.type;
+ if (question.type === "file") field.accept = "image/*";
- div.append(label, field);
+ div.appendChild(field);
fs.insertBefore(div, fs.querySelector("button"));
}
@@ -30,14 +40,13 @@ form.addEventListener("submit", async (evt) => {
const method = init ? "POST" : "PUT";
const inputs = form.querySelectorAll("input");
- const body = {};
- for (const input of inputs) body[input.name] = input.value;
-
- const resp = await fetch(url, {
- headers: { "Content-Type": "application/json" },
- method,
- body: JSON.stringify(body),
- });
+ const body = new FormData();
+ for (const input of inputs) {
+ if (input.type !== "file") body.append(input.name, input.value);
+ else body.append(input.name, input.files[0] ?? "dbg-image");
+ }
+
+ const resp = await fetch(url, { method, body });
const res = await resp.text();
if (res !== "ok") alert("AHHHH");
});
diff --git a/profile/public/style.css b/profile/public/style.css
index 2e7b945..e674e71 100644
--- a/profile/public/style.css
+++ b/profile/public/style.css
@@ -16,7 +16,7 @@ main {
position: absolute;
max-height: 80%;
overflow-y: auto;
- width: 30%;
+ width: 50%;
left: 50%;
top: 50%;
-webkit-transform: translate(-50%, -50%);
@@ -32,6 +32,11 @@ select {
width: 100%;
}
+img {
+ max-width: 80%;
+ max-height: 80%;
+}
+
@media only screen and (max-width: 600px) {
main {
width: calc(100% - 50px);
diff --git a/profile/public/uploads/.gitkeep b/profile/public/uploads/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/profile/public/uploads/.gitkeep