html Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Advanced Forex Checklist Analyzer Pro</title>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap" rel="stylesheet">
<style>
:root {
--bg-color: #1A2634;
--card-bg: #1E1E1E;
--accent-color: #B38184;
--text-color: #F2F2F2;
--inactive-color: #C1C1C1;
--active-color: #D8A7A1;
--danger-color: #ff4757;
--success-color: #2ed573;
--warning-color: #ffa502;
--info-color: #70a1ff;
--font-primary: 'Roboto', sans-serif;
--gradient-start: #1A2634;
--gradient-middle: #323C4F;
--gradient-end: #424D5C;
--container-bg: rgba(28, 33, 42, 0.98);
--item-bg: #1E1E1E;
--button-gradient-start: #B38184;
--button-gradient-end: #D8A7A1;
--text-primary: #F2F2F2;
--text-secondary: #C1C1C1;
--border-radius: 10px;
--shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
--transition-main: all 0.4s ease-in-out;
--transition-fast: all 0.25s ease-in-out;
--max-container-width: 800px;
--slider-height: 40px;
--slider-bg: #f2f2f2;
--slider-fill-start: #4a90e2;
--slider-fill-end: #82c4e8;
--slider-thumb: #fff;
--slider-thumb-border: #4a90e2;
--slider-transition: width 0.6s ease-out;
}
body, html {
margin: 0;
padding: 0;
font-family: var(--font-primary);
background-color: var(--bg-color);
color: var(--text-color);
line-height: 1.6;
}
.app-container {
display: flex;
justify-content: center;
align-items: flex-start;
min-height: 100vh;
padding: 20px;
}
.dashboard {
display: flex;
flex-direction: column;
gap: 20px;
max-width: 1200px;
width: 100%;
}
.card {
background-color: var(--card-bg);
border-radius: var(--border-radius);
padding: 25px;
box-shadow: var(--shadow);
transition: var(--transition-main);
}
.card:hover {
transform: translateY(-5px);
box-shadow: 0 15px 40px rgba(0,0,0,0.4);
}
.score-card {
display: flex;
justify-content: space-between;
align-items: center;
background: linear-gradient(135deg, var(--gradient-start), var(--gradient-end));
}
.score-info {
display: flex;
flex-direction: column;
justify-content: space-between;
height: 100%;
flex-grow: 1;
margin-left: 20px;
}
.title-buttons {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
}
h1 {
font-size: 2.5em;
margin: 0;
background: linear-gradient(45deg, var(--text-primary), var(--button-gradient-end));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
.circular-progress {
position: relative;
width: 200px;
height: 200px;
}
.circular-progress svg {
transform: rotate(-90deg);
}
.circular-progress circle {
fill: none;
stroke-width: 10;
stroke-linecap: round;
}
.progress-bg {
stroke: var(--inactive-color);
}
.progress-bar {
stroke: var(--accent-color);
transition: stroke-dashoffset 1s ease;
}
.progress-text {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 36px;
font-weight: bold;
}
.checklist-section {
margin-bottom: 30px;
}
.checklist-section h2 {
color: var(--button-gradient-start);
margin-bottom: 20px;
display: flex;
justify-content: space-between;
align-items: center;
font-size: 1.8em;
}
.checklist-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 15px 20px;
background-color: rgba(255,255,255,0.05);
border-radius: 12px;
margin-bottom: 15px;
transition: var(--transition-main);
cursor: move;
}
.checklist-item:hover {
background-color: rgba(255,255,255,0.1);
transform: translateX(5px);
}
.toggle {
position: relative;
display: inline-block;
width: 60px;
height: 34px;
}
.toggle input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: var(--inactive-color);
transition: .4s;
border-radius: 34px;
}
.slider:before {
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 4px;
bottom: 4px;
background-color: white;
transition: .4s;
border-radius: 50%;
}
input:checked + .slider {
background-color: var(--button-gradient-end);
}
input:checked + .slider:before {
transform: translateX(26px);
}
.action-buttons {
display: flex;
gap: 15px;
}
.action-button {
background-color: var(--button-gradient-start);
border: none;
color: var(--text-color);
padding: 12px 20px;
font-size: 16px;
cursor: pointer;
border-radius: 8px;
transition: var(--transition-main);
text-transform: uppercase;
letter-spacing: 1px;
font-weight: bold;
}
.action-button:hover {
background-color: var(--button-gradient-end);
transform: translateY(-3px);
box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}
.modal {
display: none;
position: fixed;
z-index: 1000;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgba(0,0,0,0.6);
backdrop-filter: blur(5px);
}
.modal-content {
background-color: var(--card-bg);
margin: 10% auto;
padding: 30px;
border-radius: 15px;
width: 50%;
max-width: 500px;
box-shadow: 0 0 50px rgba(0,0,0,0.5);
animation: modalFadeIn 0.5s;
}
@keyframes modalFadeIn {
from {opacity: 0; transform: translateY(-50px);}
to {opacity: 1; transform: translateY(0);}
}
.close {
color: var(--text-color);
float: right;
font-size: 28px;
font-weight: bold;
transition: var(--transition-main);
}
.close:hover,
.close:focus {
color: var(--danger-color);
text-decoration: none;
cursor: pointer;
transform: scale(1.2);
}
#newCriteriaInput, #newSectionInput, #sectionSelect, .priority-slider {
width: 100%;
padding: 12px;
margin: 15px 0;
border-radius: 8px;
border: 1px solid var(--inactive-color);
background-color: var(--bg-color);
color: var(--text-color);
font-size: 16px;
}
#addNewCriteriaButton, #addNewSectionButton {
background-color: var(--success-color);
color: var(--text-color);
border: none;
padding: 12px 25px;
border-radius: 8px;
cursor: pointer;
transition: var(--transition-main);
font-size: 16px;
text-transform: uppercase;
letter-spacing: 1px;
font-weight: bold;
}
#addNewCriteriaButton:hover, #addNewSectionButton:hover {
background-color: var(--active-color);
transform: translateY(-3px);
box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}
.edit-section-name, .edit-criteria, .delete-section, .delete-criteria {
background: none;
border: none;
color: var(--text-color);
cursor: pointer;
font-size: 20px;
transition: var(--transition-main);
}
.edit-section-name:hover, .edit-criteria:hover {
color: var(--warning-color);
transform: scale(1.2);
}
.delete-section:hover, .delete-criteria:hover {
color: var(--danger-color);
transform: scale(1.2);
}
.section-card {
cursor: move;
}
.section-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
}
.section-buttons, .criteria-buttons {
display: flex;
gap: 15px;
}
.dashboard-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 30px;
padding: 20px;
background: linear-gradient(135deg, var(--gradient-start), var(--gradient-end));
border-radius: 15px;
box-shadow: var(--shadow);
}
.dashboard-title {
font-size: 2.5em;
margin: 0;
background: linear-gradient(45deg, var(--text-primary), var(--button-gradient-end));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
.dashboard-stats {
display: flex;
gap: 20px;
}
.stat-card {
background-color: rgba(255,255,255,0.1);
padding: 15px;
border-radius: 10px;
text-align: center;
}
.stat-value {
font-size: 1.8em;
font-weight: bold;
margin-bottom: 5px;
}
.stat-label {
font-size: 0.9em;
opacity: 0.8;
}
.checklist-grid {
display: flex;
flex-direction: column;
gap: 30px;
}
.section-progress {
height: 5px;
background-color: var(--inactive-color);
border-radius: 5px;
overflow: hidden;
margin-top: 10px;
}
.section-progress-bar {
height: 100%;
background-color: var(--button-gradient-start);
transition: width 0.5s ease;
}
.checklist-item-content {
flex-grow: 1;
margin-right: 15px;
}
.checklist-item-text {
font-size: 1.1em;
margin-bottom: 5px;
}
.checklist-item-description {
font-size: 0.9em;
opacity: 0.7;
}
.priority-indicator {
width: 12px;
height: 12px;
border-radius: 50%;
margin-right: 10px;
}
.priority-high {
background-color: var(--danger-color);
}
.priority-medium {
background-color: var(--warning-color);
}
.priority-low {
background-color: var(--success-color);
}
.tooltip {
position: relative;
display: inline-block;
}
.tooltip .tooltiptext {
visibility: hidden;
width: 120px;
background-color: var(--bg-color);
color: var(--text-color);
text-align: center;
border-radius: 6px;
padding: 5px;
position: absolute;
z-index: 1;
bottom: 125%;
left: 50%;
margin-left: -60px;
opacity: 0;
transition: opacity 0.3s;
}
.tooltip:hover .tooltiptext {
visibility: visible;
opacity: 1;
}
@media (max-width: 768px) {
.dashboard-header {
flex-direction: column;
align-items: flex-start;
}
.dashboard-stats {
margin-top: 20px;
flex-wrap: wrap;
}
.checklist-grid {
grid-template-columns: 1fr;
}
.modal-content {
width: 90%;
}
}
.notes-section {
margin-top: 10px;
display: none;
}
.notes-toggle {
cursor: pointer;
font-size: 0.9em;
color: var(--info-color);
}
.notes-textarea {
width: 100%;
height: 80px;
margin-top: 5px;
border: 1px solid var(--inactive-color);
border-radius: 5px;
padding: 5px;
background-color: var(--bg-color);
color: var(--text-color);
resize: vertical;
}
.file-upload {
margin-top: 5px;
}
.file-upload input[type="file"] {
display: none;
}
.file-upload label {
background-color: var(--button-gradient-start);
color: var(--text-color);
border: none;
padding: 5px 10px;
border-radius: 5px;
cursor: pointer;
transition: var(--transition-main);
}
.file-upload label:hover {
background-color: var(--button-gradient-end);
}
.file-preview {
margin-top: 5px;
max-width: 100%;
max-height: 100px;
display: none;
}
.priority-slider {
width: 100%;
}
</style>
</head>
<body>
<div class="app-container">
<div class="dashboard">
<div class="dashboard-header">
<h1 class="dashboard-title">Advanced Forex Checklist Analyzer Pro</h1>
<div class="dashboard-stats">
<div class="stat-card">
<div class="stat-value" id="totalItemsCount">0</div>
<div class="stat-label">Total Items</div>
</div>
<div class="stat-card">
<div class="stat-value" id="completedItemsCount">0</div>
<div class="stat-label">Completed</div>
</div>
<div class="stat-card">
<div class="stat-value" id="sectionsCount">0</div>
<div class="stat-label">Sections</div>
</div>
</div>
</div>
<div class="card score-card">
<div class="circular-progress">
<svg width="200" height="200">
<circle class="progress-bg" cx="100" cy="100" r="90"></circle>
<circle class="progress-bar" cx="100" cy="100" r="90"></circle>
</svg>
<div class="progress-text">0%</div>
</div>
<div class="score-info">
<div class="title-buttons">
<h2>Overall Progress</h2>
<div class="action-buttons">
<button class="action-button" data-action="add-criteria">Add Criteria</button>
<button class="action-button" data-action="add-section">Add Section</button>
<button class="action-button" data-action="export-data">Export Data</button>
<button class="action-button" data-action="import-data">Import Data</button>
<button class="action-button" data-action="reset-data">Reset Data</button>
</div>
</div>
<p>Overall Score: <span id="scoreDisplay">0</span>%</p>
</div>
</div>
<div class="checklist-grid" id="checklistContainer">
</div>
<input type="text" id="searchInput" placeholder="Search..." aria-label="Search Checklist">
</div>
</div>
<div id="addCriteriaModal" class="modal" role="dialog" aria-modal="true" aria-labelledby="addCriteriaTitle">
<div class="modal-content">
<span class="close" data-close="addCriteriaModal" aria-label="Close">×</span>
<h2 id="addCriteriaTitle">Add New Criteria</h2>
<select id="sectionSelect" aria-label="Select Section">
</select>
<input type="text" id="newCriteriaInput" placeholder="Enter new criteria" aria-label="New Criteria">
<input type="range" id="newCriteriaPriority" class="priority-slider" min="1" max="5" value="1" aria-label="Criteria Priority">
<div id="priorityValue">Priority: 1</div>
<button id="addNewCriteriaButton">Add Criteria</button>
</div>
</div>
<div id="addSectionModal" class="modal" role="dialog" aria-modal="true" aria-labelledby="addSectionTitle">
<div class="modal-content">
<span class="close" data-close="addSectionModal" aria-label="Close">×</span>
<h2 id="addSectionTitle">Add New Section</h2>
<input type="text" id="newSectionInput" placeholder="Enter new section name" aria-label="New Section Name">
<button id="addNewSectionButton">Add Section</button>
</div>
</div>
<div id="confirmationModal" class="modal" role="dialog" aria-modal="true" aria-labelledby="confirmationTitle">
<div class="modal-content">
<span class="close" data-close="confirmationModal" aria-label="Close">×</span>
<h2 id="confirmationTitle">Confirm Action</h2>
<p id="confirmationMessage">Are you sure you want to proceed?</p>
<div class="action-buttons">
<button id="confirmYes">Yes</button>
<button id="confirmNo">No</button>
</div>
</div>
</div>
<div id="editModal" class="modal" role="dialog" aria-modal="true" aria-labelledby="editTitle">
<div class="modal-content">
<span class="close" data-close="editModal" aria-label="Close">×</span>
<h2 id="editTitle">Edit Item</h2>
<input type="text" id="editTextInput" placeholder="Edit text" aria-label="Edit Text">
<input type="range" id="editPriorityInput" class="priority-slider" min="1" max="5" value="1" aria-label="Edit Priority">
<div id="editPriorityValue">Priority: 1</div>
<button id="saveEditButton">Save Changes</button>
</div>
</div>
<div id="loadingIndicator" class="modal" role="alert" aria-live="assertive">
<div class="modal-content" style="text-align:center;">
<p>Loading...</p>
</div>
</div>
<script>
(() => {
const cache = {
checklistContainer: document.getElementById('checklistContainer'),
totalItemsCount: document.getElementById('totalItemsCount'),
completedItemsCount: document.getElementById('completedItemsCount'),
sectionsCount: document.getElementById('sectionsCount'),
scoreDisplay: document.getElementById('scoreDisplay'),
addCriteriaModal: document.getElementById('addCriteriaModal'),
addSectionModal: document.getElementById('addSectionModal'),
confirmationModal: document.getElementById('confirmationModal'),
editModal: document.getElementById('editModal'),
loadingIndicator: document.getElementById('loadingIndicator'),
addNewCriteriaButton: document.getElementById('addNewCriteriaButton'),
addNewSectionButton: document.getElementById('addNewSectionButton'),
confirmYes: document.getElementById('confirmYes'),
confirmNo: document.getElementById('confirmNo'),
saveEditButton: document.getElementById('saveEditButton'),
sectionSelect: document.getElementById('sectionSelect'),
newCriteriaInput: document.getElementById('newCriteriaInput'),
newCriteriaPriority: document.getElementById('newCriteriaPriority'),
newSectionInput: document.getElementById('newSectionInput'),
searchInput: document.getElementById('searchInput'),
priorityValue: document.getElementById('priorityValue'),
editTextInput: document.getElementById('editTextInput'),
editPriorityInput: document.getElementById('editPriorityInput'),
editPriorityValue: document.getElementById('editPriorityValue'),
progressBar: document.querySelector('.progress-bar'),
progressText: document.querySelector('.progress-text'),
actionButtons: document.querySelectorAll('.action-button')
};
let checklistData = {
sections: []
};
let undoStack = [];
let redoStack = [];
let currentEdit = { sectionIndex: null, criteriaIndex: null };
let confirmationCallback = null;
const formatter = new Intl.NumberFormat(undefined, {
style: 'percent',
minimumFractionDigits: 0,
maximumFractionDigits: 2
});
const debounce = (func, delay) => {
let timeout;
return (...args) => {
clearTimeout(timeout);
timeout = setTimeout(() => func.apply(this, args), delay);
};
};
const saveToLocalStorage = () => {
try {
localStorage.setItem('checklistData', JSON.stringify(checklistData));
} catch (error) {
console.error('Failed to save to localStorage:', error);
}
};
const loadFromLocalStorage = () => {
const stored = localStorage.getItem('checklistData');
if (stored) {
try {
checklistData = JSON.parse(stored);
} catch (error) {
console.error('Failed to parse localStorage data:', error);
checklistData = { sections: [] };
}
} else {
checklistData = {
sections: [
{
name: 'Section 1',
criteria: [
{ text: 'Criteria 1', checked: false, priority: 1, notes: '', imageData: null },
{ text: 'Criteria 2', checked: true, priority: 2, notes: '', imageData: null }
]
}
]
};
}
};
const saveState = () => {
undoStack.push(JSON.parse(JSON.stringify(checklistData)));
redoStack = [];
saveToLocalStorage();
};
const undo = () => {
if (undoStack.length > 1) {
redoStack.push(undoStack.pop());
checklistData = JSON.parse(JSON.stringify(undoStack[undoStack.length - 1]));
updateUI();
}
};
const redo = () => {
if (redoStack.length > 0) {
undoStack.push(redoStack.pop());
checklistData = JSON.parse(JSON.stringify(undoStack[undoStack.length - 1]));
updateUI();
}
};
const showModal = (modal) => {
modal.style.display = 'block';
modal.setAttribute('aria-hidden', 'false');
};
const closeModal = (modal) => {
modal.style.display = 'none';
modal.setAttribute('aria-hidden', 'true');
};
const updateUI = () => {
cache.checklistContainer.innerHTML = '';
const fragment = document.createDocumentFragment();
checklistData.sections.forEach((section, sectionIndex) => {
const sectionCard = document.createElement('div');
sectionCard.className = 'card section-card';
sectionCard.setAttribute('draggable', true);
sectionCard.setAttribute('data-section-index', sectionIndex);
const sectionHeader = document.createElement('div');
sectionHeader.className = 'section-header';
sectionHeader.innerHTML = `
<h2>${section.name}</h2>
<div class="section-buttons">
<button class="edit-section-name" data-action="edit-section" data-section-index="${sectionIndex}" aria-label="Edit Section">×</button>
<button class="delete-section" data-action="delete-section" data-section-index="${sectionIndex}" aria-label="Delete Section">×</button>
</div>
`;
sectionCard.appendChild(sectionHeader);
const sectionProgress = document.createElement('div');
sectionProgress.className = 'section-progress';
const sectionProgressBar = document.createElement('div');
sectionProgressBar.className = 'section-progress-bar';
sectionProgress.appendChild(sectionProgressBar);
sectionCard.appendChild(sectionProgress);
section.criteria.forEach((criteria, criteriaIndex) => {
const criteriaItem = document.createElement('div');
criteriaItem.className = 'checklist-item';
criteriaItem.setAttribute('draggable', true);
criteriaItem.setAttribute('data-section-index', sectionIndex);
criteriaItem.setAttribute('data-criteria-index', criteriaIndex);
const priorityIndicator = document.createElement('span');
priorityIndicator.className = `priority-indicator priority-${getPriorityClass(criteria.priority)}`;
criteriaItem.appendChild(priorityIndicator);
criteriaItem.innerHTML += `
<div class="checklist-item-content">
<div class="checklist-item-text">${criteria.text}</div>
</div>
<label class="toggle">
<input type="checkbox" ${criteria.checked ? 'checked' : ''} data-action="toggle-check" data-section-index="${sectionIndex}" data-criteria-index="${criteriaIndex}" aria-label="Toggle Check">
<span class="slider"></span>
</label>
<div class="criteria-buttons">
<button class="edit-criteria" data-action="edit-criteria" data-section-index="${sectionIndex}" data-criteria-index="${criteriaIndex}" aria-label="Edit Criteria">×</button>
<button class="delete-criteria" data-action="delete-criteria" data-section-index="${sectionIndex}" data-criteria-index="${criteriaIndex}" aria-label="Delete Criteria">×</button>
</div>
`;
const notesToggle = document.createElement('div');
notesToggle.className = 'notes-toggle';
notesToggle.textContent = 'Notes';
notesToggle.setAttribute('data-action', 'toggle-notes');
notesToggle.setAttribute('data-section-index', sectionIndex);
notesToggle.setAttribute('data-criteria-index', criteriaIndex);
criteriaItem.appendChild(notesToggle);
const notesSection = document.createElement('div');
notesSection.className = 'notes-section';
notesSection.innerHTML = `
<textarea class="notes-textarea" data-action="save-notes" data-section-index="${sectionIndex}" data-criteria-index="${criteriaIndex}" placeholder="Add notes here...">${criteria.notes}</textarea>
<div class="file-upload">
<input type="file" accept="image/png, image/jpeg" id="fileInput-${sectionIndex}-${criteriaIndex}" data-action="upload-image" data-section-index="${sectionIndex}" data-criteria-index="${criteriaIndex}">
<label for="fileInput-${sectionIndex}-${criteriaIndex}" aria-label="Upload Image">Upload Image</label>
<img src="${criteria.imageData || ''}" alt="Uploaded Image" class="file-preview" ${criteria.imageData ? '' : 'style="display:none;"'}>
</div>
`;
criteriaItem.appendChild(notesSection);
sectionCard.appendChild(criteriaItem);
});
fragment.appendChild(sectionCard);
});
cache.checklistContainer.appendChild(fragment);
updateScore();
updateSectionProgress();
populateSectionSelect();
};
const populateSectionSelect = () => {
cache.sectionSelect.innerHTML = '';
checklistData.sections.forEach((section, index) => {
const option = document.createElement('option');
option.value = index;
option.textContent = section.name;
cache.sectionSelect.appendChild(option);
});
};
const getTotalItems = () => checklistData.sections.reduce((total, section) => total + section.criteria.length, 0);
const getCompletedItems = () => checklistData.sections.reduce((total, section) => total + section.criteria.filter(c => c.checked).length, 0);
const updateScore = () => {
let totalPriority = 0;
let activePriority = 0;
checklistData.sections.forEach(section => {
section.criteria.forEach(criteria => {
totalPriority += criteria.priority;
if (criteria.checked) activePriority += criteria.priority;
});
});
const uncappedPercentage = totalPriority > 0 ? (activePriority / totalPriority) * 100 : 0;
const cappedPercentage = Math.min(uncappedPercentage, 100);
cache.scoreDisplay.textContent = Math.round(uncappedPercentage);
const circumference = 2 * Math.PI * 90;
const offset = circumference - (cappedPercentage / 100) * circumference;
cache.progressBar.style.strokeDasharray = `${circumference} ${circumference}`;
cache.progressBar.style.strokeDashoffset = offset;
cache.progressText.textContent = `${Math.round(cappedPercentage)}%`;
cache.totalItemsCount.textContent = getTotalItems();
cache.completedItemsCount.textContent = getCompletedItems();
cache.sectionsCount.textContent = checklistData.sections.length;
};
const updateSectionProgress = () => {
checklistData.sections.forEach((section, index) => {
const total = section.criteria.reduce((sum, c) => sum + c.priority, 0);
const active = section.criteria.reduce((sum, c) => c.checked ? sum + c.priority : sum, 0);
const progress = total > 0 ? (active / total) * 100 : 0;
const sectionCard = document.querySelector(`.section-card[data-section-index="${index}"]`);
const progressBar = sectionCard.querySelector('.section-progress-bar');
progressBar.style.width = `${progress}%`;
});
};
const getPriorityClass = (priority) => {
if (priority >= 4) return 'high';
if (priority === 3) return 'medium';
return 'low';
};
const toggleNotes = (sectionIndex, criteriaIndex) => {
const notesSection = document.querySelector(`.checklist-item[data-section-index="${sectionIndex}"][data-criteria-index="${criteriaIndex}"] .notes-section`);
notesSection.style.display = notesSection.style.display === 'block' ? 'none' : 'block';
};
const saveNotes = (sectionIndex, criteriaIndex, notes) => {
saveState();
checklistData.sections[sectionIndex].criteria[criteriaIndex].notes = notes;
};
const handleFileUpload = async (event, sectionIndex, criteriaIndex) => {
const file = event.target.files[0];
if (file) {
try {
showModal(cache.loadingIndicator);
const reader = new FileReader();
reader.onload = () => {
saveState();
checklistData.sections[sectionIndex].criteria[criteriaIndex].imageData = reader.result;
updateUI();
closeModal(cache.loadingIndicator);
};
reader.readAsDataURL(file);
} catch (error) {
alert('Error uploading file.');
closeModal(cache.loadingIndicator);
}
}
};
const addNewCriteria = () => {
const sectionIndex = cache.sectionSelect.value;
const newCriteria = cache.newCriteriaInput.value.trim();
const newPriority = parseInt(cache.newCriteriaPriority.value, 10);
if (newCriteria && !isNaN(newPriority) && newPriority > 0) {
saveState();
checklistData.sections[sectionIndex].criteria.push({
text: newCriteria,
checked: false,
priority: newPriority,
notes: '',
imageData: null
});
updateUI();
closeModal(cache.addCriteriaModal);
cache.newCriteriaInput.value = '';
cache.newCriteriaPriority.value = '1';
cache.priorityValue.textContent = 'Priority: 1';
} else {
alert('Please enter valid criteria and priority.');
}
};
const addNewSection = () => {
const newSectionName = cache.newSectionInput.value.trim();
if (newSectionName) {
saveState();
checklistData.sections.push({ name: newSectionName, criteria: [] });
updateUI();
closeModal(cache.addSectionModal);
cache.newSectionInput.value = '';
} else {
alert('Section name cannot be empty.');
}
};
const editSectionName = (sectionIndex) => {
currentEdit = { sectionIndex, criteriaIndex: null };
cache.editTextInput.value = checklistData.sections[sectionIndex].name;
showModal(cache.editModal);
};
const deleteSection = (sectionIndex) => {
confirmationCallback = () => {
saveState();
checklistData.sections.splice(sectionIndex, 1);
updateUI();
};
cache.confirmationMessage.textContent = 'Are you sure you want to delete this section?';
showModal(cache.confirmationModal);
};
const editCriteria = (sectionIndex, criteriaIndex) => {
currentEdit = { sectionIndex, criteriaIndex };
cache.editTextInput.value = checklistData.sections[sectionIndex].criteria[criteriaIndex].text;
cache.editPriorityInput.value = checklistData.sections[sectionIndex].criteria[criteriaIndex].priority;
cache.editPriorityValue.textContent = `Priority: ${checklistData.sections[sectionIndex].criteria[criteriaIndex].priority}`;
showModal(cache.editModal);
};
const deleteCriteria = (sectionIndex, criteriaIndex) => {
confirmationCallback = () => {
saveState();
checklistData.sections[sectionIndex].criteria.splice(criteriaIndex, 1);
updateUI();
};
cache.confirmationMessage.textContent = 'Are you sure you want to delete this criteria?';
showModal(cache.confirmationModal);
};
const saveEdit = () => {
const { sectionIndex, criteriaIndex } = currentEdit;
const newText = cache.editTextInput.value.trim();
const newPriority = parseInt(cache.editPriorityInput.value, 10);
if (newText && !isNaN(newPriority) && newPriority > 0) {
saveState();
if (criteriaIndex !== null) {
checklistData.sections[sectionIndex].criteria[criteriaIndex].text = newText;
checklistData.sections[sectionIndex].criteria[criteriaIndex].priority = newPriority;
} else {
checklistData.sections[sectionIndex].name = newText;
}
updateUI();
closeModal(cache.editModal);
} else {
alert('Please provide valid input.');
}
};
const toggleCheck = (sectionIndex, criteriaIndex) => {
saveState();
checklistData.sections[sectionIndex].criteria[criteriaIndex].checked = !checklistData.sections[sectionIndex].criteria[criteriaIndex].checked;
updateUI();
};
const exportChecklistData = () => {
const dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(checklistData));
const downloadAnchorNode = document.createElement('a');
downloadAnchorNode.setAttribute("href", dataStr);
downloadAnchorNode.setAttribute("download", "checklist_data.json");
document.body.appendChild(downloadAnchorNode);
downloadAnchorNode.click();
downloadAnchorNode.remove();
};
const importChecklistData = async () => {
const input = document.createElement('input');
input.type = 'file';
input.accept = '.json';
input.onchange = async (event) => {
const file = event.target.files[0];
if (file) {
try {
showModal(cache.loadingIndicator);
const text = await file.text();
const importedData = JSON.parse(text);
if (importedData.sections) {
saveState();
checklistData = importedData;
updateUI();
closeModal(cache.loadingIndicator);
} else {
throw new Error('Invalid data format.');
}
} catch (error) {
alert('Error importing data: ' + error.message);
closeModal(cache.loadingIndicator);
}
}
};
input.click();
};
const resetChecklistData = () => {
confirmationCallback = () => {
saveState();
checklistData = { sections: [] };
updateUI();
};
cache.confirmationMessage.textContent = 'Are you sure you want to reset all data?';
showModal(cache.confirmationModal);
};
const handleDragStart = (e) => {
const target = e.target;
const sectionIndex = target.getAttribute('data-section-index');
const criteriaIndex = target.getAttribute('data-criteria-index');
e.dataTransfer.setData('text/plain', JSON.stringify({ sectionIndex, criteriaIndex }));
};
const handleDrop = (e) => {
e.preventDefault();
const data = JSON.parse(e.dataTransfer.getData('text'));
const target = e.target.closest('.checklist-item, .section-card');
if (target) {
const toSectionIndex = target.getAttribute('data-section-index');
const toCriteriaIndex = target.getAttribute('data-criteria-index');
if (data.criteriaIndex === null) { // Moving section
if (data.sectionIndex !== toSectionIndex) {
saveState();
const movedSection = checklistData.sections.splice(data.sectionIndex, 1)[0];
checklistData.sections.splice(toSectionIndex, 0, movedSection);
updateUI();
}
} else { // Moving criteria
if (data.sectionIndex !== toSectionIndex || data.criteriaIndex !== toCriteriaIndex) {
saveState();
const movedCriteria = checklistData.sections[data.sectionIndex].criteria.splice(data.criteriaIndex, 1)[0];
if (toCriteriaIndex !== null) {
checklistData.sections[toSectionIndex].criteria.splice(toCriteriaIndex, 0, movedCriteria);
} else {
checklistData.sections[toSectionIndex].criteria.push(movedCriteria);
}
updateUI();
}
}
}
};
const handleDragOver = (e) => {
e.preventDefault();
};
const searchChecklist = debounce(() => {
const query = cache.searchInput.value.toLowerCase();
document.querySelectorAll('.checklist-item').forEach(item => {
const text = item.querySelector('.checklist-item-text').textContent.toLowerCase();
item.style.display = text.includes(query) ? 'flex' : 'none';
});
}, 300);
const initEventListeners = () => {
cache.actionButtons.forEach(button => {
button.addEventListener('click', (e) => {
const action = e.target.getAttribute('data-action');
switch(action) {
case 'add-criteria':
showModal(cache.addCriteriaModal);
break;
case 'add-section':
showModal(cache.addSectionModal);
break;
case 'export-data':
exportChecklistData();
break;
case 'import-data':
importChecklistData();
break;
case 'reset-data':
resetChecklistData();
break;
}
});
});
cache.addNewCriteriaButton.addEventListener('click', addNewCriteria);
cache.addNewSectionButton.addEventListener('click', addNewSection);
cache.saveEditButton.addEventListener('click', saveEdit);
cache.sectionSelect.addEventListener('change', () => {
const priority = cache.newCriteriaPriority.value;
cache.priorityValue.textContent = `Priority: ${priority}`;
});
cache.newCriteriaPriority.addEventListener('input', () => {
const priority = cache.newCriteriaPriority.value;
cache.priorityValue.textContent = `Priority: ${priority}`;
});
cache.editPriorityInput.addEventListener('input', () => {
const priority = cache.editPriorityInput.value;
cache.editPriorityValue.textContent = `Priority: ${priority}`;
});
document.body.addEventListener('click', (e) => {
if (e.target.matches('[data-close]')) {
const modalId = e.target.getAttribute('data-close');
const modal = document.getElementById(modalId);
closeModal(modal);
}
});
cache.confirmYes.addEventListener('click', () => {
if (confirmationCallback) confirmationCallback();
confirmationCallback = null;
closeModal(cache.confirmationModal);
});
cache.confirmNo.addEventListener('click', () => {
confirmationCallback = null;
closeModal(cache.confirmationModal);
});
cache.checklistContainer.addEventListener('click', (e) => {
const action = e.target.getAttribute('data-action');
const sectionIndex = e.target.getAttribute('data-section-index');
const criteriaIndex = e.target.getAttribute('data-criteria-index');
if (action) {
switch(action) {
case 'edit-section':
editSectionName(parseInt(sectionIndex, 10));
break;
case 'delete-section':
deleteSection(parseInt(sectionIndex, 10));
break;
case 'edit-criteria':
editCriteria(parseInt(sectionIndex, 10), parseInt(criteriaIndex, 10));
break;
case 'delete-criteria':
deleteCriteria(parseInt(sectionIndex, 10), parseInt(criteriaIndex, 10));
break;
case 'toggle-notes':
toggleNotes(parseInt(sectionIndex, 10), parseInt(criteriaIndex, 10));
break;
}
}
});
cache.checklistContainer.addEventListener('change', (e) => {
const action = e.target.getAttribute('data-action');
const sectionIndex = e.target.getAttribute('data-section-index');
const criteriaIndex = e.target.getAttribute('data-criteria-index');
if (action === 'toggle-check') {
toggleCheck(parseInt(sectionIndex, 10), parseInt(criteriaIndex, 10));
}
});
cache.checklistContainer.addEventListener('input', (e) => {
const action = e.target.getAttribute('data-action');
const sectionIndex = e.target.getAttribute('data-section-index');
const criteriaIndex = e.target.getAttribute('data-criteria-index');
if (action === 'save-notes') {
saveNotes(parseInt(sectionIndex, 10), parseInt(criteriaIndex, 10), e.target.value);
}
});
cache.checklistContainer.addEventListener('change', (e) => {
const action = e.target.getAttribute('data-action');
const sectionIndex = e.target.getAttribute('data-section-index');
const criteriaIndex = e.target.getAttribute('data-criteria-index');
if (action === 'upload-image') {
handleFileUpload(e, parseInt(sectionIndex, 10), parseInt(criteriaIndex, 10));
}
});
cache.checklistContainer.addEventListener('dragstart', handleDragStart);
cache.checklistContainer.addEventListener('dragover', handleDragOver);
cache.checklistContainer.addEventListener('drop', handleDrop);
cache.searchInput.addEventListener('input', searchChecklist);
document.addEventListener('keydown', (event) => {
if (event.ctrlKey && event.key === 'z') {
event.preventDefault();
undo();
} else if (event.ctrlKey && event.shiftKey && (event.key === 'Z' || event.key === 'z')) {
event.preventDefault();
redo();
}
});
};
const initialize = () => {
loadFromLocalStorage();
undoStack.push(JSON.parse(JSON.stringify(checklistData)));
updateUI();
initEventListeners();
setInterval(saveToLocalStorage, 5000);
};
initialize();
})();
</script>
</body>
</html>