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: 20px;
padding: 25px;
box-shadow: 0 10px 30px rgba(0,0,0,0.3);
transition: var(--transition-fast);
}
.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-fast);
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;
flex-wrap: wrap;
}
.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-fast);
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: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
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: 90%;
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-fast);
cursor: pointer;
}
.close:hover,
.close:focus {
color: var(--danger-color);
text-decoration: none;
transform: scale(1.2);
}
input[type="text"], input[type="number"], select, .priority-input {
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;
}
button[type="submit"] {
background-color: var(--success-color);
color: var(--text-color);
border: none;
padding: 12px 25px;
border-radius: 8px;
cursor: pointer;
transition: var(--transition-fast);
font-size: 16px;
text-transform: uppercase;
letter-spacing: 1px;
font-weight: bold;
}
button[type="submit"]: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-fast);
}
.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: 0 10px 30px rgba(0,0,0,0.2);
flex-wrap: wrap;
}
.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;
flex-wrap: wrap;
}
.stat-card {
background-color: rgba(255,255,255,0.1);
padding: 15px;
border-radius: 10px;
text-align: center;
flex: 1;
}
.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-number {
margin-right: 10px;
font-weight: bold;
}
.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-fast);
}
.file-upload label:hover {
background-color: var(--button-gradient-end);
}
.file-preview {
margin-top: 5px;
max-width: 100%;
max-height: 100px;
display: block;
}
@media (max-width: 768px) {
.dashboard-header {
flex-direction: column;
align-items: flex-start;
}
.dashboard-stats {
margin-top: 20px;
}
.modal-content {
width: 90%;
}
}
</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" id="addCriteriaButton">Add Criteria</button>
<button class="action-button" id="addSectionButton">Add Section</button>
<button class="action-button" id="exportDataButton">Export Data</button>
<button class="action-button" id="importDataButton">Import Data</button>
<button class="action-button" id="resetDataButton">Reset Data</button>
</div>
</div>
<p>Overall Score: <span id="scoreDisplay">0</span>%</p>
</div>
</div>
<div class="checklist-grid" id="checklistContainer">
</div>
</div>
</div>
<div id="addCriteriaModal" class="modal" role="dialog" aria-modal="true" aria-labelledby="addCriteriaTitle">
<div class="modal-content">
<span class="close" id="closeAddCriteriaModal" tabindex="0" role="button" aria-label="Close Modal">×</span>
<h2 id="addCriteriaTitle">Add New Criteria</h2>
<form id="addCriteriaForm" novalidate>
<select id="sectionSelect" required aria-label="Select Section"></select>
<input type="text" id="newCriteriaInput" placeholder="Enter new criteria" required aria-label="Criteria Text">
<input type="range" id="newCriteriaPriority" min="1" max="10" value="1" aria-label="Priority">
<output for="newCriteriaPriority" id="priorityValue">1</output>
<button type="submit" id="addNewCriteriaButton">Add Criteria</button>
</form>
</div>
</div>
<div id="addSectionModal" class="modal" role="dialog" aria-modal="true" aria-labelledby="addSectionTitle">
<div class="modal-content">
<span class="close" id="closeAddSectionModal" tabindex="0" role="button" aria-label="Close Modal">×</span>
<h2 id="addSectionTitle">Add New Section</h2>
<form id="addSectionForm" novalidate>
<input type="text" id="newSectionInput" placeholder="Enter new section name" required aria-label="Section Name">
<button type="submit" id="addNewSectionButton">Add Section</button>
</form>
</div>
</div>
<div id="modalOverlay" class="modal" role="dialog" aria-modal="true" style="display:none;">
<div class="modal-content" id="customModalContent">
<span class="close" id="closeCustomModal" tabindex="0" role="button" aria-label="Close Modal">×</span>
<div id="customModalBody"></div>
<div id="customModalActions"></div>
</div>
</div>
<input type="text" id="searchInput" placeholder="Search..." aria-label="Search Criteria">
<script>
(function() {
'use strict';
let checklistData = { sections: [] };
let undoStack = [];
let redoStack = [];
let debounceTimeout;
document.addEventListener('DOMContentLoaded', init);
function init() {
const addCriteriaButton = document.getElementById('addCriteriaButton');
const addSectionButton = document.getElementById('addSectionButton');
const exportDataButton = document.getElementById('exportDataButton');
const importDataButton = document.getElementById('importDataButton');
const resetDataButton = document.getElementById('resetDataButton');
const closeAddCriteriaModalButton = document.getElementById('closeAddCriteriaModal');
const closeAddSectionModalButton = document.getElementById('closeAddSectionModal');
const addNewCriteriaForm = document.getElementById('addCriteriaForm');
const addNewSectionForm = document.getElementById('addSectionForm');
const sectionSelect = document.getElementById('sectionSelect');
const newCriteriaPriority = document.getElementById('newCriteriaPriority');
const priorityValue = document.getElementById('priorityValue');
const searchInput = document.getElementById('searchInput');
loadState();
updateUI();
addCriteriaButton.addEventListener('click', () => showModal('addCriteriaModal'));
addSectionButton.addEventListener('click', () => showModal('addSectionModal'));
exportDataButton.addEventListener('click', exportChecklistData);
importDataButton.addEventListener('click', importChecklistData);
resetDataButton.addEventListener('click', resetChecklistData);
closeAddCriteriaModalButton.addEventListener('click', () => closeModal('addCriteriaModal'));
closeAddSectionModalButton.addEventListener('click', () => closeModal('addSectionModal'));
addNewCriteriaForm.addEventListener('submit', addNewCriteria);
addNewSectionForm.addEventListener('submit', addNewSection);
newCriteriaPriority.addEventListener('input', () => priorityValue.textContent = newCriteriaPriority.value);
document.addEventListener('keydown', function(event) {
if (event.ctrlKey && event.key === 'z') {
undo();
} else if ((event.ctrlKey && event.shiftKey && event.key === 'Z') || (event.ctrlKey && event.key === 'y')) {
redo();
}
});
document.getElementById('checklistContainer').addEventListener('click', handleChecklistClick);
document.getElementById('checklistContainer').addEventListener('change', handleChecklistChange);
document.getElementById('checklistContainer').addEventListener('input', handleChecklistInput);
document.getElementById('checklistContainer').addEventListener('blur', handleChecklistBlur, true);
document.getElementById('checklistContainer').addEventListener('dragstart', dragStart);
document.getElementById('checklistContainer').addEventListener('dragover', dragOver);
document.getElementById('checklistContainer').addEventListener('drop', drop);
searchInput.addEventListener('input', () => {
clearTimeout(debounceTimeout);
debounceTimeout = setTimeout(() => {
updateUI(searchInput.value.trim().toLowerCase());
}, 300);
});
}
function updateUI(searchTerm = '') {
const container = document.getElementById('checklistContainer');
container.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.dataset.sectionIndex = sectionIndex;
const sectionHeader = document.createElement('div');
sectionHeader.className = 'section-header';
const sectionTitle = document.createElement('h2');
sectionTitle.textContent = section.name;
const sectionButtons = document.createElement('div');
sectionButtons.className = 'section-buttons';
const editSectionButton = document.createElement('button');
editSectionButton.className = 'edit-section-name';
editSectionButton.innerHTML = '✎';
editSectionButton.dataset.action = 'edit-section';
editSectionButton.dataset.sectionIndex = sectionIndex;
const deleteSectionButton = document.createElement('button');
deleteSectionButton.className = 'delete-section';
deleteSectionButton.innerHTML = '🗑';
deleteSectionButton.dataset.action = 'delete-section';
deleteSectionButton.dataset.sectionIndex = sectionIndex;
sectionButtons.append(editSectionButton, deleteSectionButton);
sectionHeader.append(sectionTitle, sectionButtons);
sectionCard.append(sectionHeader);
const sectionProgress = document.createElement('div');
sectionProgress.className = 'section-progress';
const sectionProgressBar = document.createElement('div');
sectionProgressBar.className = 'section-progress-bar';
sectionProgress.append(sectionProgressBar);
sectionCard.append(sectionProgress);
section.criteria.forEach((criteria, criteriaIndex) => {
if (searchTerm && !criteria.text.toLowerCase().includes(searchTerm)) return;
const criteriaItem = document.createElement('div');
criteriaItem.className = 'checklist-item';
criteriaItem.setAttribute('draggable', true);
criteriaItem.dataset.sectionIndex = sectionIndex;
criteriaItem.dataset.criteriaIndex = criteriaIndex;
const priorityNumber = document.createElement('span');
priorityNumber.className = 'priority-number';
priorityNumber.textContent = criteria.priority;
priorityNumber.contentEditable = true;
priorityNumber.dataset.sectionIndex = sectionIndex;
priorityNumber.dataset.criteriaIndex = criteriaIndex;
const criteriaContent = document.createElement('div');
criteriaContent.className = 'checklist-item-content';
const criteriaText = document.createElement('div');
criteriaText.className = 'checklist-item-text';
criteriaText.textContent = criteria.text;
criteriaContent.append(criteriaText);
const toggle = document.createElement('label');
toggle.className = 'toggle';
const toggleInput = document.createElement('input');
toggleInput.type = 'checkbox';
toggleInput.checked = criteria.checked;
toggleInput.dataset.sectionIndex = sectionIndex;
toggleInput.dataset.criteriaIndex = criteriaIndex;
const slider = document.createElement('span');
slider.className = 'slider';
toggle.append(toggleInput, slider);
const criteriaButtons = document.createElement('div');
criteriaButtons.className = 'criteria-buttons';
const editCriteriaButton = document.createElement('button');
editCriteriaButton.className = 'edit-criteria';
editCriteriaButton.innerHTML = '✎';
editCriteriaButton.dataset.action = 'edit-criteria';
editCriteriaButton.dataset.sectionIndex = sectionIndex;
editCriteriaButton.dataset.criteriaIndex = criteriaIndex;
const deleteCriteriaButton = document.createElement('button');
deleteCriteriaButton.className = 'delete-criteria';
deleteCriteriaButton.innerHTML = '🗑';
deleteCriteriaButton.dataset.action = 'delete-criteria';
deleteCriteriaButton.dataset.sectionIndex = sectionIndex;
deleteCriteriaButton.dataset.criteriaIndex = criteriaIndex;
criteriaButtons.append(editCriteriaButton, deleteCriteriaButton);
const notesToggle = document.createElement('div');
notesToggle.className = 'notes-toggle';
notesToggle.textContent = 'Notes';
notesToggle.dataset.action = 'toggle-notes';
notesToggle.dataset.sectionIndex = sectionIndex;
notesToggle.dataset.criteriaIndex = criteriaIndex;
const notesSection = document.createElement('div');
notesSection.className = 'notes-section';
const notesTextarea = document.createElement('textarea');
notesTextarea.className = 'notes-textarea';
notesTextarea.placeholder = 'Add notes here...';
notesTextarea.value = criteria.notes || '';
notesTextarea.dataset.sectionIndex = sectionIndex;
notesTextarea.dataset.criteriaIndex = criteriaIndex;
const fileUpload = document.createElement('div');
fileUpload.className = 'file-upload';
const fileInput = document.createElement('input');
fileInput.type = 'file';
fileInput.accept = 'image/png, image/jpeg';
fileInput.id = `fileInput-${sectionIndex}-${criteriaIndex}`;
fileInput.dataset.sectionIndex = sectionIndex;
fileInput.dataset.criteriaIndex = criteriaIndex;
const fileLabel = document.createElement('label');
fileLabel.htmlFor = `fileInput-${sectionIndex}-${criteriaIndex}`;
fileLabel.textContent = 'Upload Image';
fileUpload.append(fileInput, fileLabel);
const filePreview = document.createElement('img');
filePreview.className = 'file-preview';
filePreview.loading = 'lazy';
if (criteria.imageData) {
filePreview.src = criteria.imageData;
}
notesSection.append(notesTextarea, fileUpload, filePreview);
criteriaItem.append(priorityNumber, criteriaContent, toggle, criteriaButtons, notesToggle, notesSection);
sectionCard.append(criteriaItem);
});
fragment.append(sectionCard);
});
container.append(fragment);
updateScore();
updateSectionProgress();
populateSectionSelect();
document.getElementById('totalItemsCount').textContent = getTotalItems();
document.getElementById('completedItemsCount').textContent = getCompletedItems();
document.getElementById('sectionsCount').textContent = checklistData.sections.length;
}
function 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 ? Math.round((activePriority / totalPriority) * 100) : 0;
const cappedPercentage = Math.min(uncappedPercentage, 100);
document.getElementById('scoreDisplay').textContent = uncappedPercentage;
const progressBar = document.querySelector('.progress-bar');
const circumference = 2 * Math.PI * 90;
const offset = circumference - (cappedPercentage / 100) * circumference;
progressBar.style.strokeDasharray = `${circumference} ${circumference}`;
progressBar.style.strokeDashoffset = offset;
document.querySelector('.progress-text').textContent = `${cappedPercentage}%`;
}
function updateSectionProgress() {
checklistData.sections.forEach((section, index) => {
const totalPriority = section.criteria.reduce((sum, criteria) => sum + criteria.priority, 0);
const activePriority = section.criteria.reduce((sum, criteria) => criteria.checked ? sum + criteria.priority : sum, 0);
const progress = totalPriority > 0 ? (activePriority / totalPriority) * 100 : 0;
const sectionCard = document.querySelector(`.section-card[data-section-index="${index}"]`);
if (sectionCard) {
const progressBar = sectionCard.querySelector('.section-progress-bar');
progressBar.style.width = `${progress}%`;
}
});
}
function handleChecklistClick(e) {
const action = e.target.dataset.action;
const sectionIndex = e.target.dataset.sectionIndex;
const criteriaIndex = e.target.dataset.criteriaIndex;
if (action === 'edit-section') {
editSectionName(sectionIndex);
} else if (action === 'delete-section') {
deleteSection(sectionIndex);
} else if (action === 'edit-criteria') {
editCriteria(sectionIndex, criteriaIndex);
} else if (action === 'delete-criteria') {
deleteCriteria(sectionIndex, criteriaIndex);
} else if (action === 'toggle-notes') {
toggleNotes(sectionIndex, criteriaIndex);
}
}
function handleChecklistChange(e) {
const sectionIndex = e.target.dataset.sectionIndex;
const criteriaIndex = e.target.dataset.criteriaIndex;
if (e.target.type === 'checkbox') {
updateCriteriaStatus(sectionIndex, criteriaIndex);
} else if (e.target.type === 'file') {
handleFileUpload(e, sectionIndex, criteriaIndex);
}
}
function handleChecklistInput(e) {
if (e.target.classList.contains('notes-textarea')) {
const sectionIndex = e.target.dataset.sectionIndex;
const criteriaIndex = e.target.dataset.criteriaIndex;
saveNotes(sectionIndex, criteriaIndex, e.target.value);
}
}
function handleChecklistBlur(e) {
if (e.target.classList.contains('priority-number')) {
const sectionIndex = e.target.dataset.sectionIndex;
const criteriaIndex = e.target.dataset.criteriaIndex;
const newPriority = parseInt(e.target.textContent, 10);
if (!isNaN(newPriority) && newPriority > 0) {
saveState();
checklistData.sections[sectionIndex].criteria[criteriaIndex].priority = newPriority;
updateScore();
updateSectionProgress();
} else {
e.target.textContent = checklistData.sections[sectionIndex].criteria[criteriaIndex].priority;
}
}
}
function updateCriteriaStatus(sectionIndex, criteriaIndex) {
saveState();
checklistData.sections[sectionIndex].criteria[criteriaIndex].checked = !checklistData.sections[sectionIndex].criteria[criteriaIndex].checked;
debounceUpdate();
}
function debounceUpdate() {
clearTimeout(debounceTimeout);
debounceTimeout = setTimeout(() => {
updateScore();
updateSectionProgress();
localStorage.setItem('checklistData', JSON.stringify(checklistData));
}, 300);
}
function showModal(modalId) {
document.getElementById(modalId).style.display = 'block';
document.body.classList.add('modal-open');
}
function closeModal(modalId) {
document.getElementById(modalId).style.display = 'none';
document.body.classList.remove('modal-open');
}
function addNewCriteria(e) {
e.preventDefault();
const sectionIndex = document.getElementById('sectionSelect').value;
const newCriteria = document.getElementById('newCriteriaInput').value.trim();
const newCriteriaPriority = parseInt(document.getElementById('newCriteriaPriority').value, 10);
if (newCriteria && !isNaN(newCriteriaPriority)) {
saveState();
checklistData.sections[sectionIndex].criteria.push({
text: newCriteria,
checked: false,
priority: newCriteriaPriority,
notes: '',
imageData: null
});
updateUI();
closeModal('addCriteriaModal');
document.getElementById('addCriteriaForm').reset();
document.getElementById('priorityValue').textContent = '1';
}
}
function addNewSection(e) {
e.preventDefault();
const newSectionName = document.getElementById('newSectionInput').value.trim();
if (newSectionName) {
saveState();
checklistData.sections.push({ name: newSectionName, criteria: [] });
updateUI();
closeModal('addSectionModal');
document.getElementById('addSectionForm').reset();
}
}
function editSectionName(sectionIndex) {
const currentName = checklistData.sections[sectionIndex].name;
showCustomModal('Edit Section Name', `<input type="text" id="editSectionNameInput" value="${currentName}" aria-label="Edit Section Name">`, [
{ text: 'Cancel', handler: closeCustomModal },
{ text: 'Save', handler: () => {
const newName = document.getElementById('editSectionNameInput').value.trim();
if (newName) {
saveState();
checklistData.sections[sectionIndex].name = newName;
updateUI();
closeCustomModal();
}
} }
]);
}
function deleteSection(sectionIndex) {
showCustomModal('Delete Section', 'Are you sure you want to delete this section?', [
{ text: 'Cancel', handler: closeCustomModal },
{ text: 'Delete', handler: () => {
saveState();
checklistData.sections.splice(sectionIndex, 1);
updateUI();
closeCustomModal();
} }
]);
}
function editCriteria(sectionIndex, criteriaIndex) {
const criteria = checklistData.sections[sectionIndex].criteria[criteriaIndex];
showCustomModal('Edit Criteria', `
<input type="text" id="editCriteriaText" value="${criteria.text}" aria-label="Edit Criteria Text">
<input type="number" id="editCriteriaPriority" value="${criteria.priority}" min="1" aria-label="Edit Criteria Priority">
`, [
{ text: 'Cancel', handler: closeCustomModal },
{ text: 'Save', handler: () => {
const newText = document.getElementById('editCriteriaText').value.trim();
const newPriority = parseInt(document.getElementById('editCriteriaPriority').value, 10);
if (newText && !isNaN(newPriority)) {
saveState();
criteria.text = newText;
criteria.priority = newPriority;
updateUI();
closeCustomModal();
}
} }
]);
}
function deleteCriteria(sectionIndex, criteriaIndex) {
showCustomModal('Delete Criteria', 'Are you sure you want to delete this criteria?', [
{ text: 'Cancel', handler: closeCustomModal },
{ text: 'Delete', handler: () => {
saveState();
checklistData.sections[sectionIndex].criteria.splice(criteriaIndex, 1);
updateUI();
closeCustomModal();
} }
]);
}
function dragStart(e) {
e.dataTransfer.setData('text/plain', e.target.dataset.sectionIndex + ',' + (e.target.dataset.criteriaIndex || ''));
}
function dragOver(e) {
e.preventDefault();
}
function drop(e) {
e.preventDefault();
const [fromSectionIndex, fromCriteriaIndex] = e.dataTransfer.getData('text/plain').split(',');
const toSectionCard = e.target.closest('.section-card');
const toCriteriaItem = e.target.closest('.checklist-item');
if (toSectionCard) {
const toSectionIndex = toSectionCard.dataset.sectionIndex;
if (fromCriteriaIndex === '') {
if (fromSectionIndex !== toSectionIndex) {
saveState();
const fromIndex = parseInt(fromSectionIndex, 10);
const toIndex = parseInt(toSectionIndex, 10);
const [movedSection] = checklistData.sections.splice(fromIndex, 1);
checklistData.sections.splice(toIndex, 0, movedSection);
updateUI();
}
} else {
saveState();
const fromSecIndex = parseInt(fromSectionIndex, 10);
const fromCritIndex = parseInt(fromCriteriaIndex, 10);
const toSecIndex = parseInt(toSectionIndex, 10);
const toCritIndex = toCriteriaItem ? parseInt(toCriteriaItem.dataset.criteriaIndex, 10) : null;
const [movedCriteria] = checklistData.sections[fromSecIndex].criteria.splice(fromCritIndex, 1);
if (toCritIndex !== null) {
checklistData.sections[toSecIndex].criteria.splice(toCritIndex, 0, movedCriteria);
} else {
checklistData.sections[toSecIndex].criteria.push(movedCriteria);
}
updateUI();
}
}
}
async function exportChecklistData() {
try {
const dataStr = JSON.stringify(checklistData);
const blob = new Blob([dataStr], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const downloadAnchorNode = document.createElement('a');
downloadAnchorNode.href = url;
downloadAnchorNode.download = 'checklist_data.json';
document.body.appendChild(downloadAnchorNode);
downloadAnchorNode.click();
downloadAnchorNode.remove();
URL.revokeObjectURL(url);
} catch (error) {
alert('Error exporting data.');
}
}
async function importChecklistData() {
const input = document.createElement('input');
input.type = 'file';
input.accept = '.json';
input.addEventListener('change', async function(event) {
try {
const file = event.target.files[0];
if (file) {
saveState();
const text = await file.text();
checklistData = JSON.parse(text);
updateUI();
}
} catch (error) {
alert('Error importing data.');
}
});
input.click();
}
function resetChecklistData() {
showCustomModal('Reset Data', 'Are you sure you want to reset all data?', [
{ text: 'Cancel', handler: closeCustomModal },
{ text: 'Reset', handler: () => {
saveState();
checklistData = { sections: [] };
updateUI();
closeCustomModal();
} }
]);
}
function toggleNotes(sectionIndex, criteriaIndex) {
const notesSection = document.querySelector(`.checklist-item[data-section-index="${sectionIndex}"][data-criteria-index="${criteriaIndex}"] .notes-section`);
if (notesSection) {
notesSection.style.display = notesSection.style.display === 'block' ? 'none' : 'block';
}
}
function saveNotes(sectionIndex, criteriaIndex, notes) {
saveState();
checklistData.sections[sectionIndex].criteria[criteriaIndex].notes = notes;
localStorage.setItem('checklistData', JSON.stringify(checklistData));
}
function handleFileUpload(event, sectionIndex, criteriaIndex) {
const file = event.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function(e) {
saveState();
checklistData.sections[sectionIndex].criteria[criteriaIndex].imageData = e.target.result;
updateUI();
};
reader.readAsDataURL(file);
}
}
function getTotalItems() {
return checklistData.sections.reduce((total, section) => total + section.criteria.length, 0);
}
function getCompletedItems() {
return checklistData.sections.reduce((total, section) => total + section.criteria.filter(criteria => criteria.checked).length, 0);
}
function saveState() {
undoStack.push(JSON.parse(JSON.stringify(checklistData)));
if (undoStack.length > 100) undoStack.shift();
redoStack = [];
}
function undo() {
if (undoStack.length > 1) {
redoStack.push(undoStack.pop());
checklistData = JSON.parse(JSON.stringify(undoStack[undoStack.length - 1]));
updateUI();
}
}
function redo() {
if (redoStack.length > 0) {
undoStack.push(redoStack.pop());
checklistData = JSON.parse(JSON.stringify(undoStack[undoStack.length - 1]));
updateUI();
}
}
function loadState() {
const storedData = localStorage.getItem('checklistData');
if (storedData) {
checklistData = JSON.parse(storedData);
} 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 }
]
}
]
};
}
undoStack.push(JSON.parse(JSON.stringify(checklistData)));
}
function populateSectionSelect() {
const sectionSelect = document.getElementById('sectionSelect');
sectionSelect.innerHTML = '';
checklistData.sections.forEach((section, index) => {
const option = document.createElement('option');
option.value = index;
option.textContent = section.name;
sectionSelect.appendChild(option);
});
}
function showCustomModal(title, bodyContent, actions) {
const modalOverlay = document.getElementById('modalOverlay');
const modalBody = document.getElementById('customModalBody');
const modalActions = document.getElementById('customModalActions');
document.getElementById('closeCustomModal').addEventListener('click', closeCustomModal);
modalBody.innerHTML = `<h2>${title}</h2>${bodyContent}`;
modalActions.innerHTML = '';
actions.forEach(action => {
const button = document.createElement('button');
button.textContent = action.text;
button.addEventListener('click', action.handler);
modalActions.appendChild(button);
});
modalOverlay.style.display = 'block';
}
function closeCustomModal() {
const modalOverlay = document.getElementById('modalOverlay');
modalOverlay.style.display = 'none';
}
})();
</script>
</body>
</html>