Kumi
1ddae1b7d3
- Added a date input and an "Update Date" button in the header to allow users to select and update the current date for the Kanban board. - Modified CSS to support new header layout with flexbox for better alignment and distribution. - Enhanced JavaScript to initialize the Kanban board with the selected date and to allow dynamic updates based on the chosen date. - Improved user experience with button hover state and default date setting to today's date. - Ensured the Kanban state is retained across date changes, enhancing data persistence and usability.
56 lines
1.8 KiB
JavaScript
56 lines
1.8 KiB
JavaScript
document.addEventListener('DOMContentLoaded', () => {
|
|
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
|
|
});
|
|
|
|
const createTaskBtn = document.getElementById('createTaskBtn');
|
|
createTaskBtn.addEventListener('click', () => window.kanblendar.openModal());
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
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!');
|
|
}
|
|
});
|
|
|
|
function clearState() {
|
|
if (!confirm('Are you sure you want to clear the state?')) {
|
|
return;
|
|
}
|
|
|
|
localStorage.removeItem('kanblendarState');
|
|
console.log('State cleared!');
|
|
document.location.reload();
|
|
}
|