Skip to content

Commit 4103c75

Browse files
committed
Fix & improve marking speakers as arrived
* Adjust for switch to POST by pretalx, see: pretalx/pretalx@d038075b5 * Handle CSRF protection * Deal with pretalx's default handling of form submission buttons * Fix typo that broke error handling * Use JS strict mode, just because
1 parent 625a469 commit 4103c75

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/samaware/static/samaware/samaware.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict'
2+
13
document.addEventListener('DOMContentLoaded', () => {
24

35
document.querySelectorAll('.samaware-list-filter input[type="checkbox"]').forEach((checkbox) => {
@@ -7,12 +9,21 @@ document.addEventListener('DOMContentLoaded', () => {
79
})
810

911
document.querySelectorAll('form.samaware-arrived-form').forEach((form) => {
12+
// Save original contents of the buttons, as JS from pretalx itself will modify them upon submission
13+
const buttonContents = new Map()
14+
form.querySelectorAll('.samaware-btn').forEach((button) => {
15+
buttonContents.set(button, button.innerHTML)
16+
})
17+
1018
form.addEventListener('submit', async (ev) => {
1119
ev.preventDefault()
1220

1321
if (await toggleArrived(form)) {
1422
form.querySelectorAll('.samaware-btn').forEach((button) => {
1523
button.classList.toggle('d-none')
24+
// Undo modifications performed by pretalx JS
25+
button.classList.remove('disabled')
26+
button.innerHTML = buttonContents.get(button)
1627
})
1728
}
1829
})
@@ -24,8 +35,11 @@ document.addEventListener('DOMContentLoaded', () => {
2435
async function toggleArrived(form) {
2536

2637
try {
27-
const response = await fetch(form.action)
28-
if (response.staus >= 400) {
38+
const response = await fetch(form.action, {
39+
method: 'POST',
40+
body: new FormData(form)
41+
})
42+
if (response.status >= 400) {
2943
return false
3044
}
3145
return true

src/samaware/templates/samaware/talk_overview.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ <h3>{% translate 'Contact' %}</h3>
191191
<a href="mailto:{{ speaker.email }}">{{ speaker.email }}</a>
192192

193193
<h3>{% translate 'Attendance' %}</h3>
194-
<form action="{% url 'orga:speakers.arrived' event=submission.event.slug code=speaker.code %}" method="GET" class="samaware-arrived-form">
194+
<form action="{% url 'orga:speakers.arrived' event=submission.event.slug code=speaker.code %}" method="POST" class="samaware-arrived-form">
195+
{% csrf_token %}
195196
{% if speaker_profile.has_arrived %}
196197
<button type="submit" class="samaware-btn btn btn-sm btn-info d-none">{% translate 'Mark as arrived' %}</button>
197198
<button type="submit" class="samaware-btn btn btn-sm btn-success">{% blocktranslate %}Mark as <strong>not</strong> arrived{% endblocktranslate %}</button>

0 commit comments

Comments
 (0)