Spaces:
Sleeping
Sleeping
Lucas ARRIESSE
commited on
Commit
·
daecf53
1
Parent(s):
551031a
Attempt to fix JS
Browse files- static/script.js +46 -16
static/script.js
CHANGED
|
@@ -720,37 +720,47 @@ async function categorizeRequirements(max_categories) {
|
|
| 720 |
*/
|
| 721 |
function displayCategorizedRequirements(categorizedData) {
|
| 722 |
const container = document.getElementById('categorized-requirements-list');
|
|
|
|
|
|
|
|
|
|
|
|
|
| 723 |
container.innerHTML = '';
|
| 724 |
|
| 725 |
categorizedData.forEach((category, categoryIndex) => {
|
| 726 |
const categoryDiv = document.createElement('div');
|
| 727 |
-
categoryDiv.
|
| 728 |
-
categoryDiv.className = 'collapse collapse-arrow mb-2 border border-gray-200 rounded-lg bg-white';
|
| 729 |
-
|
| 730 |
|
| 731 |
-
// Generate unique IDs for checkboxes
|
| 732 |
const globalCheckboxId = `global-checkbox-${categoryIndex}`;
|
| 733 |
|
|
|
|
| 734 |
const requirementsHTML = category.requirements.map((req, reqIndex) => {
|
| 735 |
const checkboxId = `checkbox-${categoryIndex}-${reqIndex}`;
|
| 736 |
return `
|
| 737 |
-
<div class="p-2 bg-gray-50 rounded border-l-4 border-blue-400 flex items-start gap-
|
| 738 |
-
<input type="checkbox" class="item-checkbox" id="${checkboxId}" data-category-index="${categoryIndex}" />
|
| 739 |
-
<label for="${checkboxId}" class="flex-1">
|
| 740 |
-
<div class="text-sm font-medium text-gray-
|
| 741 |
<div class="text-sm text-gray-600">${req.requirement}</div>
|
| 742 |
</label>
|
| 743 |
</div>`;
|
| 744 |
}).join('');
|
| 745 |
|
|
|
|
| 746 |
categoryDiv.innerHTML = `
|
| 747 |
-
|
| 748 |
-
<input type="checkbox"
|
| 749 |
-
|
| 750 |
-
|
| 751 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 752 |
<div class="collapse-content text-sm">
|
| 753 |
-
<div class="space-y-2">
|
| 754 |
${requirementsHTML}
|
| 755 |
</div>
|
| 756 |
</div>
|
|
@@ -759,7 +769,16 @@ function displayCategorizedRequirements(categorizedData) {
|
|
| 759 |
container.appendChild(categoryDiv);
|
| 760 |
});
|
| 761 |
|
| 762 |
-
// Event
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 763 |
container.querySelectorAll('.global-checkbox').forEach(globalCheckbox => {
|
| 764 |
globalCheckbox.addEventListener('change', (e) => {
|
| 765 |
const categoryIndex = e.target.dataset.categoryIndex;
|
|
@@ -770,7 +789,7 @@ function displayCategorizedRequirements(categorizedData) {
|
|
| 770 |
});
|
| 771 |
});
|
| 772 |
|
| 773 |
-
// Update global checkbox state when individual
|
| 774 |
container.querySelectorAll('.item-checkbox').forEach(itemCheckbox => {
|
| 775 |
itemCheckbox.addEventListener('change', (e) => {
|
| 776 |
const categoryIndex = e.target.dataset.categoryIndex;
|
|
@@ -778,7 +797,18 @@ function displayCategorizedRequirements(categorizedData) {
|
|
| 778 |
const globalCheckbox = container.querySelector(`.global-checkbox[data-category-index="${categoryIndex}"]`);
|
| 779 |
|
| 780 |
const allChecked = Array.from(itemCheckboxes).every(cb => cb.checked);
|
|
|
|
|
|
|
| 781 |
globalCheckbox.checked = allChecked;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 782 |
});
|
| 783 |
});
|
| 784 |
}
|
|
|
|
| 720 |
*/
|
| 721 |
function displayCategorizedRequirements(categorizedData) {
|
| 722 |
const container = document.getElementById('categorized-requirements-list');
|
| 723 |
+
if (!container) {
|
| 724 |
+
console.error('Container element with ID "categorized-requirements-list" not found.');
|
| 725 |
+
return;
|
| 726 |
+
}
|
| 727 |
container.innerHTML = '';
|
| 728 |
|
| 729 |
categorizedData.forEach((category, categoryIndex) => {
|
| 730 |
const categoryDiv = document.createElement('div');
|
| 731 |
+
categoryDiv.className = 'collapse collapse-arrow mb-2 border border-gray-200 rounded-lg bg-white shadow-sm';
|
|
|
|
|
|
|
| 732 |
|
| 733 |
+
// Generate unique IDs for all checkboxes
|
| 734 |
const globalCheckboxId = `global-checkbox-${categoryIndex}`;
|
| 735 |
|
| 736 |
+
// Create the HTML for the individual requirement items within a category
|
| 737 |
const requirementsHTML = category.requirements.map((req, reqIndex) => {
|
| 738 |
const checkboxId = `checkbox-${categoryIndex}-${reqIndex}`;
|
| 739 |
return `
|
| 740 |
+
<div class="p-2.5 bg-gray-50 rounded border-l-4 border-blue-400 flex items-start gap-3" data-category-index="${categoryIndex}" data-cat-req-id="${reqIndex}">
|
| 741 |
+
<input type="checkbox" class="item-checkbox checkbox checkbox-sm mt-1" id="${checkboxId}" data-category-index="${categoryIndex}" />
|
| 742 |
+
<label for="${checkboxId}" class="flex-1 cursor-pointer">
|
| 743 |
+
<div class="text-sm font-medium text-gray-800">${req.document}</div>
|
| 744 |
<div class="text-sm text-gray-600">${req.requirement}</div>
|
| 745 |
</label>
|
| 746 |
</div>`;
|
| 747 |
}).join('');
|
| 748 |
|
| 749 |
+
// Set the innerHTML for the entire collapsible category component
|
| 750 |
categoryDiv.innerHTML = `
|
| 751 |
+
<!-- This hidden checkbox controls the collapse state -->
|
| 752 |
+
<input type="checkbox" name="collapse-accordion-${categoryIndex}" />
|
| 753 |
+
|
| 754 |
+
<div class="collapse-title text-lg font-semibold text-blue-600">
|
| 755 |
+
<!-- This wrapper prevents the collapse from triggering when clicking the checkbox or its label -->
|
| 756 |
+
<div class="checkbox-and-title-wrapper flex items-center gap-3">
|
| 757 |
+
<input type="checkbox" class="global-checkbox checkbox" id="${globalCheckboxId}" data-category-index="${categoryIndex}" />
|
| 758 |
+
<label for="${globalCheckboxId}" class="cursor-pointer">${category.title}</label>
|
| 759 |
+
</div>
|
| 760 |
+
</div>
|
| 761 |
+
|
| 762 |
<div class="collapse-content text-sm">
|
| 763 |
+
<div class="space-y-2 p-2">
|
| 764 |
${requirementsHTML}
|
| 765 |
</div>
|
| 766 |
</div>
|
|
|
|
| 769 |
container.appendChild(categoryDiv);
|
| 770 |
});
|
| 771 |
|
| 772 |
+
// --- Event Listeners ---
|
| 773 |
+
|
| 774 |
+
// Stop click propagation on the checkbox wrapper to isolate it from the collapse trigger
|
| 775 |
+
container.querySelectorAll('.checkbox-and-title-wrapper').forEach(wrapper => {
|
| 776 |
+
wrapper.addEventListener('click', (e) => {
|
| 777 |
+
e.stopPropagation();
|
| 778 |
+
});
|
| 779 |
+
});
|
| 780 |
+
|
| 781 |
+
// Handle "select all" logic when the global checkbox is changed
|
| 782 |
container.querySelectorAll('.global-checkbox').forEach(globalCheckbox => {
|
| 783 |
globalCheckbox.addEventListener('change', (e) => {
|
| 784 |
const categoryIndex = e.target.dataset.categoryIndex;
|
|
|
|
| 789 |
});
|
| 790 |
});
|
| 791 |
|
| 792 |
+
// Update the global checkbox state when any individual item checkbox is changed
|
| 793 |
container.querySelectorAll('.item-checkbox').forEach(itemCheckbox => {
|
| 794 |
itemCheckbox.addEventListener('change', (e) => {
|
| 795 |
const categoryIndex = e.target.dataset.categoryIndex;
|
|
|
|
| 797 |
const globalCheckbox = container.querySelector(`.global-checkbox[data-category-index="${categoryIndex}"]`);
|
| 798 |
|
| 799 |
const allChecked = Array.from(itemCheckboxes).every(cb => cb.checked);
|
| 800 |
+
const someChecked = Array.from(itemCheckboxes).some(cb => cb.checked);
|
| 801 |
+
|
| 802 |
globalCheckbox.checked = allChecked;
|
| 803 |
+
|
| 804 |
+
// Set indeterminate state for better UX
|
| 805 |
+
if (allChecked) {
|
| 806 |
+
globalCheckbox.indeterminate = false;
|
| 807 |
+
} else if (someChecked) {
|
| 808 |
+
globalCheckbox.indeterminate = true;
|
| 809 |
+
} else {
|
| 810 |
+
globalCheckbox.indeterminate = false;
|
| 811 |
+
}
|
| 812 |
});
|
| 813 |
});
|
| 814 |
}
|