Spaces:
Sleeping
Sleeping
< | |
<html lang="ru"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>WhatsMasterGRM - Принудительное обновление базы</title> | |
<link rel="stylesheet" href="styles.css"> | |
<script src="https://cdn.jsdelivr.net/npm/notyf/notyf.min.js"></script> | |
</head> | |
<body> | |
<h1>WhatsMasterGRM - Принудительное обновление базы</h1> | |
<div class="container"> | |
<div class="block"> | |
<h2>Тильда - Таблица CSV</h2> | |
<form id="uploadForm" enctype="multipart/form-data" method="post"> | |
<div class="input-row"> | |
<input type="file" name="file" accept=".csv"> | |
</div> | |
<div class="input-row"> | |
<label class="container-checkbox"> | |
Наличие WhatsApp | |
<input type="checkbox" name="verify_phone" value="1"> | |
<span class="checkmark"></span> | |
</label> | |
<label class="container-checkbox"> | |
Добавлять менеджера | |
<input type="checkbox" name="add_curator" value="1"> | |
<span class="checkmark"></span> | |
</label> | |
</div> | |
<input id="uploadButton" type="submit" value="Загрузить пользователей"> | |
</form> | |
<div id="result"></div> | |
<h2>WhatsMasterCRM - Файл JSON</h2> | |
<form id="uploadFormJson" onsubmit="handleFormSubmit(event)" enctype="multipart/form-data"> | |
<div class="input-row"> | |
<input type="file" id="fileJson" name="file" accept=".json" required> | |
</div> | |
<input id="uploadButtonJson" type="submit" value="Upload"> | |
</form> | |
<div id="message" style="display:none; margin-top:20px;"></div> | |
</div> | |
<div class="block"> | |
<h2>Бизон 365 - API</h2> | |
<div class="form-group"> | |
<label for="tokenInput">API-токен администратора Бизон 365:</label> | |
<input type="text" id="tokenInput" placeholder="Введите токен"> | |
</div> | |
<div class="form-group"> | |
<label for="dateInput">Крайняя дата выборки комнат:</label> | |
<input type="date" id="dateInput"> | |
</div> | |
<div class="form-group"> | |
<label for="typeSelect">Выбор формата вебинара:</label> | |
<select id="typeSelect"> | |
<option value="AutoWebinars">Автовебинарные комнаты</option> | |
<option value="LiveWebinars">Вебинарные комнаты</option> | |
</select> | |
</div> | |
<button id="sendRequestButton">Получить список комнат Бизон 365</button> | |
<div id="dropdown-container"></div> | |
<button id="sendGetRequestButton">Обновить базу WhatsMasterGRM</button> | |
</div> | |
</div> | |
<script> | |
document.getElementById('uploadForm').addEventListener('submit', function(event) { | |
event.preventDefault(); | |
const form = new FormData(this); | |
fetch('/upload_csv', { | |
method: 'POST', | |
body: form | |
}) | |
.then(response => response.json()) | |
.then(data => { | |
showNotification('Загрузка завершена'); | |
}) | |
.catch(error => { | |
console.error('Error:', error); | |
showNotification('Произошла ошибка при загрузке файла.', true); | |
}); | |
}); | |
document.getElementById('uploadFormJson').addEventListener('submit', function(event) { | |
event.preventDefault(); | |
var formData = new FormData(event.target); | |
fetch('/upload_json', { | |
method: 'POST', | |
body: formData | |
}) | |
.then(response => response.json()) | |
.then(data => { | |
showNotification(data.message || 'Файл успешно загружен'); | |
}) | |
.catch(error => { | |
showNotification("Произошла ошибка: " + error, true); | |
}); | |
}); | |
document.getElementById('sendRequestButton').addEventListener('click', function() { | |
const token = document.getElementById('tokenInput').value; | |
const minDate = document.getElementById('dateInput').value; | |
const type = document.getElementById('typeSelect').value; | |
const url = '/send_request'; | |
fetch(url, { | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/x-www-form-urlencoded' | |
}, | |
body: 'token=' + encodeURIComponent(token) + '&minDate=' + encodeURIComponent(minDate) + '&type=' + encodeURIComponent(type) | |
}) | |
.then(response => response.json()) | |
.then(data => { | |
createDropdown(data); | |
showNotification('Список комнат успешно получен'); | |
}) | |
.catch(error => { | |
console.error('Error:', error); | |
showNotification('Произошла ошибка при получении списка комнат.', true); | |
}); | |
}); | |
function createDropdown(data) { | |
const container = document.getElementById('dropdown-container'); | |
container.innerHTML = ''; | |
const select = document.createElement('select'); | |
select.id = 'dropdown'; | |
select.classList.add('form-group'); | |
data.forEach(item => { | |
const option = document.createElement('option'); | |
option.value = item; | |
option.text = item; | |
select.appendChild(option); | |
}); | |
container.appendChild(select); | |
const sendGetRequestButton = document.getElementById('sendGetRequestButton'); | |
sendGetRequestButton.removeEventListener('click', handleGetRequest); | |
sendGetRequestButton.addEventListener('click', handleGetRequest); | |
} | |
function handleGetRequest() { | |
const selectedValue = document.getElementById('dropdown').value; | |
const token = document.getElementById('tokenInput').value; | |
const getUrl = '/send_get_request?token=' + encodeURIComponent(token) + '&webinarId=' + encodeURIComponent(selectedValue); | |
fetch(getUrl, { | |
method: 'GET' | |
}) | |
.then(response => response.json()) | |
.then(data => { | |
showNotification('Пользователи добавлены в базу данных WhatsGRM'); | |
}) | |
.catch(error => { | |
console.error('Error:', error); | |
showNotification('Произошла ошибка при обновлении базы.', true); | |
}); | |
} | |
function showNotification(message, isError = false) { | |
const notyf = new Notyf({ | |
duration: 5000, | |
position: { | |
x: 'right', | |
y: 'top', | |
}, | |
types: [ | |
{ | |
type: 'success', | |
background: 'green', | |
icon: { | |
className: 'notyf__icon--success', | |
tagName: 'span', | |
text: '' | |
} | |
}, | |
{ | |
type: 'error', | |
background: 'red', | |
icon: { | |
className: 'notyf__icon--error', | |
tagName: 'span', | |
text: '' | |
} | |
} | |
] | |
}); | |
if (isError) { | |
notyf.open({ | |
type: 'error', | |
message: message | |
}); | |
} else { | |
notyf.open({ | |
type: 'success', | |
message: message | |
}); | |
} | |
} | |
</script> | |
</body> | |
</html> | |