lokesh341 commited on
Commit
2065ba9
·
verified ·
1 Parent(s): 7548e0f

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +142 -134
templates/index.html CHANGED
@@ -60,8 +60,7 @@
60
  color: gray;
61
  margin-top: 10px;
62
  }
63
- .confirm-button,
64
- .switch-button {
65
  padding: 10px 20px;
66
  background-color: #ff6a00;
67
  color: white;
@@ -70,76 +69,57 @@
70
  cursor: pointer;
71
  margin-top: 10px;
72
  }
73
- .confirm-button:hover,
74
- .switch-button:hover {
75
  background-color: #e65e00;
76
  }
77
-
78
- .form-container {
79
- display: none;
80
- }
81
-
82
- .form-container.active {
83
- display: block;
84
- }
85
-
86
- .confirmation-details {
87
- margin-top: 20px;
88
- font-size: 18px;
89
- color: #333;
90
- }
91
-
92
- .confirmation-details span {
93
- font-weight: bold;
94
- }
95
  </style>
96
  </head>
97
  <body>
98
  <div class="container">
99
  <h1>Welcome to Biryani Hub 🍽</h1>
 
 
100
 
101
  <!-- Registration Form -->
102
- <div class="form-container" id="registrationForm">
103
  <h2>Register</h2>
104
  <label for="name">Your Name</label>
105
- <input type="text" id="name" placeholder="Enter your name" readonly>
106
 
107
  <label for="email">Your Email</label>
108
- <input type="email" id="email" placeholder="Enter your email" readonly>
109
 
110
  <label for="mobile">Your Mobile Number</label>
111
- <input type="text" id="mobile" placeholder="Enter your mobile number" readonly>
112
 
113
- <button class="confirm-button" onclick="confirmRegistration()">Confirm Registration</button>
114
  <button class="switch-button" onclick="showLoginForm()">Switch to Login</button>
115
  </div>
116
 
117
  <!-- Login Form -->
118
- <div class="form-container" id="loginForm">
119
  <h2>Login</h2>
120
  <label for="loginEmail">Your Email</label>
121
- <input type="email" id="loginEmail" placeholder="Listening for email..." readonly>
122
 
123
  <label for="loginMobile">Your Mobile Number</label>
124
- <input type="text" id="loginMobile" placeholder="Listening for mobile number..." readonly>
125
 
126
- <button class="confirm-button" onclick="captureLoginDetails()">Start Voice Input</button>
127
  <button class="switch-button" onclick="showRegistrationForm()">Switch to Register</button>
128
  </div>
129
 
130
  <!-- Confirmation Details -->
131
- <div id="confirmationForm" class="form-container">
132
  <h2>Confirm Your Details</h2>
133
- <div class="confirmation-details">
134
- <p><span>Name:</span> <span id="confirmName"></span></p>
135
- <p><span>Email:</span> <span id="confirmEmail"></span></p>
136
- <p><span>Phone:</span> <span id="confirmPhone"></span></p>
137
- </div>
138
- <button class="confirm-button" onclick="submitRegistration()">Submit</button>
139
  </div>
140
 
141
- <div id="statusMessage" class="status" style="display:none;">
142
- <p id="statusText"></p>
143
  </div>
144
  </div>
145
 
@@ -154,161 +134,189 @@
154
  alert("Speech Recognition API is not supported in this browser.");
155
  }
156
 
157
- // Function to speak a message
158
  function speak(text, callback) {
159
  const speech = new SpeechSynthesisUtterance(text);
160
  speech.onend = callback;
161
  window.speechSynthesis.speak(speech);
162
  }
163
 
164
- // Registration flow confirmation
165
- function confirmRegistration() {
166
- const name = document.getElementById('name').value;
167
- const email = document.getElementById('email').value;
168
- const mobile = document.getElementById('mobile').value;
169
-
170
- if (!name || !email || !mobile) {
171
- alert("Please fill out all fields!");
172
- return;
173
- }
174
-
175
- // Display confirmation details
176
- document.getElementById('confirmName').textContent = name;
177
- document.getElementById('confirmEmail').textContent = email;
178
- document.getElementById('confirmPhone').textContent = mobile;
179
-
180
- // Show confirmation form and hide registration form
181
- document.getElementById('registrationForm').classList.remove('active');
182
- document.getElementById('confirmationForm').classList.add('active');
183
- }
184
-
185
- // Submit registration details to backend
186
- function submitRegistration() {
187
- const name = document.getElementById('name').value;
188
- const email = document.getElementById('email').value;
189
- const mobile = document.getElementById('mobile').value;
190
-
191
- fetch('/submit', {
192
- method: 'POST',
193
- headers: { 'Content-Type': 'application/json' },
194
- body: JSON.stringify({
195
- name: name,
196
- email: email,
197
- phone: mobile
198
- })
199
- })
200
- .then(response => response.json())
201
- .then(data => {
202
- if (data.success) {
203
- showStatusMessage("Registration successful! Redirecting to login...");
204
- setTimeout(() => {
205
  showLoginForm();
206
- document.getElementById('statusMessage').style.display = 'none';
207
- }, 2000);
208
- } else {
209
- showStatusMessage("Error submitting details, please try again.");
210
- }
211
- })
212
- .catch(error => {
213
- showStatusMessage("An error occurred, please try again.");
214
  });
215
  }
216
 
217
- // Show status message after submission
218
- function showStatusMessage(message) {
219
- document.getElementById('statusText').textContent = message;
220
- document.getElementById('statusMessage').style.display = 'block';
 
221
  }
222
 
223
- // Switch to login form
224
  function showLoginForm() {
225
- document.getElementById('loginForm').classList.add('active');
226
- document.getElementById('registrationForm').classList.remove('active');
227
- document.getElementById('confirmationForm').classList.remove('active');
 
228
  }
229
 
230
- // Capture login details (email and mobile)
231
- function captureLoginDetails() {
232
- const loginEmail = document.getElementById('loginEmail');
233
- const loginMobile = document.getElementById('loginMobile');
234
-
235
- speak("Please say your email for login.", function () {
236
  recognition.start();
237
  recognition.onresult = function (event) {
238
- const emailCaptured = event.results[0][0].transcript.trim().replace(/\bat\b/g, '@').replace(/\s+/g, '');
239
- loginEmail.value = emailCaptured;
240
  recognition.stop();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
241
 
 
 
 
 
 
 
 
242
  speak("You said " + emailCaptured + ". Is it correct?", function () {
243
- confirmLoginEmail(emailCaptured);
244
  });
245
  };
246
  });
247
  }
248
 
249
- // Confirm login email and capture mobile number
250
- function confirmLoginEmail(emailCaptured) {
251
  recognition.start();
252
  recognition.onresult = function (event) {
253
  let confirmation = event.results[0][0].transcript.trim().toLowerCase();
254
  recognition.stop();
255
  if (confirmation.includes("yes") || confirmation.includes("ok")) {
256
- captureLoginMobile();
257
  } else {
258
- captureLoginDetails();
259
  }
260
  };
261
  }
262
 
263
- // Capture login mobile number
264
- function captureLoginMobile() {
265
- const loginMobile = document.getElementById('loginMobile');
266
- speak("Now, say your mobile number for login.", function () {
267
  recognition.start();
268
  recognition.onresult = function (event) {
269
- const mobileCaptured = event.results[0][0].transcript.trim().replace(/\s+/g, '');
270
- loginMobile.value = mobileCaptured;
271
  recognition.stop();
272
-
273
  speak("You said " + mobileCaptured + ". Is it correct?", function () {
274
- confirmLoginMobile(mobileCaptured);
275
  });
276
  };
277
  });
278
  }
279
 
280
- // Confirm login mobile number and submit
281
- function confirmLoginMobile(mobileCaptured) {
282
  recognition.start();
283
  recognition.onresult = function (event) {
284
  let confirmation = event.results[0][0].transcript.trim().toLowerCase();
285
  recognition.stop();
286
  if (confirmation.includes("yes") || confirmation.includes("ok")) {
287
- submitLoginDetails();
 
288
  } else {
289
- captureLoginMobile();
290
  }
291
  };
292
  }
293
 
294
- // Simulate login submission
295
- function submitLoginDetails() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
296
  const loginEmail = document.getElementById('loginEmail').value;
297
  const loginMobile = document.getElementById('loginMobile').value;
298
 
299
- if (!loginEmail || !loginMobile) {
300
- alert("Please fill out both fields!");
301
- return;
 
 
 
 
302
  }
303
-
304
- speak("Login successful!");
305
- setTimeout(() => {
306
- window.location.href = "/dashboard"; // Redirect to the dashboard or main page after login
307
- }, 2000);
308
  }
309
 
310
  window.onload = function () {
311
- showLoginForm(); // Show login form by default
312
  };
313
  </script>
314
  </body>
 
60
  color: gray;
61
  margin-top: 10px;
62
  }
63
+ .confirm-button, .switch-button {
 
64
  padding: 10px 20px;
65
  background-color: #ff6a00;
66
  color: white;
 
69
  cursor: pointer;
70
  margin-top: 10px;
71
  }
72
+ .confirm-button:hover, .switch-button:hover {
 
73
  background-color: #e65e00;
74
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  </style>
76
  </head>
77
  <body>
78
  <div class="container">
79
  <h1>Welcome to Biryani Hub 🍽</h1>
80
+ <h2 class="info" id="infoMessage">Listening... 🗣🎙</h2>
81
+ <p class="status" id="status">🔊 Speak Now...</p>
82
 
83
  <!-- Registration Form -->
84
+ <div id="registrationForm">
85
  <h2>Register</h2>
86
  <label for="name">Your Name</label>
87
+ <input type="text" id="name" placeholder="Listening for name..." readonly>
88
 
89
  <label for="email">Your Email</label>
90
+ <input type="text" id="email" placeholder="Listening for email..." readonly>
91
 
92
  <label for="mobile">Your Mobile Number</label>
93
+ <input type="text" id="mobile" placeholder="Listening for mobile number..." readonly>
94
 
95
+ <button class="confirm-button" onclick="startVoiceRecognition()">Restart Voice Input</button>
96
  <button class="switch-button" onclick="showLoginForm()">Switch to Login</button>
97
  </div>
98
 
99
  <!-- Login Form -->
100
+ <div id="loginForm" style="display: none;">
101
  <h2>Login</h2>
102
  <label for="loginEmail">Your Email</label>
103
+ <input type="text" id="loginEmail" placeholder="Your email" required>
104
 
105
  <label for="loginMobile">Your Mobile Number</label>
106
+ <input type="text" id="loginMobile" placeholder="Your mobile number" required>
107
 
108
+ <button class="confirm-button" onclick="submitLogin()">Login</button>
109
  <button class="switch-button" onclick="showRegistrationForm()">Switch to Register</button>
110
  </div>
111
 
112
  <!-- Confirmation Details -->
113
+ <div id="confirmationForm" style="display: none;">
114
  <h2>Confirm Your Details</h2>
115
+ <p><strong>Name:</strong> <span id="confirmName"></span></p>
116
+ <p><strong>Email:</strong> <span id="confirmEmail"></span></p>
117
+ <p><strong>Phone:</strong> <span id="confirmPhone"></span></p>
118
+ <button class="confirm-button" onclick="submitDetails()">Confirm and Submit</button>
 
 
119
  </div>
120
 
121
+ <div id="statusMessage" style="display: none;">
122
+ <h2 id="statusText"></h2>
123
  </div>
124
  </div>
125
 
 
134
  alert("Speech Recognition API is not supported in this browser.");
135
  }
136
 
 
137
  function speak(text, callback) {
138
  const speech = new SpeechSynthesisUtterance(text);
139
  speech.onend = callback;
140
  window.speechSynthesis.speak(speech);
141
  }
142
 
143
+ function askLoginOrRegister() {
144
+ speak("Are you a new customer or an existing customer? Say 'new' to register or 'existing' to login.", function () {
145
+ recognition.start();
146
+ recognition.onresult = function (event) {
147
+ let response = event.results[0][0].transcript.trim().toLowerCase();
148
+ recognition.stop();
149
+ if (response.includes("new")) {
150
+ showRegistrationForm();
151
+ captureName();
152
+ } else if (response.includes("existing")) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
153
  showLoginForm();
154
+ } else {
155
+ speak("I didn't understand. Please say 'new' for registration or 'existing' for login.", askLoginOrRegister);
156
+ }
157
+ };
 
 
 
 
158
  });
159
  }
160
 
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
+ // Handle login submission
304
+ function submitLogin() {
305
  const loginEmail = document.getElementById('loginEmail').value;
306
  const loginMobile = document.getElementById('loginMobile').value;
307
 
308
+ // Here, you can add validation for login based on Salesforce or your database
309
+ // For now, it's just a simple check to show success.
310
+ if (loginEmail && loginMobile) {
311
+ speak("Login successful! Welcome back.");
312
+ window.location.href = '/dashboard'; // Redirect to a dashboard or home page after successful login
313
+ } else {
314
+ speak("Please provide valid login details.");
315
  }
 
 
 
 
 
316
  }
317
 
318
  window.onload = function () {
319
+ askLoginOrRegister();
320
  };
321
  </script>
322
  </body>