Исправлена форма заказа услуги для показа QR-кода вместо создания заявки напрямую
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -417,21 +417,16 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
// Get CSRF token
|
||||
const csrfToken = document.querySelector('[name=csrfmiddlewaretoken]').value;
|
||||
|
||||
// Prepare data for submission
|
||||
// Prepare data for QR code generation
|
||||
const serviceId = document.getElementById('serviceId').value;
|
||||
const clientData = {
|
||||
service_id: serviceId,
|
||||
first_name: formData.get('first_name'),
|
||||
last_name: formData.get('last_name'),
|
||||
email: formData.get('email'),
|
||||
phone: formData.get('phone'),
|
||||
description: formData.get('description'),
|
||||
budget: formData.get('budget'),
|
||||
timeline: formData.get('timeline')
|
||||
client_email: formData.get('email'),
|
||||
client_phone: formData.get('phone'),
|
||||
client_name: formData.get('name')
|
||||
};
|
||||
|
||||
// Submit to server
|
||||
fetch(`/service/request/${serviceId}/`, {
|
||||
// Submit to QR code generation endpoint
|
||||
fetch(`/service/generate_qr_code/${serviceId}/`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@@ -441,24 +436,41 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
// Show success animation
|
||||
if (data.registration_link) {
|
||||
// Hide form and show QR code
|
||||
document.querySelector('.modal-body form').style.display = 'none';
|
||||
document.getElementById('successSection').style.display = 'block';
|
||||
|
||||
// Close modal after delay
|
||||
setTimeout(() => {
|
||||
const modal = bootstrap.Modal.getInstance(document.getElementById('serviceModal'));
|
||||
if (modal) {
|
||||
modal.hide();
|
||||
}
|
||||
// Reset form
|
||||
form.reset();
|
||||
document.querySelector('.modal-body form').style.display = 'block';
|
||||
document.getElementById('successSection').style.display = 'none';
|
||||
}, 3000);
|
||||
|
||||
// Create QR code section
|
||||
const qrSection = document.createElement('div');
|
||||
qrSection.id = 'qrSection';
|
||||
qrSection.className = 'text-center py-4';
|
||||
qrSection.innerHTML = `
|
||||
<h4 class="text-primary mb-3">Завершите заявку в Telegram</h4>
|
||||
<p class="text-muted mb-4">Отсканируйте QR-код или перейдите по ссылке для завершения регистрации заявки</p>
|
||||
<div class="qr-code-container mb-4">
|
||||
<img src="${data.qr_code_url}" alt="QR Code" class="img-fluid" style="max-width: 250px; border: 2px solid #dee2e6; border-radius: 8px;">
|
||||
</div>
|
||||
<div class="d-grid gap-2">
|
||||
<a href="${data.registration_link}" target="_blank" class="btn btn-primary btn-lg">
|
||||
<i class="fab fa-telegram-plane me-2"></i>
|
||||
Открыть в Telegram
|
||||
</a>
|
||||
<button type="button" class="btn btn-outline-secondary" onclick="resetModal()" data-bs-dismiss="modal">
|
||||
Закрыть
|
||||
</button>
|
||||
</div>
|
||||
`;
|
||||
|
||||
document.querySelector('.modal-body').appendChild(qrSection);
|
||||
|
||||
// Hide footer buttons
|
||||
document.querySelector('.modal-footer').style.display = 'none';
|
||||
|
||||
} else if (data.status === 'existing_request') {
|
||||
alert('У вас уже есть активная заявка на данную услугу. Проверьте ваш Telegram.');
|
||||
} else {
|
||||
alert('Ошибка при отправке заявки: ' + (data.message || 'Попробуйте позже'));
|
||||
alert('Ошибка при создании заявки: ' + (data.error || 'Попробуйте позже'));
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
@@ -473,6 +485,33 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Function to reset modal to initial state
|
||||
function resetModal() {
|
||||
const modal = document.getElementById('serviceModal');
|
||||
const form = document.getElementById('serviceRequestForm');
|
||||
const qrSection = document.getElementById('qrSection');
|
||||
|
||||
// Remove QR section if exists
|
||||
if (qrSection) {
|
||||
qrSection.remove();
|
||||
}
|
||||
|
||||
// Show form and hide success section
|
||||
document.querySelector('.modal-body form').style.display = 'block';
|
||||
document.getElementById('successSection').style.display = 'none';
|
||||
|
||||
// Show footer
|
||||
document.querySelector('.modal-footer').style.display = 'flex';
|
||||
|
||||
// Reset form
|
||||
form.reset();
|
||||
}
|
||||
|
||||
// Reset modal when it's closed
|
||||
document.getElementById('serviceModal').addEventListener('hidden.bs.modal', function () {
|
||||
resetModal();
|
||||
});
|
||||
</script>
|
||||
|
||||
<style>
|
||||
|
||||
Reference in New Issue
Block a user