142 lines
5.6 KiB
JavaScript
142 lines
5.6 KiB
JavaScript
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/edit_ajax/?id='+id
|
||
fetch(url,{
|
||
headers: {
|
||
'Content-Type': 'application/json;charset=utf-8',
|
||
'X-CSRFToken': csrftoken,
|
||
},
|
||
})
|
||
.then(response => response.json())
|
||
.then(responce => {
|
||
console.log(responce)
|
||
if (responce.status==0 ) {
|
||
document.getElementById('status').value = responce.message;
|
||
if (responce.status_color == 0) {
|
||
removeClass('status','bg-danger')
|
||
addClass('status','bg-success')
|
||
} else if (responce.status_color == 1) {
|
||
removeClass('status','bg-success')
|
||
addClass('status','bg-danger')
|
||
}
|
||
}
|
||
/*setByIdHtml('connect_time',responce.connect_time)
|
||
removeClass('status','bg-danger')
|
||
removeClass('status','bg-success')
|
||
setByIdHtml('quality',' '+responce.quality[0]+' ')
|
||
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)
|
||
}
|
||
}
|
||
}
|
||
})
|
||
}
|
||
|