2023-05-18 23:42:48 +04:00
|
|
|
|
const createBtn = document.getElementById("create-button");
|
|
|
|
|
const tbody = document.getElementById("scrollable-table__tbody");
|
|
|
|
|
const serviceInput = document.getElementById("service-input");
|
|
|
|
|
const coastInput = document.getElementById("coast-input");
|
2023-05-20 04:01:15 +04:00
|
|
|
|
const currentLawyerId = document.getElementById("lawyer-id").dataset.id;
|
2023-05-18 23:42:48 +04:00
|
|
|
|
var contracts = [];
|
|
|
|
|
var dataArray = [];
|
|
|
|
|
var currentLawyer = null;
|
|
|
|
|
|
|
|
|
|
window.addEventListener('load', async () => {
|
|
|
|
|
await $.ajax({
|
2023-05-19 14:53:49 +04:00
|
|
|
|
url: "/contracts/getallbyuser",
|
2023-05-18 23:42:48 +04:00
|
|
|
|
type: "GET",
|
|
|
|
|
contentType: "json"
|
|
|
|
|
}).done((result) => {
|
|
|
|
|
contracts = result;
|
|
|
|
|
});
|
2023-05-20 04:01:15 +04:00
|
|
|
|
console.log(currentLawyerId)
|
2023-05-18 23:42:48 +04:00
|
|
|
|
await $.ajax({
|
2023-05-20 04:01:15 +04:00
|
|
|
|
url: "/lawyers/get?id=${currentLawyerId}",
|
2023-05-18 23:42:48 +04:00
|
|
|
|
type: "GET",
|
|
|
|
|
contentType: "json"
|
|
|
|
|
}).done((result) => {
|
|
|
|
|
currentLawyer = result;
|
|
|
|
|
});
|
2023-05-20 04:01:15 +04:00
|
|
|
|
console.log(currentLawyerId);
|
|
|
|
|
console.log(currentLawyer);
|
|
|
|
|
contracts.forEach((contract) => {
|
|
|
|
|
const { id, service, coast, date } = contract;
|
|
|
|
|
const row = tbody.insertRow();
|
|
|
|
|
row.setAttribute("data-id", id);
|
|
|
|
|
|
|
|
|
|
const cells = [service, coast, formatDate(date)];
|
|
|
|
|
cells.forEach((value) => {
|
|
|
|
|
const cell = row.insertCell();
|
|
|
|
|
cell.textContent = value;
|
|
|
|
|
});
|
|
|
|
|
console.log(currentLawyer);
|
|
|
|
|
if (currentLawyer.ContractViewModels.find(x => parseInt(x.id) === parseInt(contract.id))) {
|
|
|
|
|
row.classList.add("bg-success");
|
|
|
|
|
dataArray.push(contract);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
row.addEventListener('click', () => addAndRemoveFromList(row));
|
|
|
|
|
});
|
2023-05-18 23:42:48 +04:00
|
|
|
|
})
|
|
|
|
|
|
2023-05-19 14:53:49 +04:00
|
|
|
|
createBtn.addEventListener('click', () => {
|
2023-05-18 23:42:48 +04:00
|
|
|
|
var lawyerCasesUpdate = {
|
|
|
|
|
"Id": currentLawyer.id,
|
|
|
|
|
"Service": serviceInput.value,
|
|
|
|
|
"Coast": coastInput.value,
|
|
|
|
|
"Date": currentLawyer.date,
|
2023-05-19 18:12:37 +04:00
|
|
|
|
"ContractViewModels": dataArray,
|
2023-05-18 23:42:48 +04:00
|
|
|
|
"LawyerCases": currentLawyer.lawyerCases,
|
|
|
|
|
}
|
|
|
|
|
$.ajax({
|
2023-05-20 04:01:15 +04:00
|
|
|
|
url: "/lawyers/update",
|
2023-05-18 23:42:48 +04:00
|
|
|
|
type: "POST",
|
|
|
|
|
contentType: "application/json",
|
|
|
|
|
data: JSON.stringify(lawyerCasesUpdate)
|
|
|
|
|
}).done(() => {
|
|
|
|
|
window.location.href = "/Home/Lawyers";
|
|
|
|
|
});
|
2023-05-19 14:53:49 +04:00
|
|
|
|
})
|
2023-05-18 23:42:48 +04:00
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
var index = dataArray.indexOf(contracts.find(x => x.id === id));
|
|
|
|
|
if (index === -1) {
|
|
|
|
|
dataArray.push(contracts.find(x => x.id === id));
|
|
|
|
|
row.classList.add("bg-success");
|
|
|
|
|
} else {
|
|
|
|
|
dataArray.splice(index, 1);
|
|
|
|
|
row.classList.remove("bg-success");
|
|
|
|
|
}
|
|
|
|
|
}
|