copying, evidovat btn hidden

This commit is contained in:
JiriUhlir
2026-05-28 13:33:22 +02:00
parent 8624352253
commit 17a4d4db1b
3 changed files with 78 additions and 15 deletions
+2 -2
View File
@@ -94,13 +94,13 @@ def index(request: Request, user=Depends(require_user)):
<label class="muted">HTTP</label> <label class="muted">HTTP</label>
<div class="cmd-row"> <div class="cmd-row">
<input readonly value="{http_clone}" id="http-{app_id}"> <input readonly value="{http_clone}" id="http-{app_id}">
<button onclick="copyValue('http-{app_id}')">Kopírovat</button> <button type="button" onclick="return copyText(this)">Kopírovat</button>
</div> </div>
<label class="muted">SSH</label> <label class="muted">SSH</label>
<div class="cmd-row"> <div class="cmd-row">
<input readonly value="{ssh_clone}" id="ssh-{app_id}"> <input readonly value="{ssh_clone}" id="ssh-{app_id}">
<button onclick="copyValue('ssh-{app_id}')">Kopírovat</button> <button type="button" onclick="return copyText(this)">Kopírovat</button>
</div> </div>
</details> </details>
</td> </td>
-4
View File
@@ -45,10 +45,6 @@ def backups_page(request: Request, user=Depends(require_user)):
<input readonly value="{restore_cmd}"> <input readonly value="{restore_cmd}">
<button type="button" class="copy-button" data-copy-value="{restore_cmd}" onclick="copyText(this)">Kopírovat</button> <button type="button" class="copy-button" data-copy-value="{restore_cmd}" onclick="copyText(this)">Kopírovat</button>
</div> </div>
<form method="post" action="/portal/backups/restore-trigger">
<input type="hidden" name="backup_path" value="{backup_path}">
<button type="submit" class="btn-secondary">Evidovat obnovu</button>
</form>
<div class="muted">Obnova je nebezpečná a musí se spustit ručně přes SSH.</div> <div class="muted">Obnova je nebezpečná a musí se spustit ručně přes SSH.</div>
</td> </td>
<td class="actions-cell"> <td class="actions-cell">
+76 -9
View File
@@ -1,17 +1,84 @@
function copyValue(id) { function writeClipboard(value) {
const el = document.getElementById(id); if (navigator.clipboard && window.isSecureContext) {
el.select(); return navigator.clipboard.writeText(value);
el.setSelectionRange(0, 99999);
navigator.clipboard.writeText(el.value);
} }
function copyText(button) { const textarea = document.createElement("textarea");
const value = button.dataset.copyValue || ""; textarea.value = value;
navigator.clipboard.writeText(value); textarea.setAttribute("readonly", "");
textarea.style.position = "fixed";
textarea.style.top = "-1000px";
document.body.appendChild(textarea);
textarea.select();
document.execCommand("copy");
document.body.removeChild(textarea);
return Promise.resolve();
}
function nearestCopyValue(button) {
if (button.dataset.copyValue) {
return button.dataset.copyValue;
}
const scopes = [
button.closest(".copy-row"),
button.closest(".cmd-row"),
button.closest("td"),
button.parentElement,
];
for (const scope of scopes) {
if (!scope) {
continue;
}
const target = scope.querySelector("input, textarea, pre, code");
if (target) {
return "value" in target ? target.value : target.textContent;
}
}
return "";
}
function showCopied(button, ok) {
const label = button.textContent; const label = button.textContent;
button.textContent = "Zkopírováno"; button.textContent = ok ? "Zkopírováno" : "Nelze kopírovat";
window.setTimeout(() => { window.setTimeout(() => {
button.textContent = label; button.textContent = label;
}, 1200); }, 1200);
} }
function copyValue(idOrButton) {
const target = typeof idOrButton === "string" ? document.getElementById(idOrButton) : idOrButton;
if (!target) {
return false;
}
const value = "value" in target ? target.value : nearestCopyValue(target);
if ("select" in target) {
target.select();
target.setSelectionRange(0, target.value.length);
}
writeClipboard(value)
.then(() => {
if (!("value" in target)) {
showCopied(target, true);
}
})
.catch(() => {
if (!("value" in target)) {
showCopied(target, false);
}
});
return false;
}
function copyText(button) {
const value = nearestCopyValue(button);
writeClipboard(value)
.then(() => showCopied(button, true))
.catch(() => showCopied(button, false));
return false;
}