2024-09-25 19:48:36 +00:00
<!-- SPDX - License - Identifier: GPL - 3.0 - or - later -->
2024-09-14 18:49:57 +00:00
{% extends "base.html" %}
2024-12-04 21:26:50 +00:00
{% block head %}
< title > LabelPrinter Label generator< / title >
2025-10-31 14:27:40 +00:00
2024-12-04 21:26:50 +00:00
{% endblock %}
2025-10-31 20:23:58 +00:00
<!-- TODO: Make fields outside the form also update based on localStorage, instead of serverside, add dropshadows to white text, and make size and y - position boxes smaller, also, text alignment -->
2024-09-14 18:49:57 +00:00
{% block content %}
2025-10-31 18:54:10 +00:00
< form id = "template" >
2024-09-14 18:49:57 +00:00
< label for = "template" > Template:< / label >
< select name = "template" >
< option value = "DNH" > Do not hack< / option >
< option value = "Food" > Food< / option >
2025-10-31 18:54:10 +00:00
< option value = "Remove by" > Remove by< / option >
2024-09-14 18:49:57 +00:00
< / select >
< input type = "submit" value = "Apply" >
< / form >
2025-10-31 14:27:40 +00:00
< form method = "POST" action = "/text-form" , id = "text_form" >
2025-10-31 20:17:11 +00:00
< div id = "input" , class = "tiles" > < / div >
< div id = "plus minus buttons" > < / div >
2024-11-27 23:59:36 +00:00
< h2 > Font< / h2 >
< label for = "font" > Font:< / label >
< select name = "font" >
{% for font in fonts %}
< option value = "{{ font }}" { % if fonts [ font ] . selected % } selected { % endif % } > {{ fonts[font].name }}< / option >
{% endfor %}
< / select >
< br / >
2024-09-25 20:36:55 +00:00
< input type = "submit" value = "Generate preview" >
2024-09-14 18:49:57 +00:00
< / form >
2024-09-26 18:38:41 +00:00
{% if info %}
< p class = "info" style = "color: {{info_color}}" > {{info}}< / p >
{% endif %}
2024-09-14 18:49:57 +00:00
{% if filename %}
2024-09-25 20:23:32 +00:00
< img src = "user_data/{{filename}}" alt = "Generated Image" style = "height: 150px; width: auto;" >
2024-09-14 18:49:57 +00:00
< form method = "POST" action = "/text-print" >
{% if cut %}
< input type = "checkbox" name = "cut" value = "cut" checked >
{%else %}
< input type = "checkbox" name = "cut" value = "cut" >
{%endif%}
< label for = "cut" > Cut paper after printing < / label > < br >
2024-09-15 11:54:29 +00:00
< input type = "submit" value = "Print" style = "font-size: 2em; padding: 20px 40px;" >
2024-09-14 18:49:57 +00:00
< / form >
{% endif %}
2025-10-31 14:27:40 +00:00
< script >
2025-10-31 20:17:11 +00:00
const line_form = `< div > < h2 > [title]< / h2 >
2025-10-31 14:27:40 +00:00
Text:< br >
< textarea name = "[text]" > (text)< / textarea > < br >
Size: < input type = "number" value = "(size)" name = "[size]" min = "0" required
style="width: 40px">< br >
Y position: < input type = "number" value = "(y_pos)" name = "[y_pos]" required
2025-10-31 19:54:49 +00:00
style="width: 40px">< br >
2025-10-31 20:17:11 +00:00
Bold: < input type = "checkbox" name = "[bold]" value = "bold" ( bold ) > < / div > `
2025-10-31 14:27:40 +00:00
const min_button = `< button type = "button" onClick = "remove_line()" > -< / button > `
const plus_button = `< button type = "button" onClick = "add_line()" > +< / button > `
function get_persistent(name, initial_value) {
if (localStorage.getItem(name) == null) {
localStorage.setItem(name, initial_value)
}
return localStorage.getItem(name)
}
function init_field(local_name, initial_value, i, html) {
html = html.replace("[" + local_name + "]", local_name + i);
html = html.replace("(" + local_name + ")", get_persistent(local_name + i, initial_value));
return html;
}
2025-10-31 18:54:10 +00:00
const templates = new Map ([
["DNH", [{
text: "Do Not Hack",
size: 130,
2025-10-31 19:54:49 +00:00
y_pos: 0,
bold: true
2025-10-31 18:54:10 +00:00
}, {
text: "bottom text",
size: 50,
2025-10-31 19:54:49 +00:00
y_pos: 130,
bold: false
2025-10-31 18:54:10 +00:00
}]],
["Food", [{
text: "Nickname",
size: 130,
2025-10-31 19:54:49 +00:00
y_pos: 0,
bold: true
2025-10-31 18:54:10 +00:00
}, {
text: new Date().toISOString().slice(0, 10),
size: 50,
2025-10-31 19:54:49 +00:00
y_pos: 130,
bold: false
2025-10-31 18:54:10 +00:00
}]],
["Remove by", [{
text: "Remove by",
size: 130,
2025-10-31 19:54:49 +00:00
y_pos: 0,
bold: true
2025-10-31 18:54:10 +00:00
}, {
text: new Date(Date.now() + 3 * 7 * 24 * 60 * 60 * 1000).toISOString().slice(0, 10),
size: 50,
2025-10-31 19:54:49 +00:00
y_pos: 130,
bold: false
2025-10-31 18:54:10 +00:00
}]],
]);
function generate_and_populate_fields() {
2025-10-31 14:27:40 +00:00
let html = ""
2025-10-31 19:54:49 +00:00
if (localStorage.getItem("text0") == null) {
template = templates.get("DNH");
populate_local_storage_from_template(template);
}
2025-10-31 14:27:40 +00:00
let lineCnt = get_persistent("lineCount", 2);
for (let i = 0; i < lineCnt ; i + + ) {
let modified_line_form = line_form;
modified_line_form
modified_line_form = modified_line_form.replace("[title]", "Line " + i);
2025-10-31 19:54:49 +00:00
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);
2025-10-31 14:27:40 +00:00
html += modified_line_form;
}
2025-10-31 20:17:11 +00:00
let buttons = ""
2025-10-31 14:27:40 +00:00
if (lineCnt == 1) {
2025-10-31 20:17:11 +00:00
buttons = plus_button;
2025-10-31 14:27:40 +00:00
} else {
2025-10-31 20:17:11 +00:00
buttons += min_button + plus_button;
2025-10-31 14:27:40 +00:00
}
document.getElementById("input").innerHTML = html;
2025-10-31 20:17:11 +00:00
document.getElementById("plus minus buttons").innerHTML = buttons;
2025-10-31 14:27:40 +00:00
}
2025-10-31 18:54:10 +00:00
generate_and_populate_fields()
2025-10-31 14:27:40 +00:00
const text_form = document.getElementById("text_form")
text_form.addEventListener('submit', function(e) {
e.preventDefault();
for (const element of text_form.elements) {
2025-10-31 19:54:49 +00:00
if (element.type == 'checkbox') {
localStorage.setItem(element.name, element.checked ? "checked" : "");
} else {
localStorage.setItem(element.name, element.value);
}
2025-10-31 14:27:40 +00:00
}
const lineCount = document.createElement('input');
lineCount.type = 'hidden';
lineCount.name = 'lineCount';
lineCount.value = localStorage.getItem("lineCount");
text_form.appendChild(lineCount);
text_form.submit();
});
function add_line() {
localStorage.setItem("lineCount", Number(localStorage.getItem("lineCount")) + 1);
2025-10-31 18:54:10 +00:00
generate_and_populate_fields();
2025-10-31 14:27:40 +00:00
}
function remove_line() {
localStorage.setItem("lineCount", Number(localStorage.getItem("lineCount")) - 1);
2025-10-31 18:54:10 +00:00
generate_and_populate_fields();
2025-10-31 14:27:40 +00:00
}
2025-10-31 19:54:49 +00:00
function populate_local_storage_from_template(template) {
2025-10-31 18:54:10 +00:00
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);
2025-10-31 19:54:49 +00:00
localStorage.setItem("bold" + i, template[i].bold ? "checked" : "");
2025-10-31 18:54:10 +00:00
}
localStorage.setItem("lineCount", template.length);
2025-10-31 19:54:49 +00:00
}
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);
generate_and_populate_fields();
2025-10-31 18:54:10 +00:00
});
2025-10-31 14:27:40 +00:00
< / script >
2024-09-26 18:38:41 +00:00
2024-09-14 18:49:57 +00:00
{% endblock %}