FrederickSundeep commited on
Commit
716c06e
·
1 Parent(s): 462f51f

update file 025

Browse files
Files changed (1) hide show
  1. templates/index.html +125 -78
templates/index.html CHANGED
@@ -18,13 +18,25 @@
18
  }
19
  .message {
20
  margin: 10px 0;
 
 
 
21
  }
22
  .message.bot {
 
23
  color: #333;
 
 
24
  }
25
  .message.user {
26
- color: #007bff;
 
27
  text-align: right;
 
 
 
 
 
28
  }
29
  input, select, textarea {
30
  width: 100%;
@@ -34,26 +46,33 @@
34
  border: 1px solid #ccc;
35
  }
36
  button {
37
- margin-top: 10px;
38
- padding: 10px 18px;
39
  background-color: #007bff;
40
  color: white;
41
  border: none;
42
  border-radius: 8px;
43
  cursor: pointer;
44
  }
45
- .button-secondary {
46
- background-color: #6c757d;
 
 
 
 
 
 
 
47
  }
48
  </style>
49
  </head>
50
  <body>
51
 
52
- <div class="chat-box" id="chatBox">
53
- <div class="message bot">👋 Hi! Let's create your HR ticket step-by-step.</div>
54
  </div>
55
 
56
- <form id="chatForm" style="display:none;" action="/generate" method="post">
57
  <input type="hidden" name="name" id="nameField">
58
  <input type="hidden" name="firstName" id="firstNameField">
59
  <input type="hidden" name="lastName" id="lastNameField">
@@ -63,103 +82,131 @@
63
  <input type="hidden" name="date" id="dateField">
64
  </form>
65
 
66
- <script>
67
- const chatBox = document.getElementById("chatBox");
68
- const form = document.getElementById("chatForm");
 
 
 
 
 
 
 
 
 
69
 
 
70
  const questions = [
71
- { label: "What's your first name?", field: "firstName", type: "text" },
72
- { label: "What's your last name?", field: "lastName", type: "text" },
73
- { label: "What's your email address?", field: "email", type: "email" },
74
  { label: "Describe the issue you're facing.", field: "issue", type: "textarea" },
75
  {
76
- label: "Select the priority level of the issue.",
77
  field: "priority",
78
  type: "select",
79
  options: ["High", "Medium", "Low"]
80
  },
81
- { label: "When did this issue occur?", field: "date", type: "date" }
82
  ];
83
 
 
84
  let current = 0;
85
- let responses = {};
86
 
87
- function nextQuestion() {
88
- if (current >= questions.length) {
89
- showConfirmation();
90
- return;
91
- }
92
 
93
- const q = questions[current];
94
- const inputId = "input_" + q.field;
95
- let html = `<div class="message bot">${q.label}</div>`;
 
 
 
 
96
 
97
- if (q.type === "select") {
98
- html += `<select id="${inputId}">`;
99
- q.options.forEach(opt => {
100
- html += `<option value="${opt}">${opt}</option>`;
 
 
 
 
 
 
 
101
  });
102
- html += `</select>`;
103
- } else if (q.type === "textarea") {
104
- html += `<textarea id="${inputId}" rows="4"></textarea>`;
105
  } else {
106
- html += `<input type="${q.type}" id="${inputId}" />`;
 
107
  }
108
 
109
- html += `<button onclick="handleInput('${q.field}', '${inputId}'); return false;">Next</button>`;
110
- chatBox.innerHTML += html;
111
- scrollToBottom();
112
- }
113
-
114
- function handleInput(field, inputId) {
115
- const value = document.getElementById(inputId).value.trim();
116
- if (!value) return;
117
-
118
- responses[field] = value;
119
-
120
- const userReply = `<div class="message user">${value}</div>`;
121
- chatBox.innerHTML += userReply;
122
- current++;
123
- setTimeout(nextQuestion, 500);
124
- }
125
 
126
- function showConfirmation() {
127
- chatBox.innerHTML += `<div class="message bot">✅ Great! Here's a summary of your ticket:</div>`;
128
- for (let key in responses) {
129
- const label = questions.find(q => q.field === key).label;
130
- chatBox.innerHTML += `
131
- <div class="message bot"><strong>${label}</strong><br>${responses[key]}</div>
132
- `;
133
- }
134
 
135
- chatBox.innerHTML += `
136
- <div class="message bot">Shall I go ahead and create the ticket?</div>
137
- <button onclick="submitForm(); return false;">✅ Yes, Create Ticket</button>
138
- <button class="button-secondary" onclick="restart(); return false;">❌ No, Start Over</button>
139
- `;
140
- scrollToBottom();
141
- }
142
 
143
- function submitForm() {
144
- document.getElementById("nameField").value = responses.firstName + " " + responses.lastName;
145
- document.getElementById("firstNameField").value = responses.firstName;
146
- document.getElementById("lastNameField").value = responses.lastName;
147
- document.getElementById("emailField").value = responses.email;
148
- document.getElementById("issueField").value = responses.issue;
149
- document.getElementById("priorityField").value = responses.priority;
150
- document.getElementById("dateField").value = responses.date;
151
- form.submit();
152
  }
153
 
154
- function restart() {
155
- location.reload();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156
  }
157
 
158
- function scrollToBottom() {
159
- chatBox.scrollTop = chatBox.scrollHeight;
 
 
 
 
 
 
160
  }
161
 
162
- window.onload = nextQuestion;
 
 
163
  </script>
164
 
165
  </body>
 
18
  }
19
  .message {
20
  margin: 10px 0;
21
+ padding: 10px 15px;
22
+ border-radius: 20px;
23
+ max-width: 80%;
24
  }
25
  .message.bot {
26
+ background: #e4e6eb;
27
  color: #333;
28
+ text-align: left;
29
+ align-self: flex-start;
30
  }
31
  .message.user {
32
+ background: #007bff;
33
+ color: white;
34
  text-align: right;
35
+ align-self: flex-end;
36
+ margin-left: auto;
37
+ }
38
+ .input-area {
39
+ margin-top: 20px;
40
  }
41
  input, select, textarea {
42
  width: 100%;
 
46
  border: 1px solid #ccc;
47
  }
48
  button {
49
+ margin-top: 15px;
50
+ padding: 12px 20px;
51
  background-color: #007bff;
52
  color: white;
53
  border: none;
54
  border-radius: 8px;
55
  cursor: pointer;
56
  }
57
+ .summary {
58
+ background: #f1f3f5;
59
+ padding: 15px;
60
+ border-radius: 10px;
61
+ margin-top: 20px;
62
+ }
63
+ .chat-container {
64
+ display: flex;
65
+ flex-direction: column;
66
  }
67
  </style>
68
  </head>
69
  <body>
70
 
71
+ <div class="chat-box chat-container" id="chatBox">
72
+ <div class="message bot">Hi! 👋 Let's create your HR ticket. What is your first name?</div>
73
  </div>
74
 
75
+ <form id="chatForm" action="/generate" method="post" style="display: none;">
76
  <input type="hidden" name="name" id="nameField">
77
  <input type="hidden" name="firstName" id="firstNameField">
78
  <input type="hidden" name="lastName" id="lastNameField">
 
82
  <input type="hidden" name="date" id="dateField">
83
  </form>
84
 
85
+ <div class="input-area" id="inputArea"></div>
86
+
87
+ {% if ticket %}
88
+ <div class="chat-box">
89
+ <div class="summary">
90
+ <h3>✅ Your Ticket has been Generated:</h3>
91
+ <pre>{{ ticket }}</pre>
92
+ <a href="/download/{{ session_id }}"><button>Download as PDF</button></a>
93
+ <p><a href="/tickets">📄 View Submitted Tickets</a></p>
94
+ </div>
95
+ </div>
96
+ {% endif %}
97
 
98
+ <script>
99
  const questions = [
100
+ { label: "What is your first name?", field: "firstName", type: "text" },
101
+ { label: "What is your last name?", field: "lastName", type: "text" },
102
+ { label: "What is your email address?", field: "email", type: "email" },
103
  { label: "Describe the issue you're facing.", field: "issue", type: "textarea" },
104
  {
105
+ label: "What is the priority of the issue?",
106
  field: "priority",
107
  type: "select",
108
  options: ["High", "Medium", "Low"]
109
  },
110
+ { label: "What is the date of the issue?", field: "date", type: "date" }
111
  ];
112
 
113
+ const responses = {};
114
  let current = 0;
 
115
 
116
+ const chatBox = document.getElementById("chatBox");
117
+ const inputArea = document.getElementById("inputArea");
118
+ const form = document.getElementById("chatForm");
 
 
119
 
120
+ function addMessage(text, sender = "bot") {
121
+ const message = document.createElement("div");
122
+ message.className = `message ${sender}`;
123
+ message.innerText = text;
124
+ chatBox.appendChild(message);
125
+ chatBox.scrollTop = chatBox.scrollHeight;
126
+ }
127
 
128
+ function showInput(question) {
129
+ inputArea.innerHTML = "";
130
+ let input;
131
+
132
+ if (question.type === "select") {
133
+ input = document.createElement("select");
134
+ question.options.forEach(opt => {
135
+ const option = document.createElement("option");
136
+ option.value = opt;
137
+ option.text = opt;
138
+ input.appendChild(option);
139
  });
140
+ } else if (question.type === "textarea") {
141
+ input = document.createElement("textarea");
142
+ input.rows = 4;
143
  } else {
144
+ input = document.createElement("input");
145
+ input.type = question.type;
146
  }
147
 
148
+ input.id = "userInput";
149
+ inputArea.appendChild(input);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
 
151
+ const button = document.createElement("button");
152
+ button.innerText = "Next";
153
+ button.onclick = () => {
154
+ const value = input.value.trim();
155
+ if (!value) return;
 
 
 
156
 
157
+ responses[question.field] = value;
158
+ addMessage(value, "user");
 
 
 
 
 
159
 
160
+ current++;
161
+ nextQuestion();
162
+ };
163
+ inputArea.appendChild(button);
164
+ input.focus();
 
 
 
 
165
  }
166
 
167
+ function showSummary() {
168
+ addMessage("Thanks! Here's your ticket summary. Is this okay?", "bot");
169
+
170
+ let summary = `
171
+ Name: ${responses.firstName} ${responses.lastName}
172
+ Email: ${responses.email}
173
+ Priority: ${responses.priority}
174
+ Date: ${responses.date}
175
+ Issue: ${responses.issue}
176
+ `.trim();
177
+
178
+ addMessage(summary, "bot");
179
+
180
+ const confirmButton = document.createElement("button");
181
+ confirmButton.innerText = "✅ Confirm and Generate Ticket";
182
+ confirmButton.onclick = () => {
183
+ document.getElementById("nameField").value = responses.firstName + " " + responses.lastName;
184
+ document.getElementById("firstNameField").value = responses.firstName;
185
+ document.getElementById("lastNameField").value = responses.lastName;
186
+ document.getElementById("emailField").value = responses.email;
187
+ document.getElementById("issueField").value = responses.issue;
188
+ document.getElementById("priorityField").value = responses.priority;
189
+ document.getElementById("dateField").value = responses.date;
190
+ form.submit();
191
+ };
192
+
193
+ inputArea.innerHTML = "";
194
+ inputArea.appendChild(confirmButton);
195
  }
196
 
197
+ function nextQuestion() {
198
+ if (current < questions.length) {
199
+ const question = questions[current];
200
+ addMessage(question.label);
201
+ setTimeout(() => showInput(question), 300);
202
+ } else {
203
+ showSummary();
204
+ }
205
  }
206
 
207
+ window.onload = () => {
208
+ nextQuestion();
209
+ };
210
  </script>
211
 
212
  </body>