copying, evidovat btn hidden
This commit is contained in:
+2
-2
@@ -94,13 +94,13 @@ def index(request: Request, user=Depends(require_user)):
|
||||
<label class="muted">HTTP</label>
|
||||
<div class="cmd-row">
|
||||
<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>
|
||||
|
||||
<label class="muted">SSH</label>
|
||||
<div class="cmd-row">
|
||||
<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>
|
||||
</details>
|
||||
</td>
|
||||
|
||||
@@ -45,10 +45,6 @@ def backups_page(request: Request, user=Depends(require_user)):
|
||||
<input readonly value="{restore_cmd}">
|
||||
<button type="button" class="copy-button" data-copy-value="{restore_cmd}" onclick="copyText(this)">Kopírovat</button>
|
||||
</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>
|
||||
</td>
|
||||
<td class="actions-cell">
|
||||
|
||||
+76
-9
@@ -1,17 +1,84 @@
|
||||
function copyValue(id) {
|
||||
const el = document.getElementById(id);
|
||||
el.select();
|
||||
el.setSelectionRange(0, 99999);
|
||||
navigator.clipboard.writeText(el.value);
|
||||
function writeClipboard(value) {
|
||||
if (navigator.clipboard && window.isSecureContext) {
|
||||
return navigator.clipboard.writeText(value);
|
||||
}
|
||||
|
||||
const textarea = document.createElement("textarea");
|
||||
textarea.value = 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 copyText(button) {
|
||||
const value = button.dataset.copyValue || "";
|
||||
navigator.clipboard.writeText(value);
|
||||
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;
|
||||
button.textContent = "Zkopírováno";
|
||||
button.textContent = ok ? "Zkopírováno" : "Nelze kopírovat";
|
||||
window.setTimeout(() => {
|
||||
button.textContent = label;
|
||||
}, 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user