`,
showCancelButton: true,
confirmButtonColor: "rgb(18, 102, 18)",
cancelButtonColor: "red",
confirmButtonText: "Approve",
cancelButtonText: "Disapprove",
}).then(async (result) => {
if (result.isConfirmed) {
// If the user clicks "Approve," you can perform the approval action here
// For now, let's just show another success message
try {
const options = {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
borrowid: borrowid,
tpyeApporDis: true,
}),
};
const res = await fetch("/appordis", options);
if (res.ok) {
getBorrows();
}
} catch (err) {
alert(err);
}
Swal.fire({
title: "
Approve
",
background: "white",
html: "
The request has been approved.
",
icon: "success",
showCancelButton: false,
confirmButtonColor: "#3085d6",
confirmButtonText: "OK",
});
} else if (result.dismiss === Swal.DismissReason.cancel) {
// If the user clicks "Disapprove," prompt for a reason
Swal.fire({
title: "
Enter Disapproval Reason
",
background: "white",
input: "text",
inputAttributes: {
autocapitalize: "off",
style: "color: black", // Set the text color of the input field
},
customClass: {
input: 'custom-input-class' // Define a custom class for the input
},
showCancelButton: true,
confirmButtonText: "Submit",
cancelButtonText: "Cancel",
showLoaderOnConfirm: true,
preConfirm: (reason) => {
// You can perform actions with the entered reason here
return new Promise((resolve) => {
// Simulate a delay for demonstration purposes
setTimeout(() => {
resolve();
}, 1000);
});
},
allowOutsideClick: () => !Swal.isLoading(),
}).then(async (result) => {
if (result.isConfirmed) {
try {
const options = {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
borrowid: borrowid,
tpyeApporDis: false,
reasons: result.value,
}),
};
const res = await fetch("/appordis", options);
if (res.ok) {
getBorrows();
}
} catch (err) {
alert(err);
}
Swal.fire({
title: '
Disapproved!
',
background: 'white',
html: `
The request has been disapproved.
Reason: ${result.value}
`,
icon: 'error',
showCancelButton: false,
confirmButtonColor: '#3085d6',
confirmButtonText: 'OK',
});
}
});
setStatusproduct(0, productId);
}
});
}
// get products
async function getBorrows() {
try {
const response = await fetch("/borrows");
if (response.ok) {
const data = await response.json();
let rows = "";
data.forEach(function (b) {
if (b.statusborrow == 1) {
rows += `
${b.userid}
`;
rows += `
${b.email}
`;
rows += `
${b.id}
`;
rows += `
`;
rows += `
${b.name}
`;
rows += `
${new Date(b.borrowdate).toLocaleDateString()}
`;
rows += `
${new Date(b.returndate).toLocaleDateString()}
`;
rows += `
`;
rows += `
`;
}
});
tblProduct.innerHTML = rows;
} else {
throw Error("Connection error");
}
} catch (err) {
console.error(err);
alert(err.message);
}
}
// get all products
getBorrows();
async function setStatusproduct(statusproduct, idproductx) {
console.log(statusproduct);
try {
const options = {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
status: statusproduct,
idproduct: idproductx,
}),
};
const response = await fetch("/onoffitem", options);
if (response.ok) {
const data = await response.text();
// alert(data);
} else {
throw Error("Error naja");
}
} catch (error) {
console.error(error.message);
alert(error.message);
}
}
document.getElementById("lechome").addEventListener("click", function (event) {
event.preventDefault(); // Prevent the default link behavior
window.location.href = "/lecturerHomepage";
});
document.getElementById("lecass").addEventListener("click", function (event) {
event.preventDefault(); // Prevent the default link behavior
window.location.href = "/lecAss";
});
document.getElementById("lecre").addEventListener("click", function (event) {
event.preventDefault(); // Prevent the default link behavior
window.location.href = "/lecRe";
});
document.getElementById("lechis").addEventListener("click", function (event) {
event.preventDefault(); // Prevent the default link behavior
window.location.href = "/lecHis";
});
document.getElementById("rolepage").addEventListener("click", function (event) {
event.preventDefault(); // Prevent the default link behavior
window.location.href = "/rolePage";
});