Skip to content

Commit

Permalink
UI: Allow to customize copied to clipboard message
Browse files Browse the repository at this point in the history
This gives better feedback to user.

Fixes #5931
  • Loading branch information
nijel committed May 1, 2021
1 parent a8ac23c commit f4277cb
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 7 deletions.
5 changes: 4 additions & 1 deletion weblate/static/loader-bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,10 @@ $(function () {
/* Copy to clipboard */
var clipboard = new ClipboardJS("[data-clipboard-text]");
clipboard.on("success", function (e) {
addAlert(gettext("Text copied to clipboard."), (kind = "info"));
var text =
e.trigger.getAttribute("data-clipboard-message") ||
gettext("Text copied to clipboard.");
addAlert(text, (kind = "info"));
});
clipboard.on("error", function (e) {
addAlert(gettext("Please press Ctrl+C to copy."), (kind = "danger"));
Expand Down
2 changes: 1 addition & 1 deletion weblate/templates/accounts/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@
<th>{% trans "Your personal API key:" %}</th>
<td>
{{ user.auth_token.key }}
<button type="button" class="btn btn-link btn-xs" data-clipboard-text="{{ user.auth_token.key }}" title="{% trans "Copy to clipboard" %}">{% icon "copy.svg" %}</button>
<button type="button" class="btn btn-link btn-xs" data-clipboard-text="{{ user.auth_token.key }}" data-clipboard-message="{% trans "API key copied to clipboard." %}" title="{% trans "Copy to clipboard" %}">{% icon "copy.svg" %}</button>
<a class="pull-right flip btn btn-primary link-post" href="{% url 'reset-api-key' %}">{% trans "Regenerate API key" %}</a>
</td>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion weblate/templates/manage-access.html
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ <h4 class="panel-title">
<th>{% trans "Your personal API key:" %}</th>
<td>
{{ user.auth_token.key }}
<button type="button" class="btn btn-link btn-xs" data-clipboard-text="{{ user.auth_token.key }}" title="{% trans "Copy to clipboard" %}">{% icon "copy.svg" %}</button>
<button type="button" class="btn btn-link btn-xs" data-clipboard-text="{{ user.auth_token.key }}" data-clipboard-message="{% trans "API key copied to clipboard." %}" title="{% trans "Copy to clipboard" %}">{% icon "copy.svg" %}</button>
</td>
</tr>
</table>
Expand Down
4 changes: 2 additions & 2 deletions weblate/templates/snippets/git-info.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<th>{% trans "Source code repository" %}</th>
<td class="full-cell">
<code class="git-repo ui-corner-all">{{ object.get_repo_url }}</code>
<button type="button" class="btn btn-link btn-xs" data-clipboard-text="{{ object.get_repo_url }}" title="{% trans "Copy to clipboard" %}">{% icon "copy.svg" %}</button>
<button type="button" class="btn btn-link btn-xs" data-clipboard-text="{{ object.get_repo_url }}" data-clipboard-message="{% trans "Repository URL copied to clipboard." %}" title="{% trans "Copy to clipboard" %}">{% icon "copy.svg" %}</button>
</td>
</tr>

Expand Down Expand Up @@ -43,7 +43,7 @@
<th>{% trans "Weblate repository" %}</th>
<td class="full-cell">
<code class="git-repo ui-corner-all">{{ export_url }}</code>
<button type="button" class="btn btn-link btn-xs" data-clipboard-text="{{ export_url }}" title="{% trans "Copy to clipboard" %}">{% icon "copy.svg" %}</button>
<button type="button" class="btn btn-link btn-xs" data-clipboard-text="{{ export_url }}" data-clipboard-message="{% trans "Repository URL copied to clipboard." %}" title="{% trans "Copy to clipboard" %}">{% icon "copy.svg" %}</button>
</td>
</tr>
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion weblate/templates/snippets/ssh-key.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% load icons %}

{% if ssh_key %}
<button type="button" class="btn btn-link btn-xs pull-right flip" data-clipboard-text="{{ ssh_key.key }}" title="{% trans "Copy to clipboard" %}">{% icon "copy.svg" %}</button>
<button type="button" class="btn btn-link btn-xs pull-right flip" data-clipboard-text="{{ ssh_key.key }}" data-clipboard-message="{% trans "Public key copied to clipboard." %}" title="{% trans "Copy to clipboard" %}">{% icon "copy.svg" %}</button>
<p>{% blocktrans %}Weblate uses SSH key to access remote repositories. The corresponding public key is found below, you can use it to grant Weblate access to a repository.{% endblocktrans %}</p>
<div class="list-group-item pre-scrollable">
{{ ssh_key.key|linebreaks }}
Expand Down
2 changes: 1 addition & 1 deletion weblate/templates/translate.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<div class="panel {% if unit.approved %}panel-success{% elif unit.is_source %}panel-warning{% else %}panel-default{% endif %}">

<div class="panel-heading">
<a class="btn btn-link btn-xs pull-right flip" href="{{ site_url }}{{ unit.get_absolute_url }}" data-clipboard-text="{{ site_url }}{{ unit.get_absolute_url }}" title="{% trans "Copy permalink" %}">{% icon "link.svg" %}</a>
<a class="btn btn-link btn-xs pull-right flip" href="{{ site_url }}{{ unit.get_absolute_url }}" data-clipboard-text="{{ site_url }}{{ unit.get_absolute_url }}" data-clipboard-message="{% trans "Permalink copied to clipboard." %}" title="{% trans "Copy permalink" %}">{% icon "link.svg" %}</a>
<h4 class="panel-title">
{% if unit.translation.component.is_glossary %}
{% if "forbidden" in item.all_flags %}
Expand Down

0 comments on commit f4277cb

Please sign in to comment.