-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
189 lines (161 loc) · 6.62 KB
/
script.js
File metadata and controls
189 lines (161 loc) · 6.62 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
document.addEventListener('DOMContentLoaded', () => {
const taskForm = document.getElementById('task-form');
const taskDateInput = document.getElementById('task-date');
const taskTitleInput = document.getElementById('task-title');
const taskCategoryInput = document.getElementById('task-category');
const taskColorInput = document.getElementById('task-color');
const taskDeadlineInput = document.getElementById('task-deadline');
const taskList = document.getElementById('task-list');
const calendarDays = document.getElementById('days');
const monthYearElement = document.getElementById('month-year');
const prevMonthButton = document.getElementById('prev-month');
const nextMonthButton = document.getElementById('next-month');
const timetableForm = document.getElementById('timetable-form');
const timetableDayInput = document.getElementById('timetable-day');
const entryTimeInput = document.getElementById('entry-time');
const entryActivityInput = document.getElementById('entry-activity');
const entryColorInput = document.getElementById('entry-color');
const timetableTable = document.getElementById('traditional-timetable');
let tasks = [];
let timetableEntries = [];
let currentDate = new Date(); // Initialize to the current date
// Function to render tasks
const renderTasks = () => {
taskList.innerHTML = '';
tasks.forEach((task, index) => {
const li = document.createElement('li');
li.innerHTML = `
<strong>${task.title}</strong>
<span>${task.category}</span>
<span>Deadline: ${task.deadline}</span>
<button onclick="removeTask(${index})">Delete</button>
`;
taskList.appendChild(li);
});
};
// Function to render calendar with task colors
const renderCalendar = () => {
const month = currentDate.getMonth();
const year = currentDate.getFullYear();
const daysInMonth = new Date(year, month + 1, 0).getDate();
calendarDays.innerHTML = ''; // Clear previous days
const firstDay = new Date(year, month, 1).getDay();
// Render empty divs for the first week days before the 1st of the month
for (let i = 0; i < firstDay; i++) {
const emptyDiv = document.createElement('div');
calendarDays.appendChild(emptyDiv);
}
// Render the days with task colors
for (let day = 1; day <= daysInMonth; day++) {
const dayDiv = document.createElement('div');
dayDiv.textContent = day;
// Check if there are any tasks for this date
const taskForTheDay = tasks.filter(task => {
const taskDate = new Date(task.date);
return taskDate.getDate() === day && taskDate.getMonth() === month && taskDate.getFullYear() === year;
});
if (taskForTheDay.length > 0) {
dayDiv.style.backgroundColor = taskForTheDay[0].color;
}
calendarDays.appendChild(dayDiv);
}
// Update the month and year label
const months = [
'January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December'
];
const monthName = months[month];
monthYearElement.textContent = `${monthName} ${year}`;
};
// Handle task form submission
taskForm.addEventListener('submit', (e) => {
e.preventDefault();
const task = {
date: taskDateInput.value,
title: taskTitleInput.value,
category: taskCategoryInput.value,
color: taskColorInput.value,
deadline: taskDeadlineInput.value
};
tasks.push(task);
renderTasks();
renderCalendar(); // Re-render the calendar to show the new task
// Reset the form
taskForm.reset();
});
// Remove task by index
window.removeTask = (index) => {
tasks.splice(index, 1);
renderTasks();
renderCalendar(); // Re-render the calendar after removing a task
};
// Handle previous month button click
prevMonthButton.addEventListener('click', () => {
currentDate.setMonth(currentDate.getMonth() - 1);
renderCalendar();
});
// Handle next month button click
nextMonthButton.addEventListener('click', () => {
currentDate.setMonth(currentDate.getMonth() + 1);
renderCalendar();
});
// Render timetable entries
const renderTimetable = () => {
timetableTable.querySelectorAll('td').forEach(cell => cell.innerHTML = ''); // Clear existing timetable
timetableEntries.forEach(entry => {
const dayCell = document.getElementById(entry.day.toLowerCase()); // Get the correct day cell by id
if (dayCell) {
dayCell.innerHTML += `
<div style="background-color: ${entry.color}; padding: 5px; margin: 5px; border-radius: 5px;">
<strong>${entry.time}</strong> - ${entry.activity}
</div>
`;
}
});
};
// Handle timetable form submission
timetableForm.addEventListener('submit', (e) => {
e.preventDefault();
const timetableEntry = {
day: timetableDayInput.value,
time: entryTimeInput.value,
activity: entryActivityInput.value,
color: entryColorInput.value
};
timetableEntries.push(timetableEntry);
renderTimetable(); // Re-render timetable after adding an entry
timetableForm.reset();
});
// Initialize the calendar with current month
renderCalendar();
});
// Handle sign up form submission
document.getElementById('signup-form').addEventListener('submit', function(event) {
event.preventDefault();
// Get form values
const username = document.getElementById('username').value;
const password = document.getElementById('password').value;
// Store credentials in localStorage
localStorage.setItem('username', username);
localStorage.setItem('password', password);
alert('Sign up successful! You can now log in.');
// Redirect to login page
window.location.href = 'login.html';
});
// Handle login form submission
document.getElementById('login-form').addEventListener('submit', function(event) {
event.preventDefault();
// Get form values
const username = document.getElementById('username').value;
const password = document.getElementById('password').value;
// Retrieve stored credentials from localStorage
const storedUsername = localStorage.getItem('username');
const storedPassword = localStorage.getItem('password');
// Validate credentials
if (username === storedUsername && password === storedPassword) {
alert('Login successful!');
window.location.href = 'pages/TaskNova.html'; // Redirect to Tasknova main page
} else {
alert('Incorrect username or password!');
}
});