2024-05-15 13:27:22 +00:00
|
|
|
|
const createTable = () => {
|
|
|
|
|
const table = document.getElementById("passesTable");
|
|
|
|
|
const tbody = table.querySelector("tbody");
|
|
|
|
|
|
|
|
|
|
// Очищаем таблицу
|
|
|
|
|
tbody.innerHTML = "";
|
|
|
|
|
|
|
|
|
|
passes.forEach((pass) => {
|
|
|
|
|
const row = document.createElement("tr");
|
|
|
|
|
row.setAttribute("onclick", `openPass(${pass.id});`);
|
|
|
|
|
|
|
|
|
|
// Добавляем ячейки с данными
|
|
|
|
|
const id = document.createElement("td");
|
|
|
|
|
id.textContent = pass.id;
|
|
|
|
|
row.appendChild(id);
|
|
|
|
|
const status = document.createElement("td");
|
|
|
|
|
status.textContent = pass.status;
|
|
|
|
|
row.appendChild(status);
|
|
|
|
|
const date = document.createElement("td");
|
|
|
|
|
const rawDate = new Date(pass.date);
|
|
|
|
|
const formattedDate = `${rawDate.getDate().toString().padStart(2, "0")}/${(
|
|
|
|
|
rawDate.getMonth() + 1
|
|
|
|
|
)
|
|
|
|
|
.toString()
|
|
|
|
|
.padStart(2, "0")}/${rawDate.getFullYear()}`;
|
|
|
|
|
date.textContent = formattedDate;
|
|
|
|
|
row.appendChild(date);
|
|
|
|
|
const type = document.createElement("td");
|
2024-06-09 23:53:32 +00:00
|
|
|
|
type.innerHTML = pass.type;
|
2024-05-15 13:27:22 +00:00
|
|
|
|
row.appendChild(type);
|
|
|
|
|
const object = document.createElement("td");
|
2024-06-09 23:53:32 +00:00
|
|
|
|
object.innerHTML = pass.object;
|
2024-05-15 13:27:22 +00:00
|
|
|
|
row.appendChild(object);
|
|
|
|
|
const editdate = document.createElement("td");
|
|
|
|
|
if (pass.editdate) {
|
|
|
|
|
const rawFinalDate = new Date(pass.editdate);
|
|
|
|
|
const formattedfinalDate = `${rawFinalDate
|
|
|
|
|
.getDate()
|
|
|
|
|
.toString()
|
|
|
|
|
.padStart(2, "0")}/${(rawFinalDate.getMonth() + 1)
|
|
|
|
|
.toString()
|
|
|
|
|
.padStart(2, "0")}/${rawFinalDate.getFullYear()}`;
|
|
|
|
|
editdate.textContent = formattedfinalDate;
|
|
|
|
|
} else {
|
|
|
|
|
editdate.textContent = "";
|
|
|
|
|
}
|
|
|
|
|
row.appendChild(editdate);
|
|
|
|
|
const executor = document.createElement("td");
|
2024-06-09 23:53:32 +00:00
|
|
|
|
executor.innerHTML = pass.executor;
|
2024-05-15 13:27:22 +00:00
|
|
|
|
row.appendChild(executor);
|
|
|
|
|
|
|
|
|
|
tbody.appendChild(row);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
document.addEventListener("DOMContentLoaded", function () {
|
|
|
|
|
createTable();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
function getCookie(name) {
|
|
|
|
|
var cookies = document.cookie.split(";");
|
|
|
|
|
for (var i = 0; i < cookies.length; i++) {
|
|
|
|
|
var cookie = cookies[i].trim();
|
|
|
|
|
if (cookie.startsWith(name + "=")) {
|
|
|
|
|
return cookie.substring(name.length + 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function requestUpdate() {
|
|
|
|
|
document.getElementById("passesTable").style.filter = "brightness(0.85)";
|
|
|
|
|
|
|
|
|
|
const formData = new FormData();
|
|
|
|
|
// formData.append("searchText", document.getElementById("table-search").value);
|
|
|
|
|
formData.append(
|
|
|
|
|
"page",
|
|
|
|
|
parseInt(document.getElementById("page-number").textContent)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const requestOptions = {
|
|
|
|
|
method: "POST",
|
|
|
|
|
headers: {
|
|
|
|
|
Authorization: getCookie("token"),
|
|
|
|
|
},
|
|
|
|
|
body: formData,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
fetch(API_SERVER + "/passes/gettso", requestOptions)
|
|
|
|
|
.then((response) => {
|
|
|
|
|
document.getElementById("passesTable").style.filter = "brightness(1)";
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return response.json();
|
|
|
|
|
} else {
|
|
|
|
|
console.error("Ошибка при отправке POST запроса.");
|
|
|
|
|
return "Ошибка при отправке запроса.";
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.then((data) => {
|
|
|
|
|
passes.splice(0, passes.length);
|
|
|
|
|
|
|
|
|
|
passes.push(
|
|
|
|
|
...data.passes.map((item) => ({
|
|
|
|
|
id: item.id,
|
|
|
|
|
status: item.Состояние,
|
|
|
|
|
object: item.Объект,
|
|
|
|
|
fabula: item.Фабула,
|
|
|
|
|
type: item.Вид_неисправности,
|
|
|
|
|
date: item.Дата_подачи,
|
|
|
|
|
editdate: item.Дата_изменения,
|
|
|
|
|
who: item.Кто_подал,
|
|
|
|
|
executor: item.Исполнитель,
|
|
|
|
|
events: item.Мероприятия,
|
|
|
|
|
}))
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
createTable();
|
|
|
|
|
|
|
|
|
|
totalMax = Math.ceil(data.totalCount / 15);
|
|
|
|
|
|
|
|
|
|
if (totalMax === 0) {
|
|
|
|
|
totalMax = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var currentPage = parseInt(pageNumberInput.textContent, 10);
|
|
|
|
|
if (currentPage > totalMax) {
|
|
|
|
|
pageNumberInput.textContent = totalMax;
|
|
|
|
|
requestUpdate();
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
console.error("Ошибка при отправке запроса:", error);
|
|
|
|
|
});
|
|
|
|
|
}
|