Spaces:
Running
Running
File size: 35,784 Bytes
34d6e14 18a5a90 34d6e14 18a5a90 34d6e14 |
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 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Student Daily Planner</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap');
body {
font-family: 'Poppins', sans-serif;
background-image: url('');
background-size: cover;
background-attachment: fixed;
background-position: center;
min-height: 100vh;
}
.glass-card {
background: rgba(255, 255, 255, 0.85);
backdrop-filter: blur(10px);
border-radius: 15px;
box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.15);
}
.timeline-item::before {
content: '';
position: absolute;
left: 0;
top: 0;
width: 2px;
height: 100%;
background-color: #4f46e5;
}
.period-card {
transition: all 0.3s ease;
}
.period-card:hover {
transform: translateY(-3px);
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
}
.notification-badge {
position: absolute;
top: -8px;
right: -8px;
width: 20px;
height: 20px;
background-color: #ef4444;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
color: white;
font-size: 10px;
}
@media (max-width: 768px) {
.routine-grid {
grid-template-columns: repeat(1, minmax(0, 1fr));
}
}
</style>
</head>
<body class="py-8 px-4">
<div class="max-w-6xl mx-auto">
<!-- Header -->
<header class="mb-8 text-center">
<h1 class="text-4xl font-bold text-indigo-800 mb-2">Student Daily Planner</h1>
<p class="text-lg text-indigo-600">Organize your tasks efficiently</p>
<div class="mt-4 flex justify-center space-x-4">
<button id="tasksTab" class="px-4 py-2 bg-indigo-600 text-white rounded-lg font-medium">Tasks</button>
</div>
</header>
<!-- Main Content -->
<main>
<!-- Tasks Section -->
<section id="tasksSection" class="glass-card p-6 mb-8">
<div class="flex justify-between items-center mb-6">
<h2 class="text-2xl font-semibold text-indigo-700 flex items-center">
<i class="fas fa-tasks mr-2"></i> Today's Tasks
</h2>
<button id="addTaskBtn" class="px-4 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 flex items-center">
<i class="fas fa-plus mr-2"></i> Add Task
</button>
</div>
<!-- Add Task Modal -->
<div id="taskModal" class="hidden fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50">
<div class="glass-card p-6 rounded-lg w-full max-w-md">
<div class="flex justify-between items-center mb-4">
<h3 class="text-xl font-semibold text-indigo-700">Add New Task</h3>
<button id="closeTaskModal" class="text-gray-500 hover:text-gray-700">
<i class="fas fa-times"></i>
</button>
</div>
<form id="taskForm" class="space-y-4">
<div>
<label for="taskTitle" class="block text-sm font-medium text-gray-700">Task Title</label>
<input type="text" id="taskTitle" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 p-2 border" required>
</div>
<div>
<label for="taskTime" class="block text-sm font-medium text-gray-700">Time</label>
<input type="time" id="taskTime" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 p-2 border" required>
</div>
<div>
<label for="taskTopic" class="block text-sm font-medium text-gray-700">Topic/Details</label>
<input type="text" id="taskTopic" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 p-2 border">
</div>
<div>
<label for="taskReminder" class="block text-sm font-medium text-gray-700">Reminder Before (minutes)</label>
<select id="taskReminder" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 p-2 border">
<option value="5">5 minutes</option>
<option value="10" selected>10 minutes</option>
<option value="15">15 minutes</option>
</select>
</div>
<div class="flex justify-end space-x-3">
<button type="button" id="cancelTask" class="px-4 py-2 bg-gray-200 text-gray-700 rounded-lg hover:bg-gray-300">Cancel</button>
<button type="submit" class="px-4 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700">Save Task</button>
</div>
</form>
</div>
</div>
<!-- Tasks Timeline -->
<div id="tasksContainer" class="space-y-4">
<!-- Sample tasks will be inserted here by JavaScript -->
<div class="text-center py-8 text-gray-500" id="noTasksMessage">
<i class="fas fa-clipboard-list text-4xl mb-2"></i>
<p>No tasks added yet. Click "Add Task" to get started!</p>
</div>
</div>
</section>
<script>
// DOM Elements
const tasksTab = document.getElementById('tasksTab');
const routineTab = document.getElementById('routineTab');
const tasksSection = document.getElementById('tasksSection');
const routineSection = document.getElementById('routineSection');
const addTaskBtn = document.getElementById('addTaskBtn');
const taskModal = document.getElementById('taskModal');
const closeTaskModal = document.getElementById('closeTaskModal');
const cancelTask = document.getElementById('cancelTask');
const taskForm = document.getElementById('taskForm');
const tasksContainer = document.getElementById('tasksContainer');
const noTasksMessage = document.getElementById('noTasksMessage');
const addDayBtn = document.getElementById('addDayBtn');
const dayModal = document.getElementById('dayModal');
const closeDayModal = document.getElementById('closeDayModal');
const cancelDay = document.getElementById('cancelDay');
const dayForm = document.getElementById('dayForm');
const periodsModal = document.getElementById('periodsModal');
const closePeriodsModal = document.getElementById('closePeriodsModal');
const cancelPeriods = document.getElementById('cancelPeriods');
const periodsForm = document.getElementById('periodsForm');
const periodsContainer = document.getElementById('periodsContainer');
const routineContainer = document.getElementById('routineContainer');
const noRoutineMessage = document.getElementById('noRoutineMessage');
const periodsModalTitle = document.getElementById('periodsModalTitle');
// Data
let tasks = JSON.parse(localStorage.getItem('tasks')) || [];
let routine = JSON.parse(localStorage.getItem('routine')) || {};
let currentDay = '';
let notificationTimeouts = {};
// Initialize
document.addEventListener('DOMContentLoaded', () => {
renderTasks();
renderRoutine();
checkForNotifications();
});
// Tab Navigation
tasksTab.addEventListener('click', () => {
tasksSection.classList.remove('hidden');
routineSection.classList.add('hidden');
tasksTab.classList.add('bg-indigo-600', 'text-white');
tasksTab.classList.remove('bg-white', 'text-indigo-600');
routineTab.classList.add('bg-white', 'text-indigo-600');
routineTab.classList.remove('bg-indigo-600', 'text-white');
});
routineTab.addEventListener('click', () => {
routineSection.classList.remove('hidden');
tasksSection.classList.add('hidden');
routineTab.classList.add('bg-indigo-600', 'text-white');
routineTab.classList.remove('bg-white', 'text-indigo-600');
tasksTab.classList.add('bg-white', 'text-indigo-600');
tasksTab.classList.remove('bg-indigo-600', 'text-white');
});
// Task Modal
addTaskBtn.addEventListener('click', () => {
taskModal.classList.remove('hidden');
});
closeTaskModal.addEventListener('click', () => {
taskModal.classList.add('hidden');
});
cancelTask.addEventListener('click', () => {
taskModal.classList.add('hidden');
});
// Task Form Submission
taskForm.addEventListener('submit', (e) => {
e.preventDefault();
const title = document.getElementById('taskTitle').value;
const time = document.getElementById('taskTime').value;
const topic = document.getElementById('taskTopic').value;
const reminder = parseInt(document.getElementById('taskReminder').value);
const newTask = {
id: Date.now(),
title,
time,
topic,
reminder,
completed: false
};
tasks.push(newTask);
saveTasks();
renderTasks();
scheduleNotification(newTask);
taskForm.reset();
taskModal.classList.add('hidden');
});
// Day Modal
addDayBtn.addEventListener('click', () => {
dayModal.classList.remove('hidden');
});
closeDayModal.addEventListener('click', () => {
dayModal.classList.add('hidden');
});
cancelDay.addEventListener('click', () => {
dayModal.classList.add('hidden');
});
// Day Form Submission
dayForm.addEventListener('submit', (e) => {
e.preventDefault();
const day = document.getElementById('daySelect').value;
const periodCount = parseInt(document.getElementById('periodCount').value);
currentDay = day;
periodsModalTitle.textContent = `Add Periods for ${day}`;
// Clear previous inputs
periodsContainer.innerHTML = '';
// Create inputs for each period
for (let i = 1; i <= periodCount; i++) {
const periodDiv = document.createElement('div');
periodDiv.className = 'space-y-2 p-4 bg-gray-50 rounded-lg mb-4';
periodDiv.innerHTML = `
<h4 class="font-medium text-indigo-600">Period ${i}</h4>
<div>
<label for="subject-${i}" class="block text-sm font-medium text-gray-700">Subject</label>
<input type="text" id="subject-${i}" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 p-2 border" required>
</div>
<div class="grid grid-cols-2 gap-4">
<div>
<label for="startTime-${i}" class="block text-sm font-medium text-gray-700">Start Time</label>
<input type="time" id="startTime-${i}" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 p-2 border" required>
</div>
<div>
<label for="endTime-${i}" class="block text-sm font-medium text-gray-700">End Time</label>
<input type="time" id="endTime-${i}" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 p-2 border" required>
</div>
</div>
`;
periodsContainer.appendChild(periodDiv);
}
dayModal.classList.add('hidden');
periodsModal.classList.remove('hidden');
});
// Periods Form Submission
periodsForm.addEventListener('submit', (e) => {
e.preventDefault();
const periodCount = parseInt(document.getElementById('periodCount').value);
const periods = [];
for (let i = 1; i <= periodCount; i++) {
const subject = document.getElementById(`subject-${i}`).value;
const startTime = document.getElementById(`startTime-${i}`).value;
const endTime = document.getElementById(`endTime-${i}`).value;
periods.push({
number: i,
subject,
startTime,
endTime
});
}
routine[currentDay] = periods;
saveRoutine();
renderRoutine();
periodsModal.classList.add('hidden');
dayForm.reset();
});
closePeriodsModal.addEventListener('click', () => {
periodsModal.classList.add('hidden');
});
cancelPeriods.addEventListener('click', () => {
periodsModal.classList.add('hidden');
});
// Render Tasks
function renderTasks() {
if (tasks.length === 0) {
noTasksMessage.classList.remove('hidden');
tasksContainer.innerHTML = '';
return;
}
noTasksMessage.classList.add('hidden');
// Sort tasks by time
tasks.sort((a, b) => {
return a.time.localeCompare(b.time);
});
tasksContainer.innerHTML = '';
tasks.forEach(task => {
const taskElement = document.createElement('div');
taskElement.className = 'relative pl-8 timeline-item';
taskElement.dataset.id = task.id;
const timeParts = task.time.split(':');
const formattedTime = `${parseInt(timeParts[0]) > 12 ? parseInt(timeParts[0]) - 12 : timeParts[0]}:${timeParts[1]} ${parseInt(timeParts[0]) >= 12 ? 'PM' : 'AM'}`;
taskElement.innerHTML = `
<div class="bg-white p-4 rounded-lg shadow-sm border-l-4 border-indigo-500 relative">
<div class="absolute -left-3 top-4 w-6 h-6 rounded-full bg-indigo-500 flex items-center justify-center text-white">
<i class="fas fa-clock text-xs"></i>
</div>
<div class="flex justify-between items-start">
<div>
<h3 class="font-medium ${task.completed ? 'line-through text-gray-400' : 'text-gray-800'}">${task.title}</h3>
<p class="text-sm text-gray-500">${formattedTime}</p>
${task.topic ? `<p class="text-sm text-gray-600 mt-1"><span class="font-medium">Topic:</span> ${task.topic}</p>` : ''}
</div>
<div class="flex space-x-2">
<button class="edit-task p-2 text-indigo-600 hover:text-indigo-800">
<i class="fas fa-edit"></i>
</button>
<button class="delete-task p-2 text-red-600 hover:text-red-800">
<i class="fas fa-trash"></i>
</button>
<button class="complete-task p-2 ${task.completed ? 'text-green-600' : 'text-gray-400 hover:text-green-600'}">
<i class="fas fa-check"></i>
</button>
</div>
</div>
</div>
`;
tasksContainer.appendChild(taskElement);
});
// Add event listeners for task actions
document.querySelectorAll('.edit-task').forEach(btn => {
btn.addEventListener('click', (e) => {
const taskId = parseInt(e.target.closest('.timeline-item').dataset.id);
editTask(taskId);
});
});
document.querySelectorAll('.delete-task').forEach(btn => {
btn.addEventListener('click', (e) => {
const taskId = parseInt(e.target.closest('.timeline-item').dataset.id);
deleteTask(taskId);
});
});
document.querySelectorAll('.complete-task').forEach(btn => {
btn.addEventListener('click', (e) => {
const taskId = parseInt(e.target.closest('.timeline-item').dataset.id);
toggleTaskComplete(taskId);
});
});
}
// Render Routine
function renderRoutine() {
if (Object.keys(routine).length === 0) {
noRoutineMessage.classList.remove('hidden');
routineContainer.innerHTML = '';
return;
}
noRoutineMessage.classList.add('hidden');
routineContainer.innerHTML = '';
Object.entries(routine).forEach(([day, periods]) => {
const dayCard = document.createElement('div');
dayCard.className = 'bg-white p-4 rounded-lg shadow-sm border-t-4 border-indigo-500';
let periodsHTML = '';
periods.forEach(period => {
periodsHTML += `
<div class="period-card bg-gray-50 p-3 rounded-lg mb-3 relative">
<div class="flex justify-between items-center">
<h4 class="font-medium text-indigo-700">Period ${period.number}: ${period.subject}</h4>
<div class="flex space-x-2">
<button class="edit-period p-1 text-indigo-600 hover:text-indigo-800" data-day="${day}" data-period="${period.number}">
<i class="fas fa-edit text-sm"></i>
</button>
<button class="delete-period p-1 text-red-600 hover:text-red-800" data-day="${day}" data-period="${period.number}">
<i class="fas fa-trash text-sm"></i>
</button>
</div>
</div>
<p class="text-sm text-gray-600 mt-1">
<i class="far fa-clock mr-1"></i> ${formatTime(period.startTime)} - ${formatTime(period.endTime)}
</p>
</div>
`;
});
dayCard.innerHTML = `
<div class="flex justify-between items-center mb-4">
<h3 class="text-lg font-semibold text-indigo-800">${day}</h3>
<div class="flex space-x-2">
<button class="add-period p-1 text-indigo-600 hover:text-indigo-800" data-day="${day}">
<i class="fas fa-plus-circle"></i>
</button>
<button class="delete-day p-1 text-red-600 hover:text-red-800" data-day="${day}">
<i class="fas fa-trash"></i>
</button>
</div>
</div>
<div class="periods-container">
${periodsHTML}
</div>
`;
routineContainer.appendChild(dayCard);
});
// Add event listeners for routine actions
document.querySelectorAll('.add-period').forEach(btn => {
btn.addEventListener('click', (e) => {
const day = e.target.closest('.add-period').dataset.day;
addPeriod(day);
});
});
document.querySelectorAll('.edit-period').forEach(btn => {
btn.addEventListener('click', (e) => {
const day = e.target.closest('.edit-period').dataset.day;
const periodNum = parseInt(e.target.closest('.edit-period').dataset.period);
editPeriod(day, periodNum);
});
});
document.querySelectorAll('.delete-period').forEach(btn => {
btn.addEventListener('click', (e) => {
const day = e.target.closest('.delete-period').dataset.day;
const periodNum = parseInt(e.target.closest('.delete-period').dataset.period);
deletePeriod(day, periodNum);
});
});
document.querySelectorAll('.delete-day').forEach(btn => {
btn.addEventListener('click', (e) => {
const day = e.target.closest('.delete-day').dataset.day;
deleteDay(day);
});
});
}
// Task Actions
function editTask(id) {
const task = tasks.find(t => t.id === id);
if (!task) return;
document.getElementById('taskTitle').value = task.title;
document.getElementById('taskTime').value = task.time;
document.getElementById('taskTopic').value = task.topic || '';
document.getElementById('taskReminder').value = task.reminder;
// Remove the task from the array
tasks = tasks.filter(t => t.id !== id);
saveTasks();
// Open the modal to edit
taskModal.classList.remove('hidden');
}
function deleteTask(id) {
if (confirm('Are you sure you want to delete this task?')) {
tasks = tasks.filter(t => t.id !== id);
saveTasks();
renderTasks();
// Clear any scheduled notification
if (notificationTimeouts[id]) {
clearTimeout(notificationTimeouts[id]);
delete notificationTimeouts[id];
}
}
}
function toggleTaskComplete(id) {
const task = tasks.find(t => t.id === id);
if (task) {
task.completed = !task.completed;
saveTasks();
renderTasks();
}
}
// Routine Actions
function addPeriod(day) {
currentDay = day;
periodsModalTitle.textContent = `Add Period to ${day}`;
// Clear previous inputs
periodsContainer.innerHTML = '';
const periodDiv = document.createElement('div');
periodDiv.className = 'space-y-2 p-4 bg-gray-50 rounded-lg mb-4';
const nextPeriodNumber = routine[day] ? routine[day].length + 1 : 1;
periodDiv.innerHTML = `
<h4 class="font-medium text-indigo-600">New Period</h4>
<div>
<label for="subject-new" class="block text-sm font-medium text-gray-700">Subject</label>
<input type="text" id="subject-new" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 p-2 border" required>
</div>
<div class="grid grid-cols-2 gap-4">
<div>
<label for="startTime-new" class="block text-sm font-medium text-gray-700">Start Time</label>
<input type="time" id="startTime-new" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 p-2 border" required>
</div>
<div>
<label for="endTime-new" class="block text-sm font-medium text-gray-700">End Time</label>
<input type="time" id="endTime-new" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 p-2 border" required>
</div>
</div>
`;
periodsContainer.appendChild(periodDiv);
// Change the form submit handler for adding a single period
periodsForm.removeEventListener('submit', handlePeriodsFormSubmit);
periodsForm.addEventListener('submit', handleAddPeriodSubmit);
periodsModal.classList.remove('hidden');
function handleAddPeriodSubmit(e) {
e.preventDefault();
const subject = document.getElementById('subject-new').value;
const startTime = document.getElementById('startTime-new').value;
const endTime = document.getElementById('endTime-new').value;
if (!routine[day]) {
routine[day] = [];
}
routine[day].push({
number: nextPeriodNumber,
subject,
startTime,
endTime
});
saveRoutine();
renderRoutine();
periodsModal.classList.add('hidden');
periodsForm.reset();
// Restore the original form handler
periodsForm.removeEventListener('submit', handleAddPeriodSubmit);
periodsForm.addEventListener('submit', handlePeriodsFormSubmit);
}
}
function editPeriod(day, periodNum) {
const period = routine[day].find(p => p.number === periodNum);
if (!period) return;
currentDay = day;
periodsModalTitle.textContent = `Edit Period ${periodNum} for ${day}`;
// Clear previous inputs
periodsContainer.innerHTML = '';
const periodDiv = document.createElement('div');
periodDiv.className = 'space-y-2 p-4 bg-gray-50 rounded-lg mb-4';
periodDiv.innerHTML = `
<h4 class="font-medium text-indigo-600">Period ${periodNum}</h4>
<div>
<label for="subject-edit" class="block text-sm font-medium text-gray-700">Subject</label>
<input type="text" id="subject-edit" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 p-2 border" value="${period.subject}" required>
</div>
<div class="grid grid-cols-2 gap-4">
<div>
<label for="startTime-edit" class="block text-sm font-medium text-gray-700">Start Time</label>
<input type="time" id="startTime-edit" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 p-2 border" value="${period.startTime}" required>
</div>
<div>
<label for="endTime-edit" class="block text-sm font-medium text-gray-700">End Time</label>
<input type="time" id="endTime-edit" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 p-2 border" value="${period.endTime}" required>
</div>
</div>
`;
periodsContainer.appendChild(periodDiv);
// Change the form submit handler for editing a single period
periodsForm.removeEventListener('submit', handlePeriodsFormSubmit);
periodsForm.addEventListener('submit', handleEditPeriodSubmit);
periodsModal.classList.remove('hidden');
function handleEditPeriodSubmit(e) {
e.preventDefault();
const subject = document.getElementById('subject-edit').value;
const startTime = document.getElementById('startTime-edit').value;
const endTime = document.getElementById('endTime-edit').value;
const periodIndex = routine[day].findIndex(p => p.number === periodNum);
if (periodIndex !== -1) {
routine[day][periodIndex] = {
number: periodNum,
subject,
startTime,
endTime
};
}
saveRoutine();
renderRoutine();
periodsModal.classList.add('hidden');
periodsForm.reset();
// Restore the original form handler
periodsForm.removeEventListener('submit', handleEditPeriodSubmit);
periodsForm.addEventListener('submit', handlePeriodsFormSubmit);
}
}
function deletePeriod(day, periodNum) {
if (confirm('Are you sure you want to delete this period?')) {
routine[day] = routine[day].filter(p => p.number !== periodNum);
// Renumber remaining periods
routine[day].forEach((p, index) => {
p.number = index + 1;
});
saveRoutine();
renderRoutine();
}
}
function deleteDay(day) {
if (confirm(`Are you sure you want to delete all periods for ${day}?`)) {
delete routine[day];
saveRoutine();
renderRoutine();
}
}
function handlePeriodsFormSubmit(e) {
e.preventDefault();
const periodCount = parseInt(document.getElementById('periodCount').value);
const periods = [];
for (let i = 1; i <= periodCount; i++) {
const subject = document.getElementById(`subject-${i}`).value;
const startTime = document.getElementById(`startTime-${i}`).value;
const endTime = document.getElementById(`endTime-${i}`).value;
periods.push({
number: i,
subject,
startTime,
endTime
});
}
routine[currentDay] = periods;
saveRoutine();
renderRoutine();
periodsModal.classList.add('hidden');
dayForm.reset();
}
// Helper Functions
function saveTasks() {
localStorage.setItem('tasks', JSON.stringify(tasks));
}
function saveRoutine() {
localStorage.setItem('routine', JSON.stringify(routine));
}
function formatTime(timeStr) {
if (!timeStr) return '';
const [hours, minutes] = timeStr.split(':');
const hourNum = parseInt(hours);
const ampm = hourNum >= 12 ? 'PM' : 'AM';
const displayHour = hourNum % 12 || 12;
return `${displayHour}:${minutes} ${ampm}`;
}
function scheduleNotification(task) {
if (!('Notification' in window)) {
console.log('This browser does not support desktop notification');
return;
}
// Check if notification permission is already granted
if (Notification.permission !== 'granted') {
Notification.requestPermission().then(permission => {
if (permission === 'granted') {
createNotificationTimeout(task);
}
});
} else {
createNotificationTimeout(task);
}
}
function createNotificationTimeout(task) {
const taskTime = new Date();
const [hours, minutes] = task.time.split(':');
taskTime.setHours(parseInt(hours));
taskTime.setMinutes(parseInt(minutes));
const reminderTime = new Date(taskTime.getTime() - task.reminder * 60000);
const now = new Date();
// Only schedule if the reminder time is in the future
if (reminderTime > now) {
const timeout = reminderTime.getTime() - now.getTime();
notificationTimeouts[task.id] = setTimeout(() => {
showNotification(task);
}, timeout);
}
}
function showNotification(task) {
const notification = new Notification('Task Reminder', {
body: `It's time to ${task.title}${task.topic ? ` (${task.topic})` : ''}`,
icon: 'https://cdn-icons-png.flaticon.com/512/3652/3652191.png'
});
notification.onclick = () => {
window.focus();
};
}
function checkForNotifications() {
tasks.forEach(task => {
if (!task.completed) {
scheduleNotification(task);
}
});
}
</script>
</body>
</html> |