-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
91 lines (76 loc) · 3.42 KB
/
script.js
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
document.addEventListener('DOMContentLoaded', function() {
const addTaskButton = document.getElementById('add-task');
const taskTable = document.getElementById('task-table').getElementsByTagName('tbody')[0];
const completeSelectedButton = document.getElementById('complete-selected');
const deleteSelectedButton = document.getElementById('delete-selected');
// Função para formatar a data no formato BR
function formatDateBR(date) {
const day = String(date.getDate()).padStart(2, '0');
const month = String(date.getMonth() + 1).padStart(2, '0');
const year = date.getFullYear();
return `${day}/${month}/${year}`;
}
// Adicionar uma nova tarefa
addTaskButton.addEventListener('click', function() {
const taskInput = document.getElementById('new-task');
const endDateInput = document.getElementById('task-end-date');
const taskText = taskInput.value.trim();
const endDate = endDateInput.value;
if (taskText === '' || endDate === '') {
alert('Por favor, preencha todos os campos.');
return;
}
const now = new Date();
const insertionDate = formatDateBR(now);
const insertionTime = `${String(now.getHours()).padStart(2, '0')}:${String(now.getMinutes()).padStart(2, '0')}`;
const newRow = taskTable.insertRow();
// Adiciona célula para checkbox
const selectCell = newRow.insertCell(0);
const checkbox = document.createElement('input');
checkbox.type = 'checkbox';
selectCell.appendChild(checkbox);
// Adiciona célula para a tarefa
const taskCell = newRow.insertCell(1);
taskCell.textContent = taskText;
// Adiciona célula para a data final
const endDateCell = newRow.insertCell(2);
endDateCell.textContent = endDate.split('-').reverse().join('/'); // Formata a data final no formato BR
// Adiciona célula para a data de inserção
const insertionDateCell = newRow.insertCell(3);
insertionDateCell.textContent = insertionDate;
// Adiciona célula para a hora
const timeCell = newRow.insertCell(4);
timeCell.textContent = insertionTime;
// Limpa os campos após adicionar
taskInput.value = '';
endDateInput.value = '';
});
completeSelectedButton.addEventListener('click', function() {
const rows = document.querySelectorAll('#task-table tbody tr');
rows.forEach(row => {
if (row.querySelector('input[type="checkbox"]').checked) {
row.classList.add('completed');
}
});
});
// Excluir tarefas selecionadas
deleteSelectedButton.addEventListener('click', function() {
const rows = document.querySelectorAll('#task-table tbody tr');
rows.forEach(row => {
if (row.querySelector('input[type="checkbox"]').checked) {
row.remove();
}
});
});
// Adiciona funcionalidade aos botões "Concluir" e "Excluir" nas linhas
taskTable.addEventListener('click', function(event) {
if (event.target.classList.contains('completed-btn')) {
const row = event.target.closest('tr');
row.classList.add('completed');
}
if (event.target.classList.contains('delete-btn')) {
const row = event.target.closest('tr');
row.remove();
}
});
});