Sprankelprachtig aan/afmeldsysteem

buttonhandlers.js 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Provides handlers for the buttons!
  2. $(setup_handlers);
  3. function setup_handlers()
  4. {
  5. $('.btn-present').on("click", set_present);
  6. $('.btn-absent').on("click", set_absent);
  7. }
  8. // Update all references on the page to this activity:
  9. // 1. The present/absent buttons
  10. // 2. The activity's row-color in any tables
  11. function activity_changed(activity_id, new_state)
  12. {
  13. // Set the present buttons and absent buttons to their appropriate state
  14. }
  15. function set_present(e)
  16. {
  17. var group, person, activity;
  18. group = this.dataset["groupId"];
  19. person = this.dataset["personId"];
  20. activity = this.dataset["activityId"];
  21. $.ajax(`/groups/${group}/activities/${activity}/presence`,
  22. {
  23. method: 'PUT',
  24. data: {person_id: person, attending: true}
  25. }
  26. );
  27. // Set row state to success
  28. $(`tr[data-person-id=${person}][data-activity-id=${activity}]`)
  29. .removeClass('danger warning')
  30. .addClass('success');
  31. // Update present buttons
  32. $(`.btn-present[data-person-id=${person}][data-activity-id=${activity}]`)
  33. .html(check_selected);
  34. $(`.btn-absent[data-person-id=${person}][data-activity-id=${activity}]`)
  35. .html(times_unselected);
  36. }
  37. function set_absent()
  38. {
  39. var group, person, activity;
  40. group = this.dataset["groupId"];
  41. person = this.dataset["personId"];
  42. activity = this.dataset["activityId"];
  43. $.ajax(`/groups/${group}/activities/${activity}/presence`,
  44. {
  45. method: 'PUT',
  46. data: {person_id: person, attending: false}
  47. }
  48. );
  49. // Set row state to danger
  50. $(`tr[data-person-id=${person}][data-activity-id=${activity}]`)
  51. .removeClass('success warning')
  52. .addClass('danger');
  53. // Update present buttons
  54. $(`.btn-present[data-person-id=${person}][data-activity-id=${activity}]`)
  55. .html(check_unselected);
  56. $(`.btn-absent[data-person-id=${person}][data-activity-id=${activity}]`)
  57. .html(times_selected);
  58. }
  59. var check_unselected = '<i class="fa fa-check"></i>';
  60. var check_selected = '<i class="fa fa-check-circle"></i>';
  61. var times_unselected = '<i class="fa fa-times"></i>';
  62. var times_selected = '<i class="fa fa-times-circle"></i>';