Skip to content

Commit 69cd8d7

Browse files
committed
Change event attendance dashboard page to use value set instead of toggle
1 parent 4f04878 commit 69cd8d7

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

apps/events/dashboard/utils.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def event_ajax_handler(event: Event, request):
1717
administrating_user = request.user
1818
attendee_id = request.POST.get("attendee_id")
1919
user_id = request.POST.get("user_id")
20+
value = request.POST.get("value") == "true"
2021

2122
if action == "attended":
2223
attendee = _get_attendee(attendee_id)
@@ -25,15 +26,15 @@ def event_ajax_handler(event: Event, request):
2526
"message": f"Fant ingen påmeldte med oppgitt ID ({attendee_id}).",
2627
"status": 400,
2728
}
28-
return handle_attended(attendee)
29+
return handle_attended(attendee, value)
2930
elif action == "paid":
3031
attendee = _get_attendee(attendee_id)
3132
if not attendee:
3233
return {
3334
"message": f"Fant ingen påmeldte med oppgitt ID ({attendee_id}).",
3435
"status": 400,
3536
}
36-
return handle_paid(attendee)
37+
return handle_paid(attendee, value)
3738
elif action == "add_attendee":
3839
return handle_add_attendee(event, user_id)
3940
elif action == "remove_attendee":
@@ -42,24 +43,24 @@ def event_ajax_handler(event: Event, request):
4243
raise NotImplementedError
4344

4445

45-
def handle_attended(attendee: Attendee):
46+
def handle_attended(attendee: Attendee, value: bool):
4647
"""
4748
Toggle attending-status of an attendee between attending and not attending
4849
"""
49-
attendee.attended = not attendee.attended
50+
attendee.attended = value
5051
attendee.save()
5152

52-
return {"message": "OK", "status": 200}
53+
return _get_event_context(attendee.event.event)
5354

5455

55-
def handle_paid(attendee: Attendee):
56+
def handle_paid(attendee: Attendee, value: bool):
5657
"""
5758
Toggle paid status of an attendee between paid and not paid
5859
"""
59-
attendee.paid = not attendee.paid
60+
attendee.paid = value
6061
attendee.save()
6162

62-
return {"message": "OK", "status": 200}
63+
return _get_event_context(attendee.event.event)
6364

6465

6566
def _get_attendee_data(attendee_qs):

assets/common/utils/dom.js

+17
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,20 @@ export const toggleChecked = (element) => {
4343
}
4444
}
4545
};
46+
47+
export const setChecked = (element, checked) => {
48+
const checkedIcon = 'fa-check-square-o';
49+
const uncheckedIcon = 'fa-square-o';
50+
const allITags = $(element).find('i');
51+
const ilen = allITags.length;
52+
53+
let icon;
54+
for (let m = 0; m < ilen; m += 1) {
55+
icon = allITags[m];
56+
if (checked) {
57+
$(icon).addClass('checked').removeClass(uncheckedIcon).addClass(checkedIcon);
58+
} else {
59+
$(icon).removeClass('checked').removeClass(checkedIcon).addClass(uncheckedIcon);
60+
}
61+
}
62+
}

0 commit comments

Comments
 (0)