Spaces:
Sleeping
Sleeping
Update static/script.js
Browse files- static/script.js +40 -16
static/script.js
CHANGED
|
@@ -71,7 +71,7 @@ function updateSelectionBox() {
|
|
| 71 |
label.textContent = 'Selected Items:';
|
| 72 |
selectionBox.appendChild(label);
|
| 73 |
|
| 74 |
-
selectedItems.forEach(item => {
|
| 75 |
const itemContainer = document.createElement('div');
|
| 76 |
itemContainer.className = 'selected-item';
|
| 77 |
|
|
@@ -85,6 +85,16 @@ function updateSelectionBox() {
|
|
| 85 |
itemSpan.textContent = item.name;
|
| 86 |
itemContainer.appendChild(itemSpan);
|
| 87 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
selectionBox.appendChild(itemContainer);
|
| 89 |
});
|
| 90 |
|
|
@@ -96,10 +106,15 @@ function updateSelectionBox() {
|
|
| 96 |
if (e.key === 'Enter' && textInput.value.trim()) {
|
| 97 |
const manualItem = {
|
| 98 |
name: textInput.value.trim(),
|
| 99 |
-
image_url: ''
|
|
|
|
| 100 |
};
|
| 101 |
-
selectedItems.
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
textInput.value = '';
|
| 104 |
updateSelectionBox();
|
| 105 |
}
|
|
@@ -205,10 +220,13 @@ function fetchItemDetails(itemName) {
|
|
| 205 |
updateSelectionBox();
|
| 206 |
} else {
|
| 207 |
const details = data.item_details;
|
| 208 |
-
selectedItems.
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
|
|
|
|
|
|
|
|
|
| 212 |
}
|
| 213 |
})
|
| 214 |
.catch(error => {
|
|
@@ -248,11 +266,16 @@ function showDescriptionPopup(item) {
|
|
| 248 |
addButton.onclick = () => {
|
| 249 |
const sectorItem = {
|
| 250 |
name: item.name,
|
| 251 |
-
image_url: item.image_url || ''
|
|
|
|
| 252 |
};
|
| 253 |
-
selectedItems.
|
| 254 |
-
|
| 255 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
popup.remove();
|
| 257 |
};
|
| 258 |
content.appendChild(addButton);
|
|
@@ -301,9 +324,7 @@ function displayItemsList(items, containerId, isSectorDetail = false) {
|
|
| 301 |
} else {
|
| 302 |
const addButton = document.createElement('button');
|
| 303 |
addButton.textContent = 'Add';
|
| 304 |
-
addButton.onclick = () =>
|
| 305 |
-
fetchItemDetails(item.name);
|
| 306 |
-
};
|
| 307 |
itemDiv.appendChild(addButton);
|
| 308 |
}
|
| 309 |
|
|
@@ -351,7 +372,10 @@ function submitToSalesforce() {
|
|
| 351 |
return;
|
| 352 |
}
|
| 353 |
|
| 354 |
-
const itemsToSubmit = selectedItems.map(item => ({
|
|
|
|
|
|
|
|
|
|
| 355 |
|
| 356 |
fetch('/submit_items', {
|
| 357 |
method: 'POST',
|
|
|
|
| 71 |
label.textContent = 'Selected Items:';
|
| 72 |
selectionBox.appendChild(label);
|
| 73 |
|
| 74 |
+
selectedItems.forEach((item, index) => {
|
| 75 |
const itemContainer = document.createElement('div');
|
| 76 |
itemContainer.className = 'selected-item';
|
| 77 |
|
|
|
|
| 85 |
itemSpan.textContent = item.name;
|
| 86 |
itemContainer.appendChild(itemSpan);
|
| 87 |
|
| 88 |
+
const removeButton = document.createElement('button');
|
| 89 |
+
removeButton.textContent = 'Remove';
|
| 90 |
+
removeButton.className = 'remove-button';
|
| 91 |
+
removeButton.onclick = () => {
|
| 92 |
+
selectedItems.splice(index, 1);
|
| 93 |
+
addMessage('bot', `Removed "${item.name}" from your selection.`);
|
| 94 |
+
updateSelectionBox();
|
| 95 |
+
};
|
| 96 |
+
itemContainer.appendChild(removeButton);
|
| 97 |
+
|
| 98 |
selectionBox.appendChild(itemContainer);
|
| 99 |
});
|
| 100 |
|
|
|
|
| 106 |
if (e.key === 'Enter' && textInput.value.trim()) {
|
| 107 |
const manualItem = {
|
| 108 |
name: textInput.value.trim(),
|
| 109 |
+
image_url: '',
|
| 110 |
+
description: 'Manually added item'
|
| 111 |
};
|
| 112 |
+
if (selectedItems.some(item => item.name === manualItem.name)) {
|
| 113 |
+
addMessage('bot', `"${manualItem.name}" is already in your selection!`);
|
| 114 |
+
} else {
|
| 115 |
+
selectedItems.push(manualItem);
|
| 116 |
+
addMessage('bot', `Added "${manualItem.name}" to your selection! Check the box below.`);
|
| 117 |
+
}
|
| 118 |
textInput.value = '';
|
| 119 |
updateSelectionBox();
|
| 120 |
}
|
|
|
|
| 220 |
updateSelectionBox();
|
| 221 |
} else {
|
| 222 |
const details = data.item_details;
|
| 223 |
+
if (selectedItems.some(item => item.name === details.name)) {
|
| 224 |
+
addMessage('bot', `"${details.name}" is already in your selection!`);
|
| 225 |
+
} else {
|
| 226 |
+
selectedItems.push(details);
|
| 227 |
+
addMessage('bot', `Added "${itemName}" to your selection! Check the box below.`);
|
| 228 |
+
updateSelectionBox();
|
| 229 |
+
}
|
| 230 |
}
|
| 231 |
})
|
| 232 |
.catch(error => {
|
|
|
|
| 266 |
addButton.onclick = () => {
|
| 267 |
const sectorItem = {
|
| 268 |
name: item.name,
|
| 269 |
+
image_url: item.image_url || '',
|
| 270 |
+
description: item.description
|
| 271 |
};
|
| 272 |
+
if (selectedItems.some(existing => existing.name === sectorItem.name)) {
|
| 273 |
+
addMessage('bot', `"${sectorItem.name}" is already in your selection!`);
|
| 274 |
+
} else {
|
| 275 |
+
selectedItems.push(sectorItem);
|
| 276 |
+
addMessage('bot', `Added "${sectorItem.name}" to your selection! Check the box below.`);
|
| 277 |
+
updateSelectionBox();
|
| 278 |
+
}
|
| 279 |
popup.remove();
|
| 280 |
};
|
| 281 |
content.appendChild(addButton);
|
|
|
|
| 324 |
} else {
|
| 325 |
const addButton = document.createElement('button');
|
| 326 |
addButton.textContent = 'Add';
|
| 327 |
+
addButton.onclick = () => fetchItemDetails(item.name);
|
|
|
|
|
|
|
| 328 |
itemDiv.appendChild(addButton);
|
| 329 |
}
|
| 330 |
|
|
|
|
| 372 |
return;
|
| 373 |
}
|
| 374 |
|
| 375 |
+
const itemsToSubmit = selectedItems.map(item => ({
|
| 376 |
+
name: item.name,
|
| 377 |
+
description: item.description || 'No description available'
|
| 378 |
+
}));
|
| 379 |
|
| 380 |
fetch('/submit_items', {
|
| 381 |
method: 'POST',
|