Spaces:
Sleeping
Sleeping
Update templates/index.html
Browse files- templates/index.html +100 -63
templates/index.html
CHANGED
@@ -71,17 +71,6 @@
|
|
71 |
.confirm-button:hover, .switch-button:hover {
|
72 |
background-color: #e65e00;
|
73 |
}
|
74 |
-
.confirmation-details {
|
75 |
-
font-size: 18px;
|
76 |
-
margin-top: 20px;
|
77 |
-
color: green;
|
78 |
-
}
|
79 |
-
.success-message {
|
80 |
-
font-size: 18px;
|
81 |
-
color: green;
|
82 |
-
margin-top: 20px;
|
83 |
-
display: none;
|
84 |
-
}
|
85 |
</style>
|
86 |
</head>
|
87 |
<body>
|
@@ -119,18 +108,17 @@
|
|
119 |
<button class="switch-button" onclick="showRegistrationForm()">Switch to Register</button>
|
120 |
</div>
|
121 |
|
122 |
-
<!-- Confirmation
|
123 |
-
<div id="
|
124 |
-
<
|
125 |
-
<p id="
|
126 |
-
<p id="
|
127 |
-
<p id="
|
128 |
-
<button class="confirm-button" onclick="submitDetails()">Confirm
|
129 |
</div>
|
130 |
|
131 |
-
|
132 |
-
|
133 |
-
<h3>Your details have been submitted successfully!</h3>
|
134 |
</div>
|
135 |
</div>
|
136 |
|
@@ -159,7 +147,7 @@
|
|
159 |
recognition.stop();
|
160 |
if (response.includes("new")) {
|
161 |
showRegistrationForm();
|
162 |
-
|
163 |
} else if (response.includes("existing")) {
|
164 |
showLoginForm();
|
165 |
captureLoginEmail();
|
@@ -173,96 +161,145 @@
|
|
173 |
function showRegistrationForm() {
|
174 |
document.getElementById('registrationForm').style.display = 'block';
|
175 |
document.getElementById('loginForm').style.display = 'none';
|
|
|
|
|
176 |
}
|
177 |
|
178 |
function showLoginForm() {
|
179 |
document.getElementById('loginForm').style.display = 'block';
|
180 |
document.getElementById('registrationForm').style.display = 'none';
|
|
|
|
|
181 |
}
|
182 |
|
183 |
-
|
184 |
-
|
185 |
-
speak("Please provide your name, email, and mobile number.", function () {
|
186 |
recognition.start();
|
187 |
recognition.onresult = function (event) {
|
188 |
-
let
|
189 |
-
let detailsArray = details.split(" ");
|
190 |
-
let nameCaptured = detailsArray[0]; // First word is assumed to be the name
|
191 |
-
let emailCaptured = detailsArray[1]; // Second word assumed to be the email
|
192 |
-
let mobileCaptured = detailsArray[2]; // Third word assumed to be the mobile
|
193 |
-
|
194 |
-
// Automatically fill in the fields
|
195 |
document.getElementById('name').value = nameCaptured;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
196 |
document.getElementById('email').value = emailCaptured;
|
197 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
198 |
|
199 |
-
|
200 |
-
|
201 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
202 |
});
|
203 |
};
|
204 |
});
|
205 |
}
|
206 |
|
207 |
-
|
208 |
-
function confirmRegistrationDetails(nameCaptured, emailCaptured, mobileCaptured) {
|
209 |
recognition.start();
|
210 |
recognition.onresult = function (event) {
|
211 |
let confirmation = event.results[0][0].transcript.trim().toLowerCase();
|
212 |
recognition.stop();
|
213 |
if (confirmation.includes("yes") || confirmation.includes("ok")) {
|
214 |
-
|
|
|
215 |
} else {
|
216 |
-
|
217 |
}
|
218 |
};
|
219 |
}
|
220 |
|
221 |
-
// Show
|
222 |
-
function
|
223 |
-
document.getElementById('
|
224 |
-
document.getElementById('
|
225 |
-
document.getElementById('
|
|
|
|
|
|
|
|
|
226 |
|
227 |
-
|
|
|
|
|
228 |
}
|
229 |
|
230 |
-
//
|
231 |
function submitDetails() {
|
232 |
const name = document.getElementById('name').value;
|
233 |
const email = document.getElementById('email').value;
|
234 |
const phone = document.getElementById('mobile').value;
|
235 |
|
236 |
-
// Send
|
237 |
fetch('/submit', {
|
238 |
method: 'POST',
|
239 |
headers: { 'Content-Type': 'application/json' },
|
240 |
-
body: JSON.stringify({
|
241 |
-
name: name,
|
242 |
-
email: email,
|
243 |
-
phone: phone
|
244 |
-
})
|
245 |
})
|
246 |
.then(response => response.json())
|
247 |
.then(data => {
|
248 |
if (data.success) {
|
249 |
-
|
|
|
|
|
|
|
|
|
250 |
} else {
|
251 |
-
|
|
|
252 |
}
|
253 |
})
|
254 |
.catch(error => {
|
255 |
-
|
256 |
-
|
257 |
});
|
258 |
}
|
259 |
|
260 |
-
// Show the success message after submitting
|
261 |
-
function showSuccessMessage() {
|
262 |
-
document.getElementById('confirmationSection').style.display = 'none';
|
263 |
-
document.getElementById('successMessage').style.display = 'block';
|
264 |
-
}
|
265 |
-
|
266 |
window.onload = function () {
|
267 |
askLoginOrRegister();
|
268 |
};
|
|
|
71 |
.confirm-button:hover, .switch-button:hover {
|
72 |
background-color: #e65e00;
|
73 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
</style>
|
75 |
</head>
|
76 |
<body>
|
|
|
108 |
<button class="switch-button" onclick="showRegistrationForm()">Switch to Register</button>
|
109 |
</div>
|
110 |
|
111 |
+
<!-- Confirmation Details -->
|
112 |
+
<div id="confirmationForm" style="display: none;">
|
113 |
+
<h2>Confirm Your Details</h2>
|
114 |
+
<p><strong>Name:</strong> <span id="confirmName"></span></p>
|
115 |
+
<p><strong>Email:</strong> <span id="confirmEmail"></span></p>
|
116 |
+
<p><strong>Phone:</strong> <span id="confirmPhone"></span></p>
|
117 |
+
<button class="confirm-button" onclick="submitDetails()">Confirm and Submit</button>
|
118 |
</div>
|
119 |
|
120 |
+
<div id="statusMessage" style="display: none;">
|
121 |
+
<h2 id="statusText"></h2>
|
|
|
122 |
</div>
|
123 |
</div>
|
124 |
|
|
|
147 |
recognition.stop();
|
148 |
if (response.includes("new")) {
|
149 |
showRegistrationForm();
|
150 |
+
captureName();
|
151 |
} else if (response.includes("existing")) {
|
152 |
showLoginForm();
|
153 |
captureLoginEmail();
|
|
|
161 |
function showRegistrationForm() {
|
162 |
document.getElementById('registrationForm').style.display = 'block';
|
163 |
document.getElementById('loginForm').style.display = 'none';
|
164 |
+
document.getElementById('confirmationForm').style.display = 'none';
|
165 |
+
document.getElementById('statusMessage').style.display = 'none';
|
166 |
}
|
167 |
|
168 |
function showLoginForm() {
|
169 |
document.getElementById('loginForm').style.display = 'block';
|
170 |
document.getElementById('registrationForm').style.display = 'none';
|
171 |
+
document.getElementById('confirmationForm').style.display = 'none';
|
172 |
+
document.getElementById('statusMessage').style.display = 'none';
|
173 |
}
|
174 |
|
175 |
+
function captureName() {
|
176 |
+
speak("Please say your name.", function () {
|
|
|
177 |
recognition.start();
|
178 |
recognition.onresult = function (event) {
|
179 |
+
let nameCaptured = event.results[0][0].transcript.trim();
|
|
|
|
|
|
|
|
|
|
|
|
|
180 |
document.getElementById('name').value = nameCaptured;
|
181 |
+
recognition.stop();
|
182 |
+
speak("You said " + nameCaptured + ". Is it correct?", function () {
|
183 |
+
confirmName(nameCaptured);
|
184 |
+
});
|
185 |
+
};
|
186 |
+
});
|
187 |
+
}
|
188 |
+
|
189 |
+
function confirmName(nameCaptured) {
|
190 |
+
recognition.start();
|
191 |
+
recognition.onresult = function (event) {
|
192 |
+
let confirmation = event.results[0][0].transcript.trim().toLowerCase();
|
193 |
+
recognition.stop();
|
194 |
+
if (confirmation.includes("yes") || confirmation.includes("ok")) {
|
195 |
+
captureEmail();
|
196 |
+
} else {
|
197 |
+
captureName();
|
198 |
+
}
|
199 |
+
};
|
200 |
+
}
|
201 |
+
|
202 |
+
function captureEmail() {
|
203 |
+
speak("Now, say your email.", function () {
|
204 |
+
recognition.start();
|
205 |
+
recognition.onresult = function (event) {
|
206 |
+
let emailCaptured = event.results[0][0].transcript.trim().replace(/\bat\b/g, '@').replace(/\s+/g, '');
|
207 |
document.getElementById('email').value = emailCaptured;
|
208 |
+
recognition.stop();
|
209 |
+
speak("You said " + emailCaptured + ". Is it correct?", function () {
|
210 |
+
confirmEmail(emailCaptured);
|
211 |
+
});
|
212 |
+
};
|
213 |
+
});
|
214 |
+
}
|
215 |
+
|
216 |
+
function confirmEmail(emailCaptured) {
|
217 |
+
recognition.start();
|
218 |
+
recognition.onresult = function (event) {
|
219 |
+
let confirmation = event.results[0][0].transcript.trim().toLowerCase();
|
220 |
+
recognition.stop();
|
221 |
+
if (confirmation.includes("yes") || confirmation.includes("ok")) {
|
222 |
+
captureMobile();
|
223 |
+
} else {
|
224 |
+
captureEmail();
|
225 |
+
}
|
226 |
+
};
|
227 |
+
}
|
228 |
|
229 |
+
function captureMobile() {
|
230 |
+
speak("Now, say your mobile number.", function () {
|
231 |
+
recognition.start();
|
232 |
+
recognition.onresult = function (event) {
|
233 |
+
let mobileCaptured = event.results[0][0].transcript.trim().replace(/\s+/g, '');
|
234 |
+
document.getElementById('mobile').value = mobileCaptured;
|
235 |
+
recognition.stop();
|
236 |
+
speak("You said " + mobileCaptured + ". Is it correct?", function () {
|
237 |
+
confirmMobile(mobileCaptured);
|
238 |
});
|
239 |
};
|
240 |
});
|
241 |
}
|
242 |
|
243 |
+
function confirmMobile(mobileCaptured) {
|
|
|
244 |
recognition.start();
|
245 |
recognition.onresult = function (event) {
|
246 |
let confirmation = event.results[0][0].transcript.trim().toLowerCase();
|
247 |
recognition.stop();
|
248 |
if (confirmation.includes("yes") || confirmation.includes("ok")) {
|
249 |
+
// Show confirmation page with details
|
250 |
+
confirmDetailsAndShow();
|
251 |
} else {
|
252 |
+
captureMobile();
|
253 |
}
|
254 |
};
|
255 |
}
|
256 |
|
257 |
+
// Show details for confirmation
|
258 |
+
function confirmDetailsAndShow() {
|
259 |
+
const name = document.getElementById('name').value;
|
260 |
+
const email = document.getElementById('email').value;
|
261 |
+
const phone = document.getElementById('mobile').value;
|
262 |
+
|
263 |
+
document.getElementById('confirmName').textContent = name;
|
264 |
+
document.getElementById('confirmEmail').textContent = email;
|
265 |
+
document.getElementById('confirmPhone').textContent = phone;
|
266 |
|
267 |
+
// Show confirmation form and hide registration form
|
268 |
+
document.getElementById('registrationForm').style.display = 'none';
|
269 |
+
document.getElementById('confirmationForm').style.display = 'block';
|
270 |
}
|
271 |
|
272 |
+
// Submit details to the backend (Salesforce)
|
273 |
function submitDetails() {
|
274 |
const name = document.getElementById('name').value;
|
275 |
const email = document.getElementById('email').value;
|
276 |
const phone = document.getElementById('mobile').value;
|
277 |
|
278 |
+
// Send to backend for Salesforce submission
|
279 |
fetch('/submit', {
|
280 |
method: 'POST',
|
281 |
headers: { 'Content-Type': 'application/json' },
|
282 |
+
body: JSON.stringify({ name, email, phone })
|
|
|
|
|
|
|
|
|
283 |
})
|
284 |
.then(response => response.json())
|
285 |
.then(data => {
|
286 |
if (data.success) {
|
287 |
+
document.getElementById('statusText').textContent = 'Your details have been successfully submitted!';
|
288 |
+
document.getElementById('statusMessage').style.display = 'block';
|
289 |
+
setTimeout(() => {
|
290 |
+
window.location.href = '/login'; // Redirect to login page
|
291 |
+
}, 3000);
|
292 |
} else {
|
293 |
+
document.getElementById('statusText').textContent = 'There was an error submitting your details. Please try again.';
|
294 |
+
document.getElementById('statusMessage').style.display = 'block';
|
295 |
}
|
296 |
})
|
297 |
.catch(error => {
|
298 |
+
document.getElementById('statusText').textContent = 'An error occurred. Please try again.';
|
299 |
+
document.getElementById('statusMessage').style.display = 'block';
|
300 |
});
|
301 |
}
|
302 |
|
|
|
|
|
|
|
|
|
|
|
|
|
303 |
window.onload = function () {
|
304 |
askLoginOrRegister();
|
305 |
};
|