Spaces:
Sleeping
Sleeping
Update static/script.js
Browse files- static/script.js +39 -17
static/script.js
CHANGED
@@ -42,29 +42,50 @@ function updateSelectionBox() {
|
|
42 |
const existingBox = document.querySelector('.selection-box');
|
43 |
if (existingBox) existingBox.remove();
|
44 |
|
45 |
-
|
46 |
-
|
47 |
-
selectionBox.className = 'selection-box';
|
48 |
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
|
|
|
59 |
const submitButton = document.createElement('button');
|
60 |
submitButton.textContent = 'Submit to Salesforce';
|
61 |
submitButton.className = 'submit-button';
|
62 |
submitButton.onclick = submitToSalesforce;
|
63 |
selectionBox.appendChild(submitButton);
|
64 |
-
|
65 |
-
chatMessages.appendChild(selectionBox);
|
66 |
-
chatMessages.scrollTop = chatMessages.scrollHeight;
|
67 |
}
|
|
|
|
|
|
|
68 |
console.log('Updated selection box with items:', selectedItems.map(item => item.name));
|
69 |
}
|
70 |
|
@@ -105,7 +126,6 @@ function fetchMenuItems(dietaryPreference) {
|
|
105 |
if (data.error) {
|
106 |
addMessage('bot', `Oops! Trouble fetching ${dietaryPreference} items: ${data.error}. Want to try again or search something specific?`);
|
107 |
} else if (data.menu_items.length > 0) {
|
108 |
-
// Removed the message: "Here’s a tasty selection of ${dietaryPreference} items from Sector_Detail__c:"
|
109 |
displayItemsList(data.menu_items, 'menuItemsList');
|
110 |
} else {
|
111 |
addMessage('bot', `Looks like we’re out of ${dietaryPreference} items in Sector_Detail__c. Try searching for something like "paneer" or "chicken"!`);
|
@@ -151,7 +171,8 @@ function fetchItemDetails(itemName) {
|
|
151 |
.then(response => response.json())
|
152 |
.then(data => {
|
153 |
if (data.error) {
|
154 |
-
addMessage('bot', `
|
|
|
155 |
} else {
|
156 |
const details = data.item_details;
|
157 |
selectedItems.push(details);
|
@@ -161,7 +182,8 @@ function fetchItemDetails(itemName) {
|
|
161 |
}
|
162 |
})
|
163 |
.catch(error => {
|
164 |
-
addMessage('bot', `Trouble fetching details for "${itemName}": ${error.message}.
|
|
|
165 |
setTimeout(() => fetchItemDetails(itemName), 2000);
|
166 |
});
|
167 |
}
|
|
|
42 |
const existingBox = document.querySelector('.selection-box');
|
43 |
if (existingBox) existingBox.remove();
|
44 |
|
45 |
+
const selectionBox = document.createElement('div');
|
46 |
+
selectionBox.className = 'selection-box';
|
|
|
47 |
|
48 |
+
const label = document.createElement('span');
|
49 |
+
label.textContent = 'Selected Items:';
|
50 |
+
selectionBox.appendChild(label);
|
51 |
|
52 |
+
selectedItems.forEach(item => {
|
53 |
+
const itemSpan = document.createElement('span');
|
54 |
+
itemSpan.textContent = item.name;
|
55 |
+
selectionBox.appendChild(itemSpan);
|
56 |
+
});
|
57 |
+
|
58 |
+
// Add text input for manual item entry
|
59 |
+
const textInput = document.createElement('input');
|
60 |
+
textInput.type = 'text';
|
61 |
+
textInput.placeholder = 'Add item manually...';
|
62 |
+
textInput.className = 'manual-input';
|
63 |
+
textInput.addEventListener('keypress', (e) => {
|
64 |
+
if (e.key === 'Enter' && textInput.value.trim()) {
|
65 |
+
const manualItem = {
|
66 |
+
name: textInput.value.trim(),
|
67 |
+
description: 'Manually added',
|
68 |
+
ingredients: 'Not specified',
|
69 |
+
image_url: ''
|
70 |
+
};
|
71 |
+
selectedItems.push(manualItem);
|
72 |
+
addMessage('bot', `Added "${manualItem.name}" to your selection! Check the box below.`);
|
73 |
+
textInput.value = '';
|
74 |
+
updateSelectionBox();
|
75 |
+
}
|
76 |
+
});
|
77 |
+
selectionBox.appendChild(textInput);
|
78 |
|
79 |
+
if (selectedItems.length > 0) {
|
80 |
const submitButton = document.createElement('button');
|
81 |
submitButton.textContent = 'Submit to Salesforce';
|
82 |
submitButton.className = 'submit-button';
|
83 |
submitButton.onclick = submitToSalesforce;
|
84 |
selectionBox.appendChild(submitButton);
|
|
|
|
|
|
|
85 |
}
|
86 |
+
|
87 |
+
chatMessages.appendChild(selectionBox);
|
88 |
+
chatMessages.scrollTop = chatMessages.scrollHeight;
|
89 |
console.log('Updated selection box with items:', selectedItems.map(item => item.name));
|
90 |
}
|
91 |
|
|
|
126 |
if (data.error) {
|
127 |
addMessage('bot', `Oops! Trouble fetching ${dietaryPreference} items: ${data.error}. Want to try again or search something specific?`);
|
128 |
} else if (data.menu_items.length > 0) {
|
|
|
129 |
displayItemsList(data.menu_items, 'menuItemsList');
|
130 |
} else {
|
131 |
addMessage('bot', `Looks like we’re out of ${dietaryPreference} items in Sector_Detail__c. Try searching for something like "paneer" or "chicken"!`);
|
|
|
171 |
.then(response => response.json())
|
172 |
.then(data => {
|
173 |
if (data.error) {
|
174 |
+
addMessage('bot', `Couldn’t find "${itemName}" in Salesforce. Add it manually in the box below!`);
|
175 |
+
updateSelectionBox(); // Show the box with text input even if no items are selected yet
|
176 |
} else {
|
177 |
const details = data.item_details;
|
178 |
selectedItems.push(details);
|
|
|
182 |
}
|
183 |
})
|
184 |
.catch(error => {
|
185 |
+
addMessage('bot', `Trouble fetching details for "${itemName}": ${error.message}. Add it manually below or I’ll retry...`);
|
186 |
+
updateSelectionBox(); // Show the box with text input on error
|
187 |
setTimeout(() => fetchItemDetails(itemName), 2000);
|
188 |
});
|
189 |
}
|