Skip to content

Commit

Permalink
add click to copy widget to api field in the account page
Browse files Browse the repository at this point in the history
  • Loading branch information
amdomanska committed Nov 13, 2023
1 parent 225665c commit 8ab8ca1
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion portality/templates/account/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ <h2 class="label">Your API access</h2>
{% if account.has_role("api") %}
<dt>API Key</dt>
<dd>
<code>{{ account.api_key }}</code>
<code id="user-api">{{ account.api_key }}</code>
<span class="form__click-to-copy" id="click-to-copy--api" data-feather="copy" aria-hidden="true"></span><span class="sr-only">Copy value</span>
<span class="tag tag--confirmation" style="display:none" id="copy-confirmation--api">Copied!</span>
</dd>
{% endif %}
</dl>
Expand Down Expand Up @@ -121,6 +123,17 @@ <h2 class="label">Your API access</h2>
$(window).scrollTop($(firstError).offset().top - 100)
}

{% if account.has_role("api") %}
// Copy API key to clipboard
$('#click-to-copy--api').click(function() {
let value_to_copy = $('#user-api').html();
navigator.clipboard.writeText(value_to_copy);
var confirmation = $("#copy-confirmation--api");
confirmation.text("Copied: " + value_to_copy);
confirmation.show().delay(3000).fadeOut();
});
{% endif %}

// If the user is editing their own account, make them confirm when email address is updated
{% if current_user.id == account.id %}
$('form#edit_user').submit(function () {
Expand Down

0 comments on commit 8ab8ca1

Please sign in to comment.