#3: new passes type, user applications page, bug fixes
This commit is contained in:
@ -20,7 +20,7 @@ const createTable = () => {
|
||||
type.textContent = application.type;
|
||||
row.appendChild(type);
|
||||
const worker = document.createElement("td");
|
||||
worker.textContent = application.worker;
|
||||
worker.innerHTML = application.worker;
|
||||
row.appendChild(worker);
|
||||
const legal = document.createElement("td");
|
||||
legal.innerHTML = application.legal;
|
||||
|
141
static/scripts/myapplications-table.js
Normal file
141
static/scripts/myapplications-table.js
Normal file
@ -0,0 +1,141 @@
|
||||
const createTable = () => {
|
||||
const table = document.getElementById("applicationsTable");
|
||||
const tbody = table.querySelector("tbody");
|
||||
|
||||
// Очищаем таблицу
|
||||
tbody.innerHTML = "";
|
||||
|
||||
applications.forEach((application) => {
|
||||
const row = document.createElement("tr");
|
||||
row.setAttribute("onclick", `openApplication(${application.id});`);
|
||||
|
||||
// Добавляем ячейки с данными
|
||||
const id = document.createElement("td");
|
||||
id.textContent = application.id;
|
||||
row.appendChild(id);
|
||||
const status = document.createElement("td");
|
||||
status.textContent = application.status;
|
||||
row.appendChild(status);
|
||||
const type = document.createElement("td");
|
||||
type.textContent = application.type;
|
||||
row.appendChild(type);
|
||||
const worker = document.createElement("td");
|
||||
worker.innerHTML = application.worker;
|
||||
row.appendChild(worker);
|
||||
const legal = document.createElement("td");
|
||||
legal.innerHTML = application.legal;
|
||||
row.appendChild(legal);
|
||||
const date = document.createElement("td");
|
||||
const rawDate = new Date(application.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 finaldate = document.createElement("td");
|
||||
if (application.finaldate) {
|
||||
const rawFinalDate = new Date(application.finaldate);
|
||||
const formattedfinalDate = `${rawFinalDate
|
||||
.getDate()
|
||||
.toString()
|
||||
.padStart(2, "0")}/${(rawFinalDate.getMonth() + 1)
|
||||
.toString()
|
||||
.padStart(2, "0")}/${rawFinalDate.getFullYear()}`;
|
||||
finaldate.textContent = formattedfinalDate;
|
||||
} else {
|
||||
finaldate.textContent = "";
|
||||
}
|
||||
row.appendChild(finaldate);
|
||||
const car = document.createElement("td");
|
||||
if (application.car) {
|
||||
let carText = application.car.replace(/"/g, '"');
|
||||
carText = JSON.parse(carText).join(", ");
|
||||
car.textContent = carText;
|
||||
}
|
||||
row.appendChild(car);
|
||||
|
||||
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("applicationsTable").style.filter =
|
||||
"brightness(0.85)";
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append(
|
||||
"page",
|
||||
parseInt(document.getElementById("page-number").textContent)
|
||||
);
|
||||
|
||||
const requestOptions = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization: getCookie("token"),
|
||||
},
|
||||
body: formData,
|
||||
};
|
||||
|
||||
fetch(API_SERVER + "/forms/getmyapplications", requestOptions)
|
||||
.then((response) => {
|
||||
document.getElementById("applicationsTable").style.filter =
|
||||
"brightness(1)";
|
||||
if (response.ok) {
|
||||
return response.json();
|
||||
} else {
|
||||
console.error("Ошибка при отправке POST запроса.");
|
||||
return "Ошибка при отправке запроса.";
|
||||
}
|
||||
})
|
||||
.then((data) => {
|
||||
applications.splice(0, applications.length);
|
||||
|
||||
applications.push(
|
||||
...data.applications.map((item) => ({
|
||||
id: item.id,
|
||||
status: item.Статус,
|
||||
type: item.Вид_заявки,
|
||||
worker: item.Работник,
|
||||
date: item.Дата_заявки,
|
||||
finaldate: item.Дата_решения,
|
||||
legal: item.Организация,
|
||||
car: 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);
|
||||
});
|
||||
}
|
@ -29,7 +29,7 @@ const createTable = () => {
|
||||
type.textContent = pass.type;
|
||||
row.appendChild(type);
|
||||
const worker = document.createElement("td");
|
||||
worker.textContent = pass.name;
|
||||
worker.innerHTML = pass.name;
|
||||
row.appendChild(worker);
|
||||
const legal = document.createElement("td");
|
||||
legal.innerHTML = pass.legal;
|
||||
|
@ -26,10 +26,10 @@ const createTable = () => {
|
||||
date.textContent = formattedDate;
|
||||
row.appendChild(date);
|
||||
const type = document.createElement("td");
|
||||
type.textContent = pass.type;
|
||||
type.innerHTML = pass.type;
|
||||
row.appendChild(type);
|
||||
const object = document.createElement("td");
|
||||
object.textContent = pass.object;
|
||||
object.innerHTML = pass.object;
|
||||
row.appendChild(object);
|
||||
const editdate = document.createElement("td");
|
||||
if (pass.editdate) {
|
||||
@ -46,7 +46,7 @@ const createTable = () => {
|
||||
}
|
||||
row.appendChild(editdate);
|
||||
const executor = document.createElement("td");
|
||||
executor.textContent = pass.executor;
|
||||
executor.innerHTML = pass.executor;
|
||||
row.appendChild(executor);
|
||||
|
||||
tbody.appendChild(row);
|
||||
|
@ -20,13 +20,13 @@ const createTable = () => {
|
||||
id.textContent = user.id;
|
||||
row.appendChild(id);
|
||||
const surname = document.createElement("td");
|
||||
surname.textContent = user.surname;
|
||||
surname.innerHTML = user.surname;
|
||||
row.appendChild(surname);
|
||||
const name = document.createElement("td");
|
||||
name.textContent = user.name;
|
||||
name.innerHTML = user.name;
|
||||
row.appendChild(name);
|
||||
const secondname = document.createElement("td");
|
||||
secondname.textContent = user.secondname;
|
||||
secondname.innerHTML = user.secondname;
|
||||
row.appendChild(secondname);
|
||||
const role = document.createElement("td");
|
||||
if (user.role) {
|
||||
@ -36,10 +36,10 @@ const createTable = () => {
|
||||
}
|
||||
row.appendChild(role);
|
||||
const phone = document.createElement("td");
|
||||
phone.textContent = user.phone;
|
||||
phone.innerHTML = user.phone;
|
||||
row.appendChild(phone);
|
||||
const email = document.createElement("td");
|
||||
email.textContent = user.email;
|
||||
email.innerHTML = user.email;
|
||||
row.appendChild(email);
|
||||
const sub = document.createElement("td");
|
||||
sub.textContent = user.sub;
|
||||
|
Reference in New Issue
Block a user