This commit is contained in:
2026-02-10 19:16:33 +01:00
parent 19a6182267
commit 758767a4d4
6 changed files with 324 additions and 32 deletions

View File

@@ -16,12 +16,15 @@
<!-- Tasks for current activity -->
{% if tasks %}
<div style="margin: 1rem 0; padding: 1rem; background: rgba(255,255,255,0.7); border-radius: 5px;">
<h4>Tasks related to {{ current_entry.activity_name }}:</h4>
<h4>Active Tasks:</h4>
{% for task in tasks %}
<div style="margin-bottom: 5px;">
<div style="margin-bottom: 5px; display: flex; align-items: center;">
<input type="checkbox" id="task_{{ task._id }}"
onchange="completeTask('{{ task.name }}', '{{ current_entry._id }}', this)">
<label for="task_{{ task._id }}">{{ task.name }}</label>
{% if task.status == 'completed' %}checked{% endif %}
onchange="toggleTask('{{ task._id }}', this)">
<label for="task_{{ task._id }}" style="margin-left: 10px; flex-grow: 1; {% if task.status == 'completed' %}text-decoration: line-through;{% endif %}">
<a href="{{ url_for('task_detail', task_id=task._id) }}">{{ task.name }}</a>
</label>
</div>
{% endfor %}
</div>
@@ -52,18 +55,20 @@
updateTimer(); // run immediately
// AJAX for Tasks
function completeTask(name, entryId, checkbox) {
if(!checkbox.checked) return; // Only track completion for now
function toggleTask(taskId, checkbox) {
const formData = new FormData();
formData.append('task_name', name);
formData.append('entry_id', entryId);
formData.append('task_id', taskId);
formData.append('is_checked', checkbox.checked);
fetch('/complete_task', { method: 'POST', body: formData })
.then(r => r.json())
.then(data => {
checkbox.disabled = true; // Prevent double logging
checkbox.parentElement.style.textDecoration = "line-through";
const label = checkbox.nextElementSibling;
if(checkbox.checked) {
label.style.textDecoration = "line-through";
} else {
label.style.textDecoration = "none";
}
});
}
</script>