Spaces:
Sleeping
Sleeping
Update static/script.js
Browse files- static/script.js +23 -2
static/script.js
CHANGED
@@ -45,6 +45,26 @@ function updateSelectionBox() {
|
|
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);
|
@@ -76,6 +96,7 @@ function updateSelectionBox() {
|
|
76 |
});
|
77 |
selectionBox.appendChild(textInput);
|
78 |
|
|
|
79 |
if (selectedItems.length > 0) {
|
80 |
const submitButton = document.createElement('button');
|
81 |
submitButton.textContent = 'Submit to Salesforce';
|
@@ -172,7 +193,7 @@ function fetchItemDetails(itemName) {
|
|
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();
|
176 |
} else {
|
177 |
const details = data.item_details;
|
178 |
selectedItems.push(details);
|
@@ -183,7 +204,7 @@ function fetchItemDetails(itemName) {
|
|
183 |
})
|
184 |
.catch(error => {
|
185 |
addMessage('bot', `Trouble fetching details for "${itemName}": ${error.message}. Add it manually below or I’ll retry...`);
|
186 |
-
updateSelectionBox();
|
187 |
setTimeout(() => fetchItemDetails(itemName), 2000);
|
188 |
});
|
189 |
}
|
|
|
45 |
const selectionBox = document.createElement('div');
|
46 |
selectionBox.className = 'selection-box';
|
47 |
|
48 |
+
// Add dietary preference buttons
|
49 |
+
const vegButton = document.createElement('button');
|
50 |
+
vegButton.textContent = 'Vegetarian';
|
51 |
+
vegButton.className = 'dietary-button green';
|
52 |
+
vegButton.onclick = () => fetchMenuItems('vegetarian');
|
53 |
+
selectionBox.appendChild(vegButton);
|
54 |
+
|
55 |
+
const nonVegButton = document.createElement('button');
|
56 |
+
nonVegButton.textContent = 'Non-Vegetarian';
|
57 |
+
nonVegButton.className = 'dietary-button red';
|
58 |
+
nonVegButton.onclick = () => fetchMenuItems('non-vegetarian');
|
59 |
+
selectionBox.appendChild(nonVegButton);
|
60 |
+
|
61 |
+
const bothButton = document.createElement('button');
|
62 |
+
bothButton.textContent = 'Both';
|
63 |
+
bothButton.className = 'dietary-button gray';
|
64 |
+
bothButton.onclick = () => fetchMenuItems('both');
|
65 |
+
selectionBox.appendChild(bothButton);
|
66 |
+
|
67 |
+
// Add selected items label and list
|
68 |
const label = document.createElement('span');
|
69 |
label.textContent = 'Selected Items:';
|
70 |
selectionBox.appendChild(label);
|
|
|
96 |
});
|
97 |
selectionBox.appendChild(textInput);
|
98 |
|
99 |
+
// Add Submit button if there are selected items
|
100 |
if (selectedItems.length > 0) {
|
101 |
const submitButton = document.createElement('button');
|
102 |
submitButton.textContent = 'Submit to Salesforce';
|
|
|
193 |
.then(data => {
|
194 |
if (data.error) {
|
195 |
addMessage('bot', `Couldn’t find "${itemName}" in Salesforce. Add it manually in the box below!`);
|
196 |
+
updateSelectionBox();
|
197 |
} else {
|
198 |
const details = data.item_details;
|
199 |
selectedItems.push(details);
|
|
|
204 |
})
|
205 |
.catch(error => {
|
206 |
addMessage('bot', `Trouble fetching details for "${itemName}": ${error.message}. Add it manually below or I’ll retry...`);
|
207 |
+
updateSelectionBox();
|
208 |
setTimeout(() => fetchItemDetails(itemName), 2000);
|
209 |
});
|
210 |
}
|