test/static/js/pla/asterisk_plagroups_list.js

145 lines
5.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

function removeClass(id,name_class){
let element = document.getElementById(id);
element.classList.remove(name_class);
}
function addClass(id,name_class){
let element = document.getElementById(id);
element.classList.add(name_class);
}
function show()
{
id = new URLSearchParams(window.location.search).get("id")
let body = {
id : id
}
url = window.location.origin+ '/pla/asterisk/plagroups/list_ajax'
fetch(url,{
headers: {
'Content-Type': 'application/json;charset=utf-8',
'X-CSRFToken': csrftoken,
},
})
.then(response => response.json())
.then(responce => {
length = responce.length-1
for (index = 0; index <= length; ++index) {
console.log('status_'+responce[index].id)
document.getElementById('status_'+responce[index].id).innerHTML = responce[index].message;
if (responce[index].status_color == 0) {
removeClass('td_status_'+responce[index].id,'bg-danger')
addClass('td_status_'+responce[index].id,'bg-success')
} else if (responce[index].status_color == 1) {
removeClass('td_status_'+responce[index].id,'bg-success')
addClass('td_status_'+responce[index].id,'bg-danger')
}
}
/*setByIdHtml('connect_time',responce.connect_time)
removeClass('status','bg-danger')
removeClass('status','bg-success')
setByIdHtml('quality','&nbsp;'+responce.quality[0]+'&nbsp;')
addClass('quality',responce.quality[1])
if (responce.verification_date === '01.01.1' || responce.verification_date === '01.01.0001') {
setByIdHtml('verification_date', 'Не задана')
} else {
setByIdHtml('verification_date',responce.verification_date)
}
syncField(responce.verification_date)
setByIdHtml('status',responce.text_status)
str_table = ''
start = 0
length = data.length-1
myChart.data.labels=[]
myChart.data.datasets[0].data = []
console.log(data)
for (index = 0; index <= length; ++index) {
start = start + 1
myChart.data.labels.push(data[index].date_time);
myChart.data.datasets[0].data.push(data[index].value);
str_table = str_table + '<tr><td>' + data[length-index].date_time + '</td><td>' + data[length-index].value + '</td></tr>'
}
myChart.update();
$("#table_bo").html(str_table)
*/
})
.catch(error=>{
console.log('Ошибка выполнение команды :' + error)
})
}
$(function ()
{
show()
setInterval('show()', 1000);
})
// Функция для получения значения CSRF-токена
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();
// Проверяем, совпадает ли cookie
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
const verificationDateForm = document.querySelector('#verificationDateForm')
if (verificationDateForm !== null) {
verificationDateForm.addEventListener('submit', async (e) => {
e.preventDefault()
const verificationDateInput = document.querySelector('#verificationDateInput')
const verificationResponsible = document.querySelector('#verificationResponsible')
const currentUserId = document.querySelector('#currentUserId')
const sensor_id = new URLSearchParams(window.location.search).get("id");
const alertBody = document.querySelector('#alertBody')
alertBody.innerHTML = ''
const csrftoken = getCookie('csrftoken');
response = await fetch('/api/v2/acs/sensor/verification/', {
method: 'POST',
body: JSON.stringify({
'date': verificationDateInput.value,
'responsible': verificationResponsible.value,
'user_id': currentUserId.value,
'sensor_id': sensor_id
}),
headers: {"X-CSRFToken": csrftoken},
})
if (response.status === 201) {
$('#modalVerification').modal('hide');
}
else {
const response_json = await response.json()
// alertBody.innerHTML = ''
if (response_json['error'].length > 0) {
for (const error of response_json['error']) {
const alert = createDangerAlert(error)
alertBody.appendChild(alert)
}
}
}
})
}