services/public/js/app.js
2022-09-13 22:40:21 +03:00

36 lines
1.1 KiB
JavaScript

window.onload = function () {
let dataToday = document.getElementById('data-today');
// Set current date
let today = new Date().toLocaleDateString('en-US', {
// 'weekday': 'long',
'year': 'numeric',
'month': 'long',
'day': 'numeric'
});
dataToday.innerText = today.replace('/', ' ');
let smsruUpdateButton = document.getElementById('button-smsru-update');
smsruUpdateButton.onclick = smsruUpdateMessages;
}
function smsruUpdateMessages() {
let smsProgress = document.getElementById('data-smsru-progress');
fetch('/api/v1.0/smsru_status')
.then(response => response.json())
.then(data => {
if (data.used_today === null) data.used_today = 0;
smsProgress.setAttribute('aria-valuenow', data.used_today);
smsProgress.setAttribute('aria-valuemax', data.total_free);
if (data.used_today > 0) {
smsProgress.setAttribute('style', `width: ${data.total_free / data.used_today}%`);
}
else {
smsProgress.setAttribute('style', `width: 100%`);
}
smsProgress.innerText = `Лимит: ${data.used_today} из ${data.total_free}`;
});
}