Push to Gitea ๐
This commit is contained in:
634
static/css/style.css
Normal file
634
static/css/style.css
Normal file
@@ -0,0 +1,634 @@
|
||||
/* Flado - Modern Todo App Styles */
|
||||
|
||||
:root {
|
||||
--primary-color: #3b82f6;
|
||||
--primary-hover: #2563eb;
|
||||
--success-color: #10b981;
|
||||
--danger-color: #ef4444;
|
||||
--text-primary: #1f2937;
|
||||
--text-secondary: #6b7280;
|
||||
--bg-primary: #ffffff;
|
||||
--bg-secondary: #f9fafb;
|
||||
--border-color: #e5e7eb;
|
||||
--shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
|
||||
--shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
|
||||
--shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
|
||||
--radius: 8px;
|
||||
--transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
[data-theme="dark"] {
|
||||
--text-primary: #f9fafb;
|
||||
--text-secondary: #d1d5db;
|
||||
--bg-primary: #111827;
|
||||
--bg-secondary: #1f2937;
|
||||
--border-color: #374151;
|
||||
}
|
||||
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
||||
color: var(--text-primary);
|
||||
background-color: var(--bg-secondary);
|
||||
line-height: 1.6;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.app-container {
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
padding: 2rem 1rem;
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.app-header {
|
||||
text-align: center;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.app-title {
|
||||
font-size: 3rem;
|
||||
font-weight: 700;
|
||||
color: var(--primary-color);
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.app-subtitle {
|
||||
color: var(--text-secondary);
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.app-main {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.app-footer {
|
||||
text-align: center;
|
||||
margin-top: 3rem;
|
||||
padding-top: 2rem;
|
||||
border-top: 1px solid var(--border-color);
|
||||
color: var(--text-secondary);
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
/* Controls Bar */
|
||||
.controls-bar {
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.search-box {
|
||||
position: relative;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.search-input {
|
||||
width: 100%;
|
||||
padding: 0.75rem 1rem;
|
||||
font-size: 1rem;
|
||||
border: 2px solid var(--border-color);
|
||||
border-radius: var(--radius);
|
||||
background-color: var(--bg-primary);
|
||||
color: var(--text-primary);
|
||||
transition: var(--transition);
|
||||
}
|
||||
|
||||
.search-input:focus {
|
||||
outline: none;
|
||||
border-color: var(--primary-color);
|
||||
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
|
||||
}
|
||||
|
||||
.search-clear {
|
||||
position: absolute;
|
||||
right: 0.75rem;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
background: none;
|
||||
border: none;
|
||||
font-size: 1.5rem;
|
||||
color: var(--text-secondary);
|
||||
cursor: pointer;
|
||||
padding: 0.25rem 0.5rem;
|
||||
}
|
||||
|
||||
.filter-tabs {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.filter-tab {
|
||||
padding: 0.5rem 1rem;
|
||||
text-decoration: none;
|
||||
color: var(--text-secondary);
|
||||
border-radius: var(--radius);
|
||||
transition: var(--transition);
|
||||
font-size: 0.875rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.filter-tab:hover {
|
||||
background-color: var(--bg-primary);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.filter-tab.active {
|
||||
background-color: var(--primary-color);
|
||||
color: white;
|
||||
}
|
||||
|
||||
/* Quick Add Form */
|
||||
.quick-add-form {
|
||||
background-color: var(--bg-primary);
|
||||
border-radius: var(--radius);
|
||||
padding: 1rem;
|
||||
margin-bottom: 1.5rem;
|
||||
box-shadow: var(--shadow-sm);
|
||||
}
|
||||
|
||||
.task-form {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.task-input {
|
||||
flex: 1;
|
||||
padding: 0.75rem;
|
||||
font-size: 1rem;
|
||||
border: 2px solid var(--border-color);
|
||||
border-radius: var(--radius);
|
||||
background-color: var(--bg-secondary);
|
||||
color: var(--text-primary);
|
||||
transition: var(--transition);
|
||||
}
|
||||
|
||||
.task-input:focus {
|
||||
outline: none;
|
||||
border-color: var(--primary-color);
|
||||
}
|
||||
|
||||
.add-button {
|
||||
padding: 0.75rem 1.5rem;
|
||||
background-color: var(--primary-color);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: var(--radius);
|
||||
font-size: 1.5rem;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: var(--transition);
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.add-button:hover {
|
||||
background-color: var(--primary-hover);
|
||||
}
|
||||
|
||||
.task-details-expand {
|
||||
margin-top: 0.75rem;
|
||||
}
|
||||
|
||||
.expand-button {
|
||||
background: transparent;
|
||||
border: 1.5px solid var(--border-color);
|
||||
color: var(--text-secondary);
|
||||
padding: 0.5rem 1rem;
|
||||
border-radius: var(--radius);
|
||||
font-size: 0.875rem;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: var(--transition);
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
}
|
||||
|
||||
.expand-icon {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 1.125rem;
|
||||
height: 1.125rem;
|
||||
font-size: 1rem;
|
||||
font-weight: 300;
|
||||
line-height: 1;
|
||||
transition: var(--transition);
|
||||
}
|
||||
|
||||
.expand-button:hover {
|
||||
background-color: var(--bg-secondary);
|
||||
border-color: var(--primary-color);
|
||||
color: var(--primary-color);
|
||||
transform: translateY(-1px);
|
||||
box-shadow: var(--shadow-sm);
|
||||
}
|
||||
|
||||
.expand-button:hover .expand-icon {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
|
||||
.expand-button:active {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
.expand-button:active .expand-icon {
|
||||
transform: rotate(90deg) scale(0.95);
|
||||
}
|
||||
|
||||
.task-details-form {
|
||||
margin-top: 1rem;
|
||||
padding-top: 1rem;
|
||||
border-top: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.task-description-input,
|
||||
.task-due-date-input {
|
||||
width: 100%;
|
||||
padding: 0.75rem;
|
||||
margin-bottom: 0.75rem;
|
||||
font-size: 0.875rem;
|
||||
border: 2px solid var(--border-color);
|
||||
border-radius: var(--radius);
|
||||
background-color: var(--bg-secondary);
|
||||
color: var(--text-primary);
|
||||
font-family: inherit;
|
||||
}
|
||||
|
||||
.task-description-input:focus,
|
||||
.task-due-date-input:focus {
|
||||
outline: none;
|
||||
border-color: var(--primary-color);
|
||||
}
|
||||
|
||||
.form-actions {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
/* Task List */
|
||||
.task-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.task-item {
|
||||
background-color: var(--bg-primary);
|
||||
border-radius: var(--radius);
|
||||
padding: 1rem;
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 1rem;
|
||||
box-shadow: var(--shadow-sm);
|
||||
transition: var(--transition);
|
||||
cursor: move;
|
||||
}
|
||||
|
||||
.task-item:hover {
|
||||
box-shadow: var(--shadow-md);
|
||||
}
|
||||
|
||||
.task-item.completed {
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.task-item.completed .task-title {
|
||||
text-decoration: line-through;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.task-item.dragging {
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.task-checkbox {
|
||||
margin-top: 0.25rem;
|
||||
}
|
||||
|
||||
.task-check {
|
||||
width: 1.25rem;
|
||||
height: 1.25rem;
|
||||
cursor: pointer;
|
||||
accent-color: var(--primary-color);
|
||||
}
|
||||
|
||||
.task-content {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.task-main {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.task-title-wrapper {
|
||||
flex: 1;
|
||||
min-width: 200px;
|
||||
}
|
||||
|
||||
.task-title {
|
||||
width: 100%;
|
||||
font-size: 1rem;
|
||||
font-weight: 500;
|
||||
border: none;
|
||||
background: transparent;
|
||||
color: var(--text-primary);
|
||||
padding: 0.25rem 0;
|
||||
cursor: text;
|
||||
}
|
||||
|
||||
.task-title:focus {
|
||||
outline: none;
|
||||
background-color: var(--bg-secondary);
|
||||
padding: 0.25rem 0.5rem;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.task-title[readonly] {
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.task-description {
|
||||
margin-top: 0.5rem;
|
||||
font-size: 0.875rem;
|
||||
color: var(--text-secondary);
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.task-tags {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
margin-top: 0.5rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.task-tag {
|
||||
padding: 0.25rem 0.5rem;
|
||||
border-radius: 4px;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.due-date-badge {
|
||||
padding: 0.25rem 0.75rem;
|
||||
border-radius: 12px;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 500;
|
||||
background-color: var(--bg-secondary);
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.due-date-badge.overdue {
|
||||
background-color: var(--danger-color);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.task-actions {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
opacity: 0;
|
||||
transition: var(--transition);
|
||||
}
|
||||
|
||||
.task-item:hover .task-actions {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.task-edit,
|
||||
.task-delete {
|
||||
background: none;
|
||||
border: none;
|
||||
font-size: 1.25rem;
|
||||
color: var(--text-secondary);
|
||||
cursor: pointer;
|
||||
padding: 0.25rem;
|
||||
transition: var(--transition);
|
||||
}
|
||||
|
||||
.task-edit:hover {
|
||||
color: var(--primary-color);
|
||||
}
|
||||
|
||||
.task-delete:hover {
|
||||
color: var(--danger-color);
|
||||
}
|
||||
|
||||
/* Empty State */
|
||||
.empty-state {
|
||||
text-align: center;
|
||||
padding: 3rem 1rem;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.empty-message {
|
||||
font-size: 1.125rem;
|
||||
}
|
||||
|
||||
/* Modal */
|
||||
.modal {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
background-color: var(--bg-primary);
|
||||
border-radius: var(--radius);
|
||||
width: 90%;
|
||||
max-width: 500px;
|
||||
max-height: 90vh;
|
||||
overflow-y: auto;
|
||||
box-shadow: var(--shadow-lg);
|
||||
}
|
||||
|
||||
.modal-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 1.5rem;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.modal-header h2 {
|
||||
font-size: 1.5rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.modal-close {
|
||||
background: none;
|
||||
border: none;
|
||||
font-size: 1.5rem;
|
||||
color: var(--text-secondary);
|
||||
cursor: pointer;
|
||||
padding: 0.25rem;
|
||||
}
|
||||
|
||||
.modal-body {
|
||||
padding: 1.5rem;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.form-group label {
|
||||
display: block;
|
||||
margin-bottom: 0.5rem;
|
||||
font-weight: 500;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.form-group input,
|
||||
.form-group textarea {
|
||||
width: 100%;
|
||||
padding: 0.75rem;
|
||||
font-size: 1rem;
|
||||
border: 2px solid var(--border-color);
|
||||
border-radius: var(--radius);
|
||||
background-color: var(--bg-secondary);
|
||||
color: var(--text-primary);
|
||||
font-family: inherit;
|
||||
}
|
||||
|
||||
.form-group input:focus,
|
||||
.form-group textarea:focus {
|
||||
outline: none;
|
||||
border-color: var(--primary-color);
|
||||
}
|
||||
|
||||
.save-button,
|
||||
.cancel-button {
|
||||
padding: 0.75rem 1.5rem;
|
||||
border: none;
|
||||
border-radius: var(--radius);
|
||||
font-size: 1rem;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: var(--transition);
|
||||
}
|
||||
|
||||
.save-button {
|
||||
background-color: var(--primary-color);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.save-button:hover {
|
||||
background-color: var(--primary-hover);
|
||||
}
|
||||
|
||||
.cancel-button {
|
||||
background-color: var(--bg-secondary);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.cancel-button:hover {
|
||||
background-color: var(--border-color);
|
||||
}
|
||||
|
||||
/* Delete Confirmation Modal */
|
||||
.delete-modal-content {
|
||||
max-width: 400px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.delete-modal-icon {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
margin: 2rem auto 1rem;
|
||||
background-color: rgba(239, 68, 68, 0.1);
|
||||
border-radius: 50%;
|
||||
color: var(--danger-color);
|
||||
}
|
||||
|
||||
.delete-modal-body {
|
||||
padding: 0 2rem 2rem;
|
||||
}
|
||||
|
||||
.delete-modal-title {
|
||||
font-size: 1.5rem;
|
||||
font-weight: 600;
|
||||
margin-bottom: 0.75rem;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.delete-modal-message {
|
||||
color: var(--text-secondary);
|
||||
margin-bottom: 2rem;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.delete-modal-actions {
|
||||
justify-content: center;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.delete-confirm-button {
|
||||
padding: 0.75rem 1.5rem;
|
||||
border: none;
|
||||
border-radius: var(--radius);
|
||||
font-size: 1rem;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: var(--transition);
|
||||
background-color: var(--danger-color);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.delete-confirm-button:hover {
|
||||
background-color: #dc2626;
|
||||
transform: translateY(-1px);
|
||||
box-shadow: var(--shadow-md);
|
||||
}
|
||||
|
||||
.delete-confirm-button:active {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.app-container {
|
||||
padding: 1rem 0.5rem;
|
||||
}
|
||||
|
||||
.app-title {
|
||||
font-size: 2rem;
|
||||
}
|
||||
|
||||
.task-item {
|
||||
padding: 0.75rem;
|
||||
}
|
||||
|
||||
.task-actions {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.task-main {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.task-title-wrapper {
|
||||
min-width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
BIN
static/favicon.ico
Normal file
BIN
static/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
569
static/js/main.js
Normal file
569
static/js/main.js
Normal file
@@ -0,0 +1,569 @@
|
||||
// Flado - Main JavaScript
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
initializeApp();
|
||||
});
|
||||
|
||||
function initializeApp() {
|
||||
setupTaskForm();
|
||||
setupTaskInteractions();
|
||||
setupSearch();
|
||||
setupDragAndDrop();
|
||||
setupKeyboardShortcuts();
|
||||
}
|
||||
|
||||
// CSRF Protection Helpers
|
||||
function getCSRFToken() {
|
||||
const metaTag = document.querySelector('meta[name="csrf-token"]');
|
||||
return metaTag ? metaTag.getAttribute('content') : '';
|
||||
}
|
||||
|
||||
async function apiRequest(url, options = {}) {
|
||||
const token = getCSRFToken();
|
||||
const headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRFToken': token,
|
||||
...options.headers
|
||||
};
|
||||
|
||||
return fetch(url, {
|
||||
...options,
|
||||
headers,
|
||||
credentials: 'same-origin'
|
||||
});
|
||||
}
|
||||
|
||||
function setupTaskForm() {
|
||||
const form = document.getElementById("task-form");
|
||||
const titleInput = document.getElementById("task-title-input");
|
||||
const descriptionInput = document.getElementById("task-description-input");
|
||||
const dueDateInput = document.getElementById("task-due-date-input");
|
||||
const detailsToggle = document.getElementById("task-details-toggle");
|
||||
const detailsForm = document.getElementById("task-details-form");
|
||||
const cancelDetails = document.getElementById("cancel-details");
|
||||
|
||||
if (!form) return;
|
||||
|
||||
if (titleInput && sessionStorage.getItem("focusTaskInput") === "true") {
|
||||
titleInput.focus();
|
||||
sessionStorage.removeItem("focusTaskInput");
|
||||
}
|
||||
|
||||
form.addEventListener("submit", async function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
const title = titleInput.value.trim();
|
||||
if (!title) return;
|
||||
|
||||
const description = descriptionInput.value.trim() || null;
|
||||
const dueDate = dueDateInput.value || null;
|
||||
|
||||
try {
|
||||
const response = await apiRequest("/api/tasks", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
title,
|
||||
description,
|
||||
due_date: dueDate,
|
||||
tags: [],
|
||||
}),
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
const task = await response.json();
|
||||
sessionStorage.setItem("focusTaskInput", "true");
|
||||
location.reload();
|
||||
} else {
|
||||
const error = await response.json();
|
||||
alert("Error: " + (error.error || "Failed to create task"));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error creating task:", error);
|
||||
alert("Failed to create task. Please try again.");
|
||||
}
|
||||
|
||||
titleInput.value = "";
|
||||
descriptionInput.value = "";
|
||||
dueDateInput.value = "";
|
||||
detailsForm.style.display = "none";
|
||||
detailsToggle.style.display = "none";
|
||||
if (titleInput) {
|
||||
titleInput.focus();
|
||||
}
|
||||
});
|
||||
|
||||
titleInput.addEventListener("input", function () {
|
||||
if (this.value.trim() && detailsForm.style.display === "none") {
|
||||
detailsToggle.style.display = "block";
|
||||
}
|
||||
});
|
||||
|
||||
if (detailsToggle) {
|
||||
detailsToggle.addEventListener("click", function () {
|
||||
detailsForm.style.display =
|
||||
detailsForm.style.display === "none" ? "block" : "none";
|
||||
});
|
||||
}
|
||||
|
||||
if (cancelDetails) {
|
||||
cancelDetails.addEventListener("click", function () {
|
||||
descriptionInput.value = "";
|
||||
dueDateInput.value = "";
|
||||
detailsForm.style.display = "none";
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function setupTaskInteractions() {
|
||||
document.addEventListener("change", async function (e) {
|
||||
if (e.target && e.target.classList && e.target.classList.contains("task-check")) {
|
||||
const taskId = parseInt(e.target.dataset.taskId);
|
||||
const completed = e.target.checked;
|
||||
|
||||
try {
|
||||
const response = await apiRequest(`/api/tasks/${taskId}`, {
|
||||
method: "PATCH",
|
||||
body: JSON.stringify({ completed }),
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
const task = await response.json();
|
||||
const taskItem = e.target.closest(".task-item");
|
||||
if (completed) {
|
||||
taskItem.classList.add("completed");
|
||||
} else {
|
||||
taskItem.classList.remove("completed");
|
||||
}
|
||||
} else {
|
||||
e.target.checked = !completed;
|
||||
alert("Failed to update task");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error updating task:", error);
|
||||
e.target.checked = !completed;
|
||||
alert("Failed to update task. Please try again.");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener("dblclick", function (e) {
|
||||
if (e.target && e.target.classList && e.target.classList.contains("task-title")) {
|
||||
e.target.removeAttribute("readonly");
|
||||
e.target.focus();
|
||||
e.target.select();
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener(
|
||||
"blur",
|
||||
async function (e) {
|
||||
if (
|
||||
e.target &&
|
||||
e.target.classList &&
|
||||
e.target.classList.contains("task-title") &&
|
||||
!e.target.hasAttribute("readonly")
|
||||
) {
|
||||
const taskId = parseInt(e.target.dataset.taskId);
|
||||
const title = e.target.value.trim();
|
||||
|
||||
if (!title) {
|
||||
e.target.value = e.target.defaultValue;
|
||||
e.target.setAttribute("readonly", "");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await apiRequest(`/api/tasks/${taskId}`, {
|
||||
method: "PATCH",
|
||||
body: JSON.stringify({ title }),
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
e.target.setAttribute("readonly", "");
|
||||
} else {
|
||||
alert("Failed to update task");
|
||||
e.target.value = e.target.defaultValue;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error updating task:", error);
|
||||
alert("Failed to update task. Please try again.");
|
||||
e.target.value = e.target.defaultValue;
|
||||
}
|
||||
|
||||
e.target.setAttribute("readonly", "");
|
||||
}
|
||||
},
|
||||
true,
|
||||
);
|
||||
|
||||
document.addEventListener("click", function (e) {
|
||||
if (e.target && e.target.classList && e.target.classList.contains("task-edit")) {
|
||||
const taskId = parseInt(e.target.dataset.taskId);
|
||||
openEditModal(taskId);
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener("click", function (e) {
|
||||
if (e.target && e.target.classList && e.target.classList.contains("task-delete")) {
|
||||
const taskId = parseInt(e.target.dataset.taskId);
|
||||
openDeleteModal(taskId, e.target.closest(".task-item"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function openEditModal(taskId) {
|
||||
try {
|
||||
const response = await apiRequest(`/api/tasks/${taskId}`, {
|
||||
method: "GET",
|
||||
});
|
||||
if (!response.ok) {
|
||||
alert("Failed to load task");
|
||||
return;
|
||||
}
|
||||
|
||||
const task = await response.json();
|
||||
const modal = document.getElementById("edit-modal");
|
||||
const form = document.getElementById("edit-task-form");
|
||||
|
||||
document.getElementById("edit-task-id").value = task.id;
|
||||
document.getElementById("edit-task-title").value = task.title;
|
||||
document.getElementById("edit-task-description").value =
|
||||
task.description || "";
|
||||
document.getElementById("edit-task-due-date").value = task.due_date || "";
|
||||
|
||||
modal.style.display = "flex";
|
||||
|
||||
form.onsubmit = async function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
const title = document.getElementById("edit-task-title").value.trim();
|
||||
if (!title) {
|
||||
alert("Title is required");
|
||||
return;
|
||||
}
|
||||
|
||||
const description =
|
||||
document.getElementById("edit-task-description").value.trim() || null;
|
||||
const dueDate =
|
||||
document.getElementById("edit-task-due-date").value || null;
|
||||
|
||||
try {
|
||||
const updateResponse = await apiRequest(`/api/tasks/${taskId}`, {
|
||||
method: "PATCH",
|
||||
body: JSON.stringify({
|
||||
title,
|
||||
description,
|
||||
due_date: dueDate,
|
||||
}),
|
||||
});
|
||||
|
||||
if (updateResponse.ok) {
|
||||
modal.style.display = "none";
|
||||
location.reload();
|
||||
} else {
|
||||
const error = await updateResponse.json();
|
||||
alert("Error: " + (error.error || "Failed to update task"));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error updating task:", error);
|
||||
alert("Failed to update task. Please try again.");
|
||||
}
|
||||
};
|
||||
|
||||
document.getElementById("cancel-edit").onclick = function () {
|
||||
modal.style.display = "none";
|
||||
};
|
||||
|
||||
document.getElementById("modal-close").onclick = function () {
|
||||
modal.style.display = "none";
|
||||
};
|
||||
|
||||
modal.onclick = function (e) {
|
||||
if (e.target === modal) {
|
||||
modal.style.display = "none";
|
||||
}
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Error opening edit modal:", error);
|
||||
alert("Failed to load task");
|
||||
}
|
||||
}
|
||||
|
||||
function openDeleteModal(taskId, taskElement) {
|
||||
const modal = document.getElementById("delete-modal");
|
||||
const cancelButton = document.getElementById("delete-cancel");
|
||||
const confirmButton = document.getElementById("delete-confirm");
|
||||
let isConfirming = false;
|
||||
|
||||
modal.style.display = "flex";
|
||||
|
||||
const closeModal = function () {
|
||||
modal.style.display = "none";
|
||||
modal.onclick = null;
|
||||
cancelButton.onclick = null;
|
||||
confirmButton.onclick = null;
|
||||
document.removeEventListener("keydown", handleKeydown);
|
||||
isConfirming = false;
|
||||
};
|
||||
|
||||
cancelButton.onclick = closeModal;
|
||||
|
||||
modal.onclick = function (e) {
|
||||
if (e.target === modal) {
|
||||
closeModal();
|
||||
}
|
||||
};
|
||||
|
||||
confirmButton.onclick = async function () {
|
||||
if (isConfirming) return;
|
||||
isConfirming = true;
|
||||
try {
|
||||
const response = await apiRequest(`/api/tasks/${taskId}`, {
|
||||
method: "DELETE",
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
taskElement.remove();
|
||||
closeModal();
|
||||
|
||||
const taskList = document.getElementById("task-list");
|
||||
if (taskList && taskList.children.length === 0) {
|
||||
location.reload();
|
||||
}
|
||||
} else {
|
||||
alert("Failed to delete task");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error deleting task:", error);
|
||||
alert("Failed to delete task. Please try again.");
|
||||
} finally {
|
||||
isConfirming = false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleKeydown = function (e) {
|
||||
if (e.key === "Escape") {
|
||||
closeModal();
|
||||
} else if (e.key === "Enter") {
|
||||
e.preventDefault();
|
||||
confirmButton.click();
|
||||
}
|
||||
};
|
||||
confirmButton.focus();
|
||||
document.addEventListener("keydown", handleKeydown);
|
||||
}
|
||||
|
||||
function setupSearch() {
|
||||
const searchInput = document.getElementById("search-input");
|
||||
const searchClear = document.getElementById("search-clear");
|
||||
const container = document.querySelector(".tasks-container");
|
||||
let searchTimeout = null;
|
||||
|
||||
if (!searchInput) return;
|
||||
|
||||
if (searchInput.value && searchClear) {
|
||||
searchClear.style.display = "block";
|
||||
}
|
||||
|
||||
const performSearch = async (query) => {
|
||||
const url = new URL(window.location);
|
||||
if (query) {
|
||||
url.searchParams.set("search", query);
|
||||
} else {
|
||||
url.searchParams.delete("search");
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(url, {
|
||||
headers: {
|
||||
"X-Requested-With": "XMLHttpRequest",
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error("Failed to fetch search results");
|
||||
}
|
||||
|
||||
const html = await response.text();
|
||||
const parser = new DOMParser();
|
||||
const doc = parser.parseFromString(html, "text/html");
|
||||
const newTaskList = doc.querySelector("#task-list");
|
||||
const newContainer = doc.querySelector(".tasks-container");
|
||||
const taskList = document.getElementById("task-list");
|
||||
|
||||
if (taskList && newTaskList) {
|
||||
taskList.innerHTML = newTaskList.innerHTML;
|
||||
}
|
||||
|
||||
if (container && newContainer) {
|
||||
container.dataset.filter = newContainer.dataset.filter || "all";
|
||||
container.dataset.search = newContainer.dataset.search || "";
|
||||
}
|
||||
|
||||
window.history.replaceState({}, "", url);
|
||||
} catch (error) {
|
||||
console.error("Error performing search:", error);
|
||||
window.location.href = url.toString();
|
||||
}
|
||||
};
|
||||
|
||||
searchInput.addEventListener("input", function () {
|
||||
const query = this.value.trim();
|
||||
|
||||
if (searchClear) {
|
||||
searchClear.style.display = query ? "block" : "none";
|
||||
}
|
||||
|
||||
if (searchTimeout) {
|
||||
clearTimeout(searchTimeout);
|
||||
}
|
||||
|
||||
searchTimeout = setTimeout(() => performSearch(query), 300);
|
||||
});
|
||||
|
||||
searchInput.addEventListener("keydown", function (e) {
|
||||
if (e.key === "Enter") {
|
||||
e.preventDefault();
|
||||
const query = this.value.trim();
|
||||
if (searchTimeout) {
|
||||
clearTimeout(searchTimeout);
|
||||
}
|
||||
performSearch(query);
|
||||
}
|
||||
});
|
||||
|
||||
if (searchClear) {
|
||||
searchClear.addEventListener("click", function () {
|
||||
searchInput.value = "";
|
||||
searchClear.style.display = "none";
|
||||
if (searchTimeout) {
|
||||
clearTimeout(searchTimeout);
|
||||
}
|
||||
performSearch("");
|
||||
searchInput.focus();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function setupDragAndDrop() {
|
||||
const container = document.querySelector(".tasks-container");
|
||||
if (!container) return;
|
||||
|
||||
const taskList = document.getElementById("task-list");
|
||||
if (!taskList) return;
|
||||
if (taskList.dataset.dragSetup === "true") return;
|
||||
|
||||
const isReorderEnabled = () => {
|
||||
const filterType = container.dataset.filter || "all";
|
||||
const hasSearchQuery = (container.dataset.search || "").trim().length > 0;
|
||||
return filterType === "all" && !hasSearchQuery;
|
||||
};
|
||||
|
||||
let draggedElement = null;
|
||||
|
||||
taskList.addEventListener("dragstart", function (e) {
|
||||
if (!isReorderEnabled()) {
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
if (e.target && e.target.classList && e.target.classList.contains("task-item")) {
|
||||
draggedElement = e.target;
|
||||
e.target.classList.add("dragging");
|
||||
e.dataTransfer.effectAllowed = "move";
|
||||
}
|
||||
});
|
||||
|
||||
taskList.addEventListener("dragend", function (e) {
|
||||
if (e.target && e.target.classList && e.target.classList.contains("task-item")) {
|
||||
e.target.classList.remove("dragging");
|
||||
}
|
||||
});
|
||||
|
||||
taskList.addEventListener("dragover", function (e) {
|
||||
if (!isReorderEnabled()) {
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
e.dataTransfer.dropEffect = "move";
|
||||
|
||||
const afterElement = getDragAfterElement(taskList, e.clientY);
|
||||
const dragging = document.querySelector(".dragging");
|
||||
|
||||
if (afterElement == null) {
|
||||
taskList.appendChild(dragging);
|
||||
} else {
|
||||
taskList.insertBefore(dragging, afterElement);
|
||||
}
|
||||
});
|
||||
|
||||
taskList.addEventListener("drop", async function (e) {
|
||||
if (!isReorderEnabled()) {
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
const taskItems = Array.from(taskList.querySelectorAll(".task-item"));
|
||||
const taskIds = taskItems.map((item) => parseInt(item.dataset.taskId));
|
||||
|
||||
try {
|
||||
const response = await apiRequest("/api/tasks/reorder", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ task_ids: taskIds }),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
alert("Failed to reorder tasks");
|
||||
location.reload();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error reordering tasks:", error);
|
||||
alert("Failed to reorder tasks. Please try again.");
|
||||
location.reload();
|
||||
}
|
||||
});
|
||||
|
||||
taskList.dataset.dragSetup = "true";
|
||||
}
|
||||
|
||||
function getDragAfterElement(container, y) {
|
||||
const draggableElements = [
|
||||
...container.querySelectorAll(".task-item:not(.dragging)"),
|
||||
];
|
||||
|
||||
return draggableElements.reduce(
|
||||
(closest, child) => {
|
||||
const box = child.getBoundingClientRect();
|
||||
const offset = y - box.top - box.height / 2;
|
||||
|
||||
if (offset < 0 && offset > closest.offset) {
|
||||
return { offset: offset, element: child };
|
||||
} else {
|
||||
return closest;
|
||||
}
|
||||
},
|
||||
{ offset: Number.NEGATIVE_INFINITY },
|
||||
).element;
|
||||
}
|
||||
|
||||
function setupKeyboardShortcuts() {
|
||||
document.addEventListener("keydown", function (e) {
|
||||
if ((e.ctrlKey || e.metaKey) && e.key === "k") {
|
||||
e.preventDefault();
|
||||
const searchInput = document.getElementById("search-input");
|
||||
if (searchInput) {
|
||||
searchInput.focus();
|
||||
}
|
||||
}
|
||||
|
||||
if ((e.ctrlKey || e.metaKey) && e.key === "n") {
|
||||
e.preventDefault();
|
||||
const taskInput = document.getElementById("task-title-input");
|
||||
if (taskInput) {
|
||||
taskInput.focus();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user