-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
103 lines (92 loc) · 4 KB
/
script.js
File metadata and controls
103 lines (92 loc) · 4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
const modal = document.getElementById("noteModal");
const openBtn = document.getElementById("openModalBtn");
const closeBtn = document.querySelector(".close-btn");
const noteForm = document.getElementById("noteForm");
const searchInput = document.getElementById("searchNote");
const sortOrder = document.getElementById("sortOrder");
let notes = JSON.parse(localStorage.getItem("prompt_vfinal_system")) || [];
openBtn.onclick = () => {
noteForm.reset();
document.getElementById("noteId").value = "";
document.getElementById("modalTitle").innerText = "Nova Nota";
modal.style.display = "flex";
};
closeBtn.onclick = () => modal.style.display = "none";
window.onclick = (e) => { if (e.target === modal) modal.style.display = "none"; };
function render() {
document.querySelectorAll('.notes-container, .day-notes').forEach(c => c.innerHTML = '');
let filtered = [...notes];
filtered.sort((a, b) => sortOrder.value === 'newest' ? b.id - a.id : a.id - b.id);
const search = searchInput.value.toLowerCase();
filtered.forEach(note => {
if (note.title.toLowerCase().includes(search) || note.text.toLowerCase().includes(search)) {
// Kanban
const container = document.querySelector(`[data-column="${note.priority}"]`);
if (container) container.appendChild(createNoteEl(note));
// Cronograma
const dateObj = new Date(note.date + 'T00:00:00');
const dayTarget = document.querySelector(`.day-col[data-day="${dateObj.getDay()}"] .day-notes`);
if (dayTarget) {
const link = document.createElement('div');
link.className = 'cron-note-link';
link.innerText = note.title;
link.onclick = (e) => { e.stopPropagation(); openNote(note.id); };
dayTarget.appendChild(link);
}
}
});
}
function createNoteEl(note) {
const div = document.createElement('div');
div.className = 'note';
div.innerHTML = `
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:8px">
<small style="color:var(--action-blue); font-weight:700">${note.date.split('-').reverse().slice(0,2).join('/')}</small>
<button style="color:var(--accent-coral); background:none; border:none; cursor:pointer; font-size:1.2rem" onclick="deleteNote(${note.id})">×</button>
</div>
<h4 style="cursor:pointer; margin:0" onclick="openNote(${note.id})">${note.title}</h4>
`;
return div;
}
function openNote(id) {
const note = notes.find(n => n.id === id);
if (note) {
document.getElementById("noteId").value = note.id;
document.getElementById("noteTitle").value = note.title;
document.getElementById("noteText").value = note.text;
document.getElementById("noteDate").value = note.date;
document.getElementById("notePriority").value = note.priority;
document.getElementById("modalTitle").innerText = "Editar Registro";
modal.style.display = "flex";
}
}
window.deleteNote = (id) => {
if(confirm("Deseja apagar?")) {
notes = notes.filter(n => n.id !== id);
localStorage.setItem("prompt_vfinal_system", JSON.stringify(notes));
render();
}
};
noteForm.onsubmit = (e) => {
e.preventDefault();
const id = document.getElementById("noteId").value;
const noteData = {
id: id ? parseInt(id) : Date.now(),
title: document.getElementById("noteTitle").value,
text: document.getElementById("noteText").value,
date: document.getElementById("noteDate").value,
priority: document.getElementById("notePriority").value
};
if (id) {
const index = notes.findIndex(n => n.id === parseInt(id));
notes[index] = noteData;
} else {
notes.push(noteData);
}
localStorage.setItem("prompt_vfinal_system", JSON.stringify(notes));
modal.style.display = "none";
render();
};
searchInput.oninput = render;
sortOrder.onchange = render;
render();