mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-23 22:35:03 +00:00
Add copy button. Fixes #2734
This commit is contained in:
2
public/v1/js/app.js
vendored
2
public/v1/js/app.js
vendored
File diff suppressed because one or more lines are too long
@@ -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.
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user