ui fix
This commit is contained in:
parent
19c3f87c06
commit
7366d07e49
@ -502,7 +502,7 @@
|
||||
<div class="info-label">{% trans "Generated Password" %}</div>
|
||||
<div class="password-container">
|
||||
<div class="password-value" id="password-value">{{ generated_password }}</div>
|
||||
<button type="button" class="btn btn-sm btn-outline-secondary ms-2" onclick="copyPassword()">
|
||||
<button type="button" class="btn btn-sm btn-outline-secondary ms-2" onclick="copyPassword(this)">
|
||||
<i class="fas fa-copy me-1"></i>
|
||||
{% trans "Copy" %}
|
||||
</button>
|
||||
@ -711,25 +711,46 @@
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function copyPassword() {
|
||||
const passwordText = document.getElementById('password-value').textContent;
|
||||
navigator.clipboard.writeText(passwordText).then(function() {
|
||||
// Show success feedback
|
||||
const button = event.target;
|
||||
const originalText = button.innerHTML;
|
||||
button.innerHTML = '<i class="fas fa-check me-1"></i> {% trans "Copied!" %}';
|
||||
button.classList.remove('btn-outline-secondary');
|
||||
button.classList.add('btn-success');
|
||||
|
||||
// Reset after 2 seconds
|
||||
function copyPassword(button) {
|
||||
const passwordTextEl = document.getElementById('password-value');
|
||||
if (!passwordTextEl) return;
|
||||
const passwordText = passwordTextEl.textContent;
|
||||
|
||||
// Try Clipboard API first
|
||||
const doFeedback = (btn) => {
|
||||
const originalHTML = btn.innerHTML;
|
||||
btn.innerHTML = '<i class="fas fa-check me-1"></i> {% trans "Copied!" %}';
|
||||
btn.classList.remove('btn-outline-secondary');
|
||||
btn.classList.add('btn-success');
|
||||
setTimeout(function() {
|
||||
button.innerHTML = originalText;
|
||||
button.classList.remove('btn-success');
|
||||
button.classList.add('btn-outline-secondary');
|
||||
btn.innerHTML = originalHTML;
|
||||
btn.classList.remove('btn-success');
|
||||
btn.classList.add('btn-outline-secondary');
|
||||
}, 2000);
|
||||
}).catch(function(err) {
|
||||
console.error('Failed to copy password: ', err);
|
||||
});
|
||||
};
|
||||
|
||||
if (navigator.clipboard && navigator.clipboard.writeText) {
|
||||
navigator.clipboard.writeText(passwordText).then(function() {
|
||||
doFeedback(button);
|
||||
}).catch(function(err) {
|
||||
console.error('Failed to copy password via Clipboard API: ', err);
|
||||
// fallback
|
||||
const ta = document.createElement('textarea');
|
||||
ta.value = passwordText;
|
||||
document.body.appendChild(ta);
|
||||
ta.select();
|
||||
try { document.execCommand('copy'); doFeedback(button); } catch (e) { console.error('execCommand fallback failed', e); }
|
||||
document.body.removeChild(ta);
|
||||
});
|
||||
} else {
|
||||
// fallback for older browsers
|
||||
const ta = document.createElement('textarea');
|
||||
ta.value = passwordText;
|
||||
document.body.appendChild(ta);
|
||||
ta.select();
|
||||
try { document.execCommand('copy'); doFeedback(button); } catch (e) { console.error('execCommand fallback failed', e); }
|
||||
document.body.removeChild(ta);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user