From fc0b7acc8fe211c5a03dc7b9c20d2b45cd1afdde Mon Sep 17 00:00:00 2001 From: TT-392 Date: Fri, 31 Oct 2025 20:54:49 +0100 Subject: [PATCH] Reimplement bold, and fix bug that broke adding fields --- app.py | 3 ++- templates/text.html | 61 +++++++++++++++++++++++++++++---------------- 2 files changed, 42 insertions(+), 22 deletions(-) diff --git a/app.py b/app.py index 7915f0c..c4fe7c1 100644 --- a/app.py +++ b/app.py @@ -119,8 +119,9 @@ def text_form(): "string": request.form["text" + str(i)], "size": int(request.form["size" + str(i)]), "pos": int(request.form["y_pos" + str(i)]), - "bold": False + "bold": "bold" + str(i) in request.form }) + print(request.form) # Clear previously saved font for font in session["fonts"]: diff --git a/templates/text.html b/templates/text.html index 3e0d526..2cc835e 100644 --- a/templates/text.html +++ b/templates/text.html @@ -60,7 +60,8 @@ Size:
Y position:
` + style="width: 40px">
+ Bold:
` const min_button = `` const plus_button = `` @@ -83,29 +84,35 @@ ["DNH", [{ text: "Do Not Hack", size: 130, - y_pos: 0 + y_pos: 0, + bold: true }, { text: "bottom text", size: 50, - y_pos: 130 + y_pos: 130, + bold: false }]], ["Food", [{ text: "Nickname", size: 130, - y_pos: 0 + y_pos: 0, + bold: true }, { text: new Date().toISOString().slice(0, 10), size: 50, - y_pos: 130 + y_pos: 130, + bold: false }]], ["Remove by", [{ text: "Remove by", size: 130, - y_pos: 0 + y_pos: 0, + bold: true }, { text: new Date(Date.now() + 3 * 7 * 24 * 60 * 60 * 1000).toISOString().slice(0, 10), size: 50, - y_pos: 130 + y_pos: 130, + bold: false }]], ]); @@ -113,19 +120,22 @@ function generate_and_populate_fields() { let html = "" + if (localStorage.getItem("text0") == null) { + template = templates.get("DNH"); + populate_local_storage_from_template(template); + } + let lineCnt = get_persistent("lineCount", 2); for (let i = 0; i < lineCnt; i++) { let modified_line_form = line_form; modified_line_form - template = templates.get("DNH"); - modified_line_form = modified_line_form.replace("[title]", "Line " + i); - modified_line_form = init_field("text", template[i].text, i, modified_line_form); - modified_line_form = init_field("size", template[i].size, i, modified_line_form); - modified_line_form = init_field("y_pos", template[i].y_pos, i, modified_line_form); + modified_line_form = init_field("text", "Text", i, modified_line_form); + modified_line_form = init_field("size", 130, i, modified_line_form); + modified_line_form = init_field("y_pos", 130 * i, i, modified_line_form); + modified_line_form = init_field("bold", false ? "checked" : "", i, modified_line_form); html += modified_line_form; - console.log(i); } if (lineCnt == 1) { html += plus_button; @@ -142,7 +152,11 @@ e.preventDefault(); for (const element of text_form.elements) { - localStorage.setItem(element.name, element.value); + if (element.type == 'checkbox') { + localStorage.setItem(element.name, element.checked ? "checked" : ""); + } else { + localStorage.setItem(element.name, element.value); + } } const lineCount = document.createElement('input'); @@ -163,19 +177,24 @@ generate_and_populate_fields(); } + function populate_local_storage_from_template(template) { + for (let i = 0; i < template.length; i++) { + localStorage.setItem("text" + i, template[i].text); + localStorage.setItem("size" + i, template[i].size); + localStorage.setItem("y_pos" + i, template[i].y_pos); + localStorage.setItem("bold" + i, template[i].bold ? "checked" : ""); + } + localStorage.setItem("lineCount", template.length); + } + const template_selector = document.getElementById("template") template_selector.addEventListener('submit', function(e) { e.preventDefault(); template = templates.get(template_selector.elements.template.value); + populate_local_storage_from_template(template); - for (let i = 0; i < template.length; i++) { - localStorage.setItem("text" + i, template[i].text); - localStorage.setItem("size" + i, template[i].size); - localStorage.setItem("y_pos" + i, template[i].y_pos); - } - localStorage.setItem("lineCount", template.length); - generate_and_populate_fields() + generate_and_populate_fields(); });