mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-08-10 23:31:21 +02:00
The openEditDialog JS function didn't populate the locked_year input in the edit dialog, and the PHP template didn't pass locked_year as an argument. Any edit to a link (even just changing the name) would clear the locked academic year to NULL. - Pass $linkLockedYear as 5th argument to openEditDialog in the template - Accept and populate edit-locked-year input in the JS handler
104 lines
3.2 KiB
JavaScript
104 lines
3.2 KiB
JavaScript
/**
|
|
* admin-acces.js — Share link + file access management for acces.php.
|
|
*
|
|
* Reads PHP-injected data from <meta> tags:
|
|
* <meta name="acces-base-url" content="...">
|
|
* <meta name="acces-new-link-password" content="...">
|
|
* <meta name="acces-new-link-slug" content="...">
|
|
*/
|
|
(() => {
|
|
var baseUrlMeta = document.querySelector('meta[name="acces-base-url"]');
|
|
var passwordMeta = document.querySelector(
|
|
'meta[name="acces-new-link-password"]',
|
|
);
|
|
var slugMeta = document.querySelector('meta[name="acces-new-link-slug"]');
|
|
|
|
// Show result dialog after redirect (new link created)
|
|
if (passwordMeta && slugMeta && passwordMeta.content && slugMeta.content) {
|
|
document.getElementById("create-result-password").value =
|
|
passwordMeta.content;
|
|
document.getElementById("create-result-url").value =
|
|
`${baseUrlMeta ? baseUrlMeta.content : ""}/partage/${slugMeta.content}`;
|
|
document.getElementById("create-result-dialog").showModal();
|
|
}
|
|
|
|
// Create dialog opener
|
|
var createBtn = document.getElementById("open-create-dialog");
|
|
if (createBtn) {
|
|
createBtn.addEventListener("click", () => {
|
|
document.getElementById("create-dialog").showModal();
|
|
});
|
|
}
|
|
})();
|
|
|
|
function _copyUrl(id) {
|
|
var input = document.getElementById(`url-${id}`);
|
|
navigator.clipboard.writeText(input.value).then(() => {
|
|
var btn = event.target.closest("button");
|
|
if (btn) {
|
|
const orig = btn.getAttribute("title") || "";
|
|
btn.setAttribute("title", "✓ Copié");
|
|
setTimeout(() => {
|
|
btn.setAttribute("title", orig);
|
|
}, 1200);
|
|
}
|
|
});
|
|
}
|
|
|
|
function _copyUrlFrom(el) {
|
|
navigator.clipboard.writeText(el.value).then(() => {
|
|
const btn = el.nextElementSibling;
|
|
if (btn) {
|
|
const orig = btn.textContent;
|
|
btn.textContent = "✓ Copié";
|
|
setTimeout(() => {
|
|
btn.textContent = orig;
|
|
}, 1200);
|
|
}
|
|
});
|
|
}
|
|
|
|
function _copyTextToClipboard(text) {
|
|
navigator.clipboard
|
|
.writeText(text)
|
|
.then(() => {
|
|
const btn = event?.target ? event.target.closest("button") : null;
|
|
if (btn) {
|
|
const orig = btn.getAttribute("title") || "";
|
|
btn.setAttribute("title", "✓ Copié");
|
|
setTimeout(() => {
|
|
btn.setAttribute("title", orig);
|
|
}, 1200);
|
|
}
|
|
})
|
|
.catch(() => {});
|
|
}
|
|
|
|
window.openEditDialog = (id, name, _hasPassword, expiresVal, lockedYear) => {
|
|
document.getElementById("edit-link-id").value = id;
|
|
document.getElementById("edit-name").value = name || "";
|
|
document.getElementById("edit-expires").value = expiresVal || "";
|
|
document.getElementById("edit-locked-year").value = lockedYear || "";
|
|
document.getElementById("edit-dialog").showModal();
|
|
};
|
|
|
|
window.openApproveDialog = (requestId) => {
|
|
document.getElementById("approve-request-id").value = requestId;
|
|
document.getElementById("approve-dialog").showModal();
|
|
};
|
|
|
|
window.openRejectDialog = (requestId) => {
|
|
document.getElementById("reject-request-id").value = requestId;
|
|
document.getElementById("reject-dialog").showModal();
|
|
};
|
|
|
|
window.openArchiveLinkDialog = (id) => {
|
|
document.getElementById("archive-link-id").value = id;
|
|
document.getElementById("archive-link-dialog").showModal();
|
|
};
|
|
|
|
window.openDeleteArchivedLinkDialog = (id) => {
|
|
document.getElementById("delete-archived-link-id").value = id;
|
|
document.getElementById("delete-archived-link-dialog").showModal();
|
|
};
|