From 53efc8551d8efe8de27b0048a350bc1538606092 Mon Sep 17 00:00:00 2001 From: Yaro Kasear Date: Thu, 2 Oct 2025 15:42:00 -0500 Subject: [PATCH] Updating notes support done! --- inventory/routes/entry.py | 11 +-- inventory/templates/inventory_note.html | 108 ++++++++++++++++++++++++ inventory/templates/submit_button.html | 16 ++-- inventory/templates/update_list.html | 10 +-- 4 files changed, 129 insertions(+), 16 deletions(-) create mode 100644 inventory/templates/inventory_note.html diff --git a/inventory/routes/entry.py b/inventory/routes/entry.py index aa8bad4..94b1890 100644 --- a/inventory/routes/entry.py +++ b/inventory/routes/entry.py @@ -48,7 +48,9 @@ def init_entry_routes(app): "device_type", "owner", "location", "condition", "image", "notes"] fields_spec = [ {"name": "label", "type": "display", "label": "", "row": "label", - "attrs": {"class": "display-6 mb-3"}}, + "attrs": {"class": "display-6 mb-3"}, "wrap": {"class": "col"}}, + {"name": "submit", "label": "", "row": "label", "type": "template", "template": "submit_button.html", + "wrap": {"class": "col-auto text-end me-2"}, "attrs": {"data-model": model}}, {"name": "name", "row": "names", "label": "Name", "wrap": {"class": "col-3"}, "attrs": {"class": "form-control"}, "label_attrs": {"class": "form-label"}}, {"name": "serial", "row": "names", "label": "Serial #", "wrap": {"class": "col"}, @@ -72,12 +74,11 @@ def init_entry_routes(app): {"name": "image", "label": "", "row": "image", "type": "template", "label_spec": "{filename}", "template": "image_display.html", "attrs": {"class": "img-fluid img-thumbnail h-auto"}, "wrap": {"class": "h-100 w-100"}}, - {"name": "notes", "type": "textarea", "label": "Notes", "row": "notes", "wrap": {"class": "col"}, - "attrs": {"class": "form-control", "rows": 10, "style": "resize: none;"}, - "label_attrs": {"class": "form-label"}}, + {"name": "notes", "type": "template", "label": "Notes", "row": "notes", "wrap": {"class": "col"}, + "template": "inventory_note.html"}, ] layout = [ - {"name": "label", "order": 5}, + {"name": "label", "order": 5, "attrs": {"class": "row align-items-center"}}, {"name": "kitchen_sink", "order": 6, "attrs": {"class": "row"}}, {"name": "everything", "order": 10, "attrs": {"class": "col"}, "parent": "kitchen_sink"}, {"name": "names", "order": 20, "attrs": {"class": "row"}, "parent": "everything"}, diff --git a/inventory/templates/inventory_note.html b/inventory/templates/inventory_note.html new file mode 100644 index 0000000..22dab40 --- /dev/null +++ b/inventory/templates/inventory_note.html @@ -0,0 +1,108 @@ + +
+
+ +
+ + +
+
+ + + + + + \ No newline at end of file diff --git a/inventory/templates/submit_button.html b/inventory/templates/submit_button.html index 2d569b0..000bb62 100644 --- a/inventory/templates/submit_button.html +++ b/inventory/templates/submit_button.html @@ -39,6 +39,8 @@ } }); + console.log(out); + return out; } @@ -69,13 +71,15 @@ const json = formToJson(e.target); json.id = {{ field['template_ctx']['values']['id'] }}; - // map friendly names to real FK columns if needed - if (json.contact && !json.contact_id) json.contact_id = Number(json.contact) || null; - if (json.work_item && !json.work_item_id) json.work_item_id = Number(json.work_item) || null; + const model_name = {{ field['attrs']['data-model'] | tojson }}; - // child mutations - json.updates = collectEditedUpdates(); - json.delete_update_ids = collectDeletedIds(); + if(model_name === 'inventory') { + json.notes = getMarkdown().trim(); + } else if (model_name === 'worklog') { + // child mutations + json.updates = collectEditedUpdates(); + json.delete_update_ids = collectDeletedIds(); + } try { const response = await fetch( diff --git a/inventory/templates/update_list.html b/inventory/templates/update_list.html index f3eb929..e9a2ab0 100644 --- a/inventory/templates/update_list.html +++ b/inventory/templates/update_list.html @@ -65,8 +65,8 @@ const html = marked.parse(md || ""); container.innerHTML = DOMPurify.sanitize(html, { ADD_ATTR: ['target','rel'] }); for (const a of container.querySelectorAll('a[href]')) { - a.setAttribute('target','_blank'); - a.setAttribute('rel','noopener noreferrer nofollow'); + a.setAttribute('target', '_blank'); + a.setAttribute('rel', 'noopener noreferrer nofollow'); } } @@ -79,9 +79,9 @@ container.innerHTML = `
- - - + + +
`;