{% extends "layout.html" %} {% block title %}{{ title }}{% endblock %} {% block content %} {{ breadcrumbs.breadcrumb_header( breadcrumbs=[ {'label': 'Work Log', 'url': url_for('main.list_worklog')} ], title=title, save_button=True, delete_button=log.id != None ) }} Start Timestamp End Timestamp Contact {% if log.contact_id %} {{ links.entry_link('user', log.contact_id) }} {% endif %} - {% for contact in users %} {{ contact.full_name }} {% endfor %} Work Item {% if log.work_item_id %} {{ links.entry_link('inventory_item', log.work_item_id) }} {% endif %} - {% for item in items %} {{ item.identifier }} {% endfor %} Complete? Follow Up? Quick Analysis? Notes {{ log.notes if log.notes else '' }} {% endblock %} {% block script %} const saveButton = document.getElementById("saveButton"); const deleteButton = document.getElementById("deleteButton"); if (saveButton) { saveButton.addEventListener("click", async (e) => { e.preventDefault(); const payload = { start_time: document.querySelector("input[name='start']").value, end_time: document.querySelector("input[name='end']").value, notes: document.querySelector("textarea[name='notes']").value, complete: document.querySelector("input[name='complete']").checked, analysis: document.querySelector("input[name='analysis']").checked, followup: document.querySelector("input[name='followup']").checked, contact_id: document.querySelector("select[name='contact']").value || null, work_item_id: document.querySelector("select[name='item']").value || null, }; try { const id = document.querySelector("#logId").value; const isEdit = id && id !== "None"; const endpoint = isEdit ? `/api/worklog/${id}` : "/api/worklog"; const method = isEdit ? "PUT" : "POST"; const response = await fetch(endpoint, { method, headers: { "Content-Type": "application/json" }, body: JSON.stringify(payload) }); const result = await response.json(); if (result.success) { localStorage.setItem("toastMessage", JSON.stringify({ message: isEdit ? "Work Log entry updated!" : "Work Log entry created!", type: "success" })); window.location.href = `/worklog/${result.id}`; } else { renderToast({ message: `Error: ${result.error}`, type: "danger" }); } } catch (err) { console.error(err) renderToast({ message: `Error: ${err}`, type: "danger" }); } }); } if (deleteButton) { deleteButton.addEventListener("click", async () => { const id = document.querySelector("#logId").value; if (!id || id === "None") { renderToast({ message: "No item ID found to delete.", type: "danger" }); return; } if (!confirm("Are you sure you want to delete this work log entry? This action cannot be undone.")) { return; } try { const response = await fetch(`/api/worklog/${id}`, { method: "DELETE" }); const result = await response.json(); if (result.success) { localStorage.setItem("toastMessage", JSON.stringify({ message: "Work log entry deleted.", type: "success" })); window.location.href = "/worklog"; } else { renderToast({ message: `Error: ${result.error}`, type: "danger" }); } } catch (err) { console.log(err); renderToast({ message: `Error: ${err}`, type: "danger" }); } }); } {% endblock %}