Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

automatically copy email addresses from button in events if possible #513

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 14 additions & 17 deletions kn/subscriptions/media/event_detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,18 @@ function reopen_event () {
event_set_opened('true');
}

function copy_emailaddresses_to_clipboard () {
_api({'action': 'get-email-addresses',
'id': event_object_id},
function(d) {
if(d.error) {
alert(d.error);
return;
}
var s = '';
var first = true;
for(var i = 0; i < d.addresses.length; i++) {
if (first) first = false;
else s += ', ';
s += d.addresses[i];
}
prompt("Dit zijn de e-mail adressen", s);
});
function copy_emailaddresses_to_clipboard (elem) {
var emails = [].join.call($('#subscribed > li > a').map(function() {
return $(this).data('email')
}), ', ');
if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(emails).catch(function(rej) {
prompt("Dit zijn de e-mail adressen", emails);
}).then(function() {
$(elem).text("Gekopieerd!");
})
} else {
prompt("Dit zijn de e-mail adressen", emails);
}
return true;
}
8 changes: 4 additions & 4 deletions kn/subscriptions/templates/subscriptions/event_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -154,24 +154,24 @@ <h1>{{ object.humanName }}</h1>
{% endif %}{# has_write_access #}

{% if has_read_access or object.has_public_subscriptions %}
<button onclick="copy_emailaddresses_to_clipboard(); return true;">
<button onclick="return copy_emailaddresses_to_clipboard(this)">
{% trans "Toon e-mail adressen van de ingeschrevenen" %}
</button>
{% if listSubscribed %}
<h2>{% trans "Aanmeldingen" %} ({{ listSubscribed|length }})</h2>
{% include "subscriptions/include_list.html" with list=listSubscribed %}
{% include "subscriptions/include_list.html" with list=listSubscribed listid="subscribed" %}
{% else %}
<p>{% trans "Er zijn (nog) geen aanmeldingen." %}</p>
{% endif %}{# listSubscribed #}

{% if listUnsubscribed %}
<h2>{% trans "Afmeldingen" %} ({{ listUnsubscribed|length }})</h2>
{% include "subscriptions/include_list.html" with list=listUnsubscribed %}
{% include "subscriptions/include_list.html" with list=listUnsubscribed listid="unsubscribed" %}
{% endif %}{# listUnsubscribed #}

{% if listInvited %}
<h2>{% trans "Uitnodigingen" %} ({{ listInvited|length }})</h2>
{% include "subscriptions/include_list.html" with list=listInvited %}
{% include "subscriptions/include_list.html" with list=listInvited listid="invited" %}
{% endif %}{# listInvited #}
{% endif %}{# has_read_access or object.has_public_subscriptions#}
{% endblock %}
3 changes: 2 additions & 1 deletion kn/subscriptions/templates/subscriptions/include_list.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{% load i18n %}
<ul>
<ul id="{{ listid }}">
{% for subscr in list %}
<li><a href="{{ subscr.user.get_absolute_url }}"
data-email="{{ subscr.user.canonical_full_email}}"
>{{ subscr.user.full_name }}</a>
{% if has_read_access %}
{% for mutation in subscr.history reversed %}
Expand Down
21 changes: 1 addition & 20 deletions kn/subscriptions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,30 +131,11 @@ def _api_event_set_opened(request):

return JsonHttpResponse({'success': True})


def _api_get_email_addresses(request):
if 'id' not in request.POST:
return JsonHttpResponse({'error': 'missing arguments'})
event = subscr_Es.event_by_id(request.POST['id'])
if not event:
raise Http404
if (not event.has_public_subscriptions and
not event.has_read_access(request.user)):
raise PermissionDenied
# XXX We can optimize this query
return JsonHttpResponse({
'success': True,
'addresses': [s.user.canonical_full_email
for s in event.listSubscribed]})


@require_POST
@login_required
def api(request):
action = request.POST.get('action')
if action == 'get-email-addresses':
return _api_get_email_addresses(request)
elif action == 'event-set-opened':
if action == 'event-set-opened':
return _api_event_set_opened(request)
else:
return JsonHttpResponse({'error': 'unknown action'})
Expand Down