2023-05-18 23:42:48 +04:00
|
|
|
|
const createBtn = document.getElementById("create-button");
|
|
|
|
|
const tbody = document.getElementById("scrollable-table__tbody");
|
|
|
|
|
const nameInput = document.getElementById("name-input");
|
|
|
|
|
const currentLawyerId = document.getElementById("lawyer-data").dataset.id;
|
|
|
|
|
var cases = [];
|
|
|
|
|
var dataArray = [];
|
2023-05-19 14:53:49 +04:00
|
|
|
|
var currentLawyer = null;
|
2023-05-18 23:42:48 +04:00
|
|
|
|
|
|
|
|
|
window.addEventListener('load', async () => {
|
|
|
|
|
await $.ajax({
|
2023-05-19 14:53:49 +04:00
|
|
|
|
url: "/lawyer/getallcases",
|
2023-05-18 23:42:48 +04:00
|
|
|
|
type: "GET",
|
|
|
|
|
contentType: "json"
|
|
|
|
|
}).done((result) => {
|
2023-05-19 14:53:49 +04:00
|
|
|
|
cases = result;
|
|
|
|
|
console.log(cases)
|
2023-05-18 23:42:48 +04:00
|
|
|
|
});
|
|
|
|
|
await $.ajax({
|
2023-05-19 18:12:37 +04:00
|
|
|
|
url: `/lawyer/get?id=${currentLawyerId}`,
|
2023-05-18 23:42:48 +04:00
|
|
|
|
type: "GET",
|
|
|
|
|
contentType: "json"
|
|
|
|
|
}).done((result) => {
|
2023-05-19 14:53:49 +04:00
|
|
|
|
currentLawyer = result;
|
|
|
|
|
console.log(currentLawyer)
|
2023-05-18 23:42:48 +04:00
|
|
|
|
});
|
2023-05-19 14:53:49 +04:00
|
|
|
|
groups.forEach((case) => createRowForCasesTable(case));
|
2023-05-18 23:42:48 +04:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
createBtn.addEventListener('click', () => {
|
2023-05-19 14:53:49 +04:00
|
|
|
|
var lawyerCasesUpdate = {
|
|
|
|
|
"Id": currentLawyer.id,
|
|
|
|
|
"Name": currentLawyer.name,
|
|
|
|
|
"Surname": currentLawyer.Surname,
|
|
|
|
|
"Patronymic": currentLawyer.Patronymic,
|
|
|
|
|
"SpecializationId": currentLawyer.SpecializationId,
|
2023-05-19 18:12:37 +04:00
|
|
|
|
"ContractViewModels": currentLawyer.lawyerContracts,
|
2023-05-19 14:53:49 +04:00
|
|
|
|
"LawyerCases": dataArray,
|
2023-05-18 23:42:48 +04:00
|
|
|
|
}
|
|
|
|
|
$.ajax({
|
2023-05-19 14:53:49 +04:00
|
|
|
|
url: "/lawyer/update",
|
2023-05-18 23:42:48 +04:00
|
|
|
|
type: "POST",
|
|
|
|
|
contentType: "application/json",
|
2023-05-19 14:53:49 +04:00
|
|
|
|
data: JSON.stringify(lawyerCasesUpdate)
|
2023-05-18 23:42:48 +04:00
|
|
|
|
}).done(() => {
|
2023-05-19 14:53:49 +04:00
|
|
|
|
window.location.href = "/Home/Lawyers";
|
2023-05-18 23:42:48 +04:00
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
|
2023-05-19 14:53:49 +04:00
|
|
|
|
const createRowForCasesTable = (case) => {
|
|
|
|
|
const { id, name, applicant, defendant, annotation, date, specializationId } = case;
|
2023-05-18 23:42:48 +04:00
|
|
|
|
const row = tbody.insertRow();
|
|
|
|
|
row.setAttribute("data-id", id);
|
|
|
|
|
|
|
|
|
|
const cells = [name];
|
|
|
|
|
cells.forEach((value) => {
|
|
|
|
|
const cell = row.insertCell();
|
|
|
|
|
cell.textContent = value;
|
|
|
|
|
});
|
2023-05-19 14:53:49 +04:00
|
|
|
|
console.log(currentLawyer)
|
|
|
|
|
if (currentLawyer.lawyerCases?.find(x => parseInt(x.id) === parseInt(case.id))) {
|
2023-05-18 23:42:48 +04:00
|
|
|
|
row.classList.add("bg-success");
|
2023-05-19 14:53:49 +04:00
|
|
|
|
dataArray.push(case);
|
2023-05-18 23:42:48 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
row.addEventListener('click', () => addAndRemoveFromList(row));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const formatDate = (dateString) => {
|
|
|
|
|
const date = new Date(dateString);
|
|
|
|
|
const year = date.getFullYear();
|
|
|
|
|
const month = ('0' + (date.getMonth() + 1)).slice(-2);
|
|
|
|
|
const day = ('0' + date.getDate()).slice(-2);
|
|
|
|
|
return `${year}-${month}-${day}`;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const addAndRemoveFromList = (row) => {
|
|
|
|
|
var id = parseInt(row.dataset.id);
|
2023-05-19 14:53:49 +04:00
|
|
|
|
var index = dataArray.indexOf(cases.find(x => x.id === id));
|
2023-05-18 23:42:48 +04:00
|
|
|
|
if (index === -1) {
|
2023-05-19 14:53:49 +04:00
|
|
|
|
dataArray.push(cases.find(x => x.id === id));
|
2023-05-18 23:42:48 +04:00
|
|
|
|
row.classList.add("bg-success");
|
|
|
|
|
} else {
|
|
|
|
|
dataArray.splice(index, 1);
|
|
|
|
|
row.classList.remove("bg-success");
|
|
|
|
|
}
|
|
|
|
|
}
|