Обновить templates/modal.html
This commit is contained in:
parent
cf669b25a1
commit
7420460e2e
|
@ -27,7 +27,16 @@
|
|||
|
||||
</div>
|
||||
|
||||
|
||||
<div class="border border-gray-200 rounded-md p-5 mt-5">
|
||||
<span id="token" style="display: none;"></span>
|
||||
<h2 class="font-medium text-base mb-2">Ask a question</h2>
|
||||
<textarea id="user-question" rows="3" class="form-control w-full mb-2" placeholder="Enter a question..."></textarea>
|
||||
<button id="send-question" class="btn button w-24 mr-1 mb-2 bg-theme-9 text-white">Send</button>
|
||||
<div class="mt-4">
|
||||
<strong>Answer:</strong>
|
||||
<p id="question-response" class="mt-1 text-gray-700">—</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
@ -188,7 +197,7 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||
</div>
|
||||
`;
|
||||
}).join('');
|
||||
|
||||
document.getElementById("token").textContent = data.token;
|
||||
document.getElementById("client-name").textContent = data.first_name+ ' ' + data.last_name;
|
||||
document.getElementById("client-email").textContent = data.email_addr;
|
||||
document.getElementById("client-phone").textContent = data.phone_num;
|
||||
|
@ -252,15 +261,50 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||
// Закрытие модалки
|
||||
closeModal.addEventListener("click", () => {
|
||||
modal.classList.add("hidden");
|
||||
clearModalFields();
|
||||
});
|
||||
|
||||
// Закрытие по клику вне модалки
|
||||
modal.addEventListener("click", (e) => {
|
||||
|
||||
|
||||
if (e.target === modal) {
|
||||
modal.classList.add("hidden");
|
||||
clearModalFields();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function clearModalFields() {
|
||||
document.getElementById("user-question").value = "";
|
||||
document.getElementById("question-response").textContent = "";
|
||||
}
|
||||
|
||||
document.getElementById("send-question").addEventListener("click", () => {
|
||||
const question = document.getElementById("user-question").value;
|
||||
const clientName = document.getElementById("client-name").textContent;
|
||||
const token = document.getElementById("token").textContent;;
|
||||
|
||||
fetch("/ask_question", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify({
|
||||
question: question,
|
||||
client_name: clientName, // или передай ID клиента, если удобнее
|
||||
token: token
|
||||
})
|
||||
})
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
document.getElementById("question-response").textContent = data.answer || "Нет ответа.";
|
||||
})
|
||||
.catch(err => {
|
||||
document.getElementById("question-response").textContent = "Ошибка при получении ответа.";
|
||||
console.error("Ошибка:", err);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue