Spaces:
Runtime error
Runtime error
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>CSV Upload</title> | |
<!-- Подключение стилей Notyf --> | |
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/notyf/notyf.min.css"> | |
<style> | |
.loader { | |
border: 16px solid #f3f3f3; | |
border-radius: 50%; | |
border-top: 16px solid #4CAF50; /* Зелёный цвет */ | |
width: 120px; | |
height: 120px; | |
-webkit-animation: spin 2s linear infinite; /* Safari */ | |
animation: spin 2s linear infinite; | |
display: none; /* Изначально скрыт */ | |
position: fixed; /* Фиксированное положение */ | |
top: 50%; /* По центру по вертикали */ | |
left: 50%; /* По центру по горизонтали */ | |
transform: translate(-50%, -50%); /* Центрирование */ | |
} | |
/* Safari */ | |
@-webkit-keyframes spin { | |
0% { -webkit-transform: rotate(0deg); } | |
100% { -webkit-transform: rotate(360deg); } | |
} | |
@keyframes spin { | |
0% { transform: rotate(0deg); } | |
100% { transform: rotate(360deg); } | |
} | |
</style> | |
</head> | |
<body> | |
<h1>Upload CSV File</h1> | |
<form id="uploadForm" enctype="multipart/form-data" method="post"> | |
<input type="file" name="file" accept=".csv"> | |
<label> | |
<input type="checkbox" name="verify_phone" value="1"> Verify Phone | |
</label> | |
<label> | |
<input type="checkbox" name="add_curator" value="1"> Add Curator | |
</label> | |
<input type="submit" value="Upload"> | |
</form> | |
<div id="result"></div> | |
<div class="loader"></div> | |
<!-- Подключение скрипта Notyf --> | |
<script src="https://cdn.jsdelivr.net/npm/notyf/notyf.min.js"></script> | |
<script> | |
document.getElementById('uploadForm').addEventListener('submit', function(event) { | |
event.preventDefault(); | |
const form = new FormData(this); | |
const loader = document.querySelector('.loader'); | |
loader.style.display = 'block'; // Показываем спиннер | |
fetch('/upload_csv', { | |
method: 'POST', | |
body: form | |
}) | |
.then(response => response.json()) | |
.then(data => { | |
loader.style.display = 'none'; // Скрываем спиннер после завершения | |
const notyf = new Notyf({ | |
duration: 5000, // Длительность показа уведомления | |
position: { | |
x: 'right', | |
y: 'bottom' | |
}, | |
types: [ | |
{ | |
type: 'success', | |
background: 'green', | |
icon: { | |
className: 'notyf__icon--success', | |
tagName: 'span', | |
text: '' | |
} | |
} | |
] | |
}); | |
notyf.success(data.message); // Показываем уведомление с сообщением от сервера | |
}) | |
.catch(error => { | |
console.error('Error:', error); | |
loader.style.display = 'none'; // Скрываем спиннер в случае ошибки | |
const notyf = new Notyf({ | |
duration: 5000, // Длительность показа уведомления | |
position: { | |
x: 'right', | |
y: 'bottom' | |
}, | |
types: [ | |
{ | |
type: 'error', | |
background: 'red', | |
icon: { | |
className: 'notyf__icon--error', | |
tagName: 'span', | |
text: '' | |
} | |
} | |
] | |
}); | |
notyf.error('An error occurred while uploading the file.'); // Показываем уведомление об ошибке | |
}); | |
}); | |
</script> | |
</body> | |
</html> |