Skip to content

Commit

Permalink
automatically copy email addresses from button in events if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
yorickvP committed Jul 15, 2019
1 parent 119aa14 commit ce951da
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 40 deletions.
29 changes: 13 additions & 16 deletions kn/subscriptions/media/event_detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,17 @@ function reopen_event () {
}

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);
});
var emails = $('#subscribed > li > a').map(function() {
return $(this).data('email')
}).join(', ');
if (navigator.clipboard && navigator.clipboard.writeText) {
var elem = this;
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);
}
}
6 changes: 3 additions & 3 deletions kn/subscriptions/templates/subscriptions/event_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -159,19 +159,19 @@ <h1>{{ object.humanName }}</h1>
</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

0 comments on commit ce951da

Please sign in to comment.