Add copy button. Fixes #2734

This commit is contained in:
James Cole
2019-10-14 19:08:08 +02:00
parent 8ee1b08c57
commit d57c5d3a20
2 changed files with 47 additions and 1 deletions

2
public/v1/js/app.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -159,11 +159,21 @@
</div> </div>
<div class="modal-body"> <div class="modal-body">
<p>
<button id="copyButton" @click="copyToken" class="btn btn-default">Copy token</button>
</p>
<p id="copySuccess" style="display:none;" class="text-success">
Copied to clipboard!
</p>
<p id="copyError" style="display:none;" class="text-danger">
Could not copy to clipboard :(
</p>
<p> <p>
Here is your new personal access token. This is the only time it will be shown so don't lose it! Here is your new personal access token. This is the only time it will be shown so don't lose it!
You may now use this token to make API requests. You may now use this token to make API requests.
</p> </p>
<pre><code>{{ accessToken }}</code></pre> <pre><code>{{ accessToken }}</code></pre>
</div> </div>
@@ -212,6 +222,42 @@
}, },
methods: { methods: {
copyToken() {
console.log('in token thing');
if (!navigator.clipboard) {
console.log('in fallback');
this.fallbackCopyTextToClipboard(this.accessToken);
return;
}
navigator.clipboard.writeText(this.accessToken).then(function () {
//console.log('Async: Copying to clipboard was successful!');
$('#copySuccess').show();
}, function (err) {
console.error('Async: Could not copy text: ', err);
$('#copyError').show();
});
},
fallbackCopyTextToClipboard(text) {
let textArea = document.createElement("textarea");
textArea.value = text;
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
try {
var successful = document.execCommand('copy');
var msg = successful ? 'successful' : 'unsuccessful';
successful ? $('#copySuccess').show() : $('#copyError').show();
//console.log('Fallback: Copying text command was ' + msg);
} catch (err) {
console.error('Fallback: Oops, unable to copy', err);
$('#copyError').show();
}
document.body.removeChild(textArea);
},
/** /**
* Prepare the component. * Prepare the component.
*/ */