@@ -6687,6 +6687,21 @@ function initResourceSelect(
66876687 'input[type="checkbox"]',
66886688 );
66896689 checkboxes.forEach((cb) => (cb.checked = false));
6690+
6691+ // Remove any select-all hidden inputs
6692+ const selectAllInput = container.querySelector(
6693+ 'input[name="selectAllResources"]',
6694+ );
6695+ if (selectAllInput) {
6696+ selectAllInput.remove();
6697+ }
6698+ const allIdsInput = container.querySelector(
6699+ 'input[name="allResourceIds"]',
6700+ );
6701+ if (allIdsInput) {
6702+ allIdsInput.remove();
6703+ }
6704+
66906705 update();
66916706 });
66926707 }
@@ -6697,12 +6712,61 @@ function initResourceSelect(
66976712 newSelectBtn.dataset.listenerAttached = "true";
66986713 selectBtn.parentNode.replaceChild(newSelectBtn, selectBtn);
66996714
6700- newSelectBtn.addEventListener("click", () => {
6701- const checkboxes = container.querySelectorAll(
6702- 'input[type="checkbox"]',
6703- );
6704- checkboxes.forEach((cb) => (cb.checked = true));
6705- update();
6715+ newSelectBtn.addEventListener("click", async () => {
6716+ const originalText = newSelectBtn.textContent;
6717+ newSelectBtn.disabled = true;
6718+ newSelectBtn.textContent = "Selecting all resources...";
6719+
6720+ try {
6721+ const resp = await fetch(`${window.ROOT_PATH}/admin/resources/ids`);
6722+ if (!resp.ok) {
6723+ throw new Error("Failed to fetch resource IDs");
6724+ }
6725+ const data = await resp.json();
6726+ const allIds = data.resource_ids || [];
6727+
6728+ // Check all currently loaded checkboxes
6729+ const loadedCheckboxes = container.querySelectorAll(
6730+ 'input[type="checkbox"]',
6731+ );
6732+ loadedCheckboxes.forEach((cb) => (cb.checked = true));
6733+
6734+ // Add hidden select-all flag
6735+ let selectAllInput = container.querySelector(
6736+ 'input[name="selectAllResources"]',
6737+ );
6738+ if (!selectAllInput) {
6739+ selectAllInput = document.createElement("input");
6740+ selectAllInput.type = "hidden";
6741+ selectAllInput.name = "selectAllResources";
6742+ container.appendChild(selectAllInput);
6743+ }
6744+ selectAllInput.value = "true";
6745+
6746+ // Store IDs as JSON for backend handling
6747+ let allIdsInput = container.querySelector(
6748+ 'input[name="allResourceIds"]',
6749+ );
6750+ if (!allIdsInput) {
6751+ allIdsInput = document.createElement("input");
6752+ allIdsInput.type = "hidden";
6753+ allIdsInput.name = "allResourceIds";
6754+ container.appendChild(allIdsInput);
6755+ }
6756+ allIdsInput.value = JSON.stringify(allIds);
6757+
6758+ update();
6759+
6760+ newSelectBtn.textContent = `✓ All ${allIds.length} resources selected`;
6761+ setTimeout(() => {
6762+ newSelectBtn.textContent = originalText;
6763+ }, 2000);
6764+ } catch (error) {
6765+ console.error("Error selecting all resources:", error);
6766+ alert("Failed to select all resources. Please try again.");
6767+ } finally {
6768+ newSelectBtn.disabled = false;
6769+ }
67066770 });
67076771 }
67086772
@@ -6713,6 +6777,33 @@ function initResourceSelect(
67136777 container.dataset.changeListenerAttached = "true";
67146778 container.addEventListener("change", (e) => {
67156779 if (e.target.type === "checkbox") {
6780+ // If Select All mode is active, update the stored IDs array
6781+ const selectAllInput = container.querySelector(
6782+ 'input[name="selectAllResources"]',
6783+ );
6784+ const allIdsInput = container.querySelector(
6785+ 'input[name="allResourceIds"]',
6786+ );
6787+
6788+ if (
6789+ selectAllInput &&
6790+ selectAllInput.value === "true" &&
6791+ allIdsInput
6792+ ) {
6793+ try {
6794+ let allIds = JSON.parse(allIdsInput.value);
6795+ const id = e.target.value;
6796+ if (e.target.checked) {
6797+ if (!allIds.includes(id)) allIds.push(id);
6798+ } else {
6799+ allIds = allIds.filter((x) => x !== id);
6800+ }
6801+ allIdsInput.value = JSON.stringify(allIds);
6802+ } catch (err) {
6803+ console.error("Error updating allResourceIds:", err);
6804+ }
6805+ }
6806+
67166807 update();
67176808 }
67186809 });
@@ -6796,6 +6887,21 @@ function initPromptSelect(
67966887 'input[type="checkbox"]',
67976888 );
67986889 checkboxes.forEach((cb) => (cb.checked = false));
6890+
6891+ // Remove any select-all hidden inputs
6892+ const selectAllInput = container.querySelector(
6893+ 'input[name="selectAllPrompts"]',
6894+ );
6895+ if (selectAllInput) {
6896+ selectAllInput.remove();
6897+ }
6898+ const allIdsInput = container.querySelector(
6899+ 'input[name="allPromptIds"]',
6900+ );
6901+ if (allIdsInput) {
6902+ allIdsInput.remove();
6903+ }
6904+
67996905 update();
68006906 });
68016907 }
@@ -6805,13 +6911,61 @@ function initPromptSelect(
68056911 const newSelectBtn = selectBtn.cloneNode(true);
68066912 newSelectBtn.dataset.listenerAttached = "true";
68076913 selectBtn.parentNode.replaceChild(newSelectBtn, selectBtn);
6914+ newSelectBtn.addEventListener("click", async () => {
6915+ const originalText = newSelectBtn.textContent;
6916+ newSelectBtn.disabled = true;
6917+ newSelectBtn.textContent = "Selecting all prompts...";
68086918
6809- newSelectBtn.addEventListener("click", () => {
6810- const checkboxes = container.querySelectorAll(
6811- 'input[type="checkbox"]',
6812- );
6813- checkboxes.forEach((cb) => (cb.checked = true));
6814- update();
6919+ try {
6920+ const resp = await fetch(`${window.ROOT_PATH}/admin/prompts/ids`);
6921+ if (!resp.ok) {
6922+ throw new Error("Failed to fetch prompt IDs");
6923+ }
6924+ const data = await resp.json();
6925+ const allIds = data.prompt_ids || [];
6926+
6927+ // Check all currently loaded checkboxes
6928+ const loadedCheckboxes = container.querySelectorAll(
6929+ 'input[type="checkbox"]',
6930+ );
6931+ loadedCheckboxes.forEach((cb) => (cb.checked = true));
6932+
6933+ // Add hidden select-all flag
6934+ let selectAllInput = container.querySelector(
6935+ 'input[name="selectAllPrompts"]',
6936+ );
6937+ if (!selectAllInput) {
6938+ selectAllInput = document.createElement("input");
6939+ selectAllInput.type = "hidden";
6940+ selectAllInput.name = "selectAllPrompts";
6941+ container.appendChild(selectAllInput);
6942+ }
6943+ selectAllInput.value = "true";
6944+
6945+ // Store IDs as JSON for backend handling
6946+ let allIdsInput = container.querySelector(
6947+ 'input[name="allPromptIds"]',
6948+ );
6949+ if (!allIdsInput) {
6950+ allIdsInput = document.createElement("input");
6951+ allIdsInput.type = "hidden";
6952+ allIdsInput.name = "allPromptIds";
6953+ container.appendChild(allIdsInput);
6954+ }
6955+ allIdsInput.value = JSON.stringify(allIds);
6956+
6957+ update();
6958+
6959+ newSelectBtn.textContent = `✓ All ${allIds.length} prompts selected`;
6960+ setTimeout(() => {
6961+ newSelectBtn.textContent = originalText;
6962+ }, 2000);
6963+ } catch (error) {
6964+ console.error("Error selecting all prompts:", error);
6965+ alert("Failed to select all prompts. Please try again.");
6966+ } finally {
6967+ newSelectBtn.disabled = false;
6968+ }
68156969 });
68166970 }
68176971
@@ -6822,6 +6976,33 @@ function initPromptSelect(
68226976 container.dataset.changeListenerAttached = "true";
68236977 container.addEventListener("change", (e) => {
68246978 if (e.target.type === "checkbox") {
6979+ // If Select All mode is active, update the stored IDs array
6980+ const selectAllInput = container.querySelector(
6981+ 'input[name="selectAllPrompts"]',
6982+ );
6983+ const allIdsInput = container.querySelector(
6984+ 'input[name="allPromptIds"]',
6985+ );
6986+
6987+ if (
6988+ selectAllInput &&
6989+ selectAllInput.value === "true" &&
6990+ allIdsInput
6991+ ) {
6992+ try {
6993+ let allIds = JSON.parse(allIdsInput.value);
6994+ const id = e.target.value;
6995+ if (e.target.checked) {
6996+ if (!allIds.includes(id)) allIds.push(id);
6997+ } else {
6998+ allIds = allIds.filter((x) => x !== id);
6999+ }
7000+ allIdsInput.value = JSON.stringify(allIds);
7001+ } catch (err) {
7002+ console.error("Error updating allPromptIds:", err);
7003+ }
7004+ }
7005+
68257006 update();
68267007 }
68277008 });
0 commit comments