2024-07-30 08:52:03 +00:00
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
2024-09-09 06:11:36 +00:00
|
|
|
const dateInput = document.getElementById('kanblendarDate');
|
|
|
|
const kanbanSection = document.getElementById('kanblendar');
|
|
|
|
|
|
|
|
// Set default date to today
|
|
|
|
const today = new Date().toISOString().split('T')[0];
|
|
|
|
dateInput.value = today;
|
|
|
|
|
|
|
|
// Initialize Kanblendar with today's date
|
|
|
|
window.kanblendar = new Kanblendar({
|
|
|
|
currentDate: today
|
|
|
|
});
|
|
|
|
|
2024-07-30 11:48:35 +00:00
|
|
|
const createTaskBtn = document.getElementById('createTaskBtn');
|
2024-07-30 12:09:38 +00:00
|
|
|
createTaskBtn.addEventListener('click', () => window.kanblendar.openModal());
|
|
|
|
|
2024-09-09 06:11:36 +00:00
|
|
|
const updateDateBtn = document.getElementById('updateDateBtn');
|
|
|
|
updateDateBtn.addEventListener('click', updateKanblendarDate);
|
|
|
|
|
|
|
|
function updateKanblendarDate() {
|
|
|
|
const selectedDate = dateInput.value;
|
|
|
|
kanbanSection.innerHTML = ''; // Clear existing tasks and columns
|
|
|
|
window.kanblendar = new Kanblendar({
|
|
|
|
currentDate: selectedDate
|
|
|
|
});
|
|
|
|
|
|
|
|
const serializedState = localStorage.getItem('kanblendarState');
|
|
|
|
if (serializedState) {
|
|
|
|
window.kanblendar.deserialize(serializedState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-30 12:09:38 +00:00
|
|
|
function saveState() {
|
|
|
|
const serializedState = kanblendar.serialize();
|
|
|
|
localStorage.setItem('kanblendarState', serializedState);
|
|
|
|
console.log('State saved!');
|
|
|
|
}
|
|
|
|
|
|
|
|
document.addEventListener('taskChanged', saveState);
|
|
|
|
|
|
|
|
const serializedState = localStorage.getItem('kanblendarState');
|
|
|
|
if (serializedState) {
|
|
|
|
kanblendar.deserialize(serializedState);
|
|
|
|
console.log('State loaded on page load!');
|
|
|
|
}
|
2024-07-30 13:13:31 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
function clearState() {
|
|
|
|
if (!confirm('Are you sure you want to clear the state?')) {
|
|
|
|
return;
|
|
|
|
}
|
2024-09-09 06:11:36 +00:00
|
|
|
|
2024-07-30 13:13:31 +00:00
|
|
|
localStorage.removeItem('kanblendarState');
|
|
|
|
console.log('State cleared!');
|
|
|
|
document.location.reload();
|
2024-09-09 06:11:36 +00:00
|
|
|
}
|