registration functions. service request resolved
This commit is contained in:
27
smartsoltech/static/assets/css/service_request_modal.css
Normal file
27
smartsoltech/static/assets/css/service_request_modal.css
Normal file
@@ -0,0 +1,27 @@
|
||||
/* Добавляем стили для анимации появления модального окна */
|
||||
#serviceModal {
|
||||
display: none;
|
||||
position: fixed;
|
||||
z-index: 1;
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: rgba(0, 0, 0, 0.4);
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
position: relative;
|
||||
background-color: #fefefe;
|
||||
margin: auto;
|
||||
padding: 20px;
|
||||
border: 1px solid #888;
|
||||
width: 80%;
|
||||
max-width: 600px;
|
||||
transform: scale(0);
|
||||
transition: transform 0.5s ease;
|
||||
}
|
||||
|
||||
.modal.show .modal-content {
|
||||
transform: scale(1);
|
||||
}
|
||||
@@ -13,3 +13,98 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
const generateQrButton = document.getElementById('generateQrButton');
|
||||
|
||||
if (generateQrButton) {
|
||||
generateQrButton.addEventListener('click', function () {
|
||||
const clientEmail = document.getElementById('clientEmail').value;
|
||||
const clientPhone = document.getElementById('clientPhone').value;
|
||||
const clientName = document.getElementById('clientName').value;
|
||||
const description = document.getElementById('description').value;
|
||||
const serviceId = generateQrButton.getAttribute('data-service-id');
|
||||
|
||||
// Проверка заполненности полей
|
||||
if (!clientEmail || !clientPhone || !clientName || !description || !serviceId) {
|
||||
alert('Все поля должны быть заполнены.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Получение CSRF токена из cookies
|
||||
function getCookie(name) {
|
||||
let cookieValue = null;
|
||||
if (document.cookie && document.cookie !== '') {
|
||||
const cookies = document.cookie.split(';');
|
||||
for (let i = 0; i < cookies.length; i++) {
|
||||
const cookie = cookies[i].trim();
|
||||
if (cookie.substring(0, name.length + 1) === (name + '=')) {
|
||||
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return cookieValue;
|
||||
}
|
||||
|
||||
const csrftoken = getCookie('csrftoken');
|
||||
|
||||
// Отправка POST запроса на создание заявки
|
||||
fetch('/service/create_request/', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRFToken': csrftoken
|
||||
},
|
||||
body: JSON.stringify({
|
||||
client_email: clientEmail,
|
||||
client_phone: clientPhone,
|
||||
client_name: clientName,
|
||||
service_id: serviceId,
|
||||
description: description
|
||||
})
|
||||
})
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error('Ошибка при создании заявки');
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
if (data.status === 'success') {
|
||||
alert(data.message);
|
||||
} else if (data.status === 'existing_request') {
|
||||
alert(data.message);
|
||||
} else {
|
||||
alert('Неизвестная ошибка. Пожалуйста, попробуйте снова.');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Ошибка при создании заявки:', error);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function checkVerificationStatus(serviceRequestId, interval) {
|
||||
fetch(`/service/request_status/${serviceRequestId}/`)
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error('Ошибка при проверке статуса заявки');
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
if (data.is_verified) {
|
||||
// Закрываем форму и показываем окно подтверждения
|
||||
document.getElementById('serviceModal').style.display = 'none';
|
||||
document.getElementById('confirmationModal').style.display = 'block';
|
||||
|
||||
// Останавливаем интервал проверки статуса
|
||||
clearInterval(interval);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Ошибка при проверке статуса заявки:', error);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user