Sprankelprachtig aan/afmeldsysteem

activities.coffee 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. $(document).on 'turbolinks:load', ->
  2. clipboard = new Clipboard('.copy-reactions', {
  3. 'text': clipreactions
  4. })
  5. $('.subgroup-filter').on('change', (e) -> filterparticipants(e))
  6. @clipreactions = (trigger) ->
  7. id = trigger.dataset['activity']
  8. dopresent = (typeof trigger.dataset['present'] != 'undefined')
  9. doabsent = (typeof trigger.dataset['absent'] != 'undefined')
  10. donoresp = (typeof trigger.dataset['unknown'] != 'undefined')
  11. req = $.ajax({
  12. async: false,
  13. method: 'GET',
  14. url: '/api/activities/' + id + '/response_summary'
  15. })
  16. resp = req.responseJSON.response_summary
  17. res = []
  18. if dopresent
  19. res.push(resp['present']['message'])
  20. if doabsent
  21. res.push(resp['absent']['message'])
  22. if donoresp
  23. res.push(resp['unknown']['message'])
  24. res.join('\n')
  25. @filterparticipants = (e) ->
  26. show = e.target.value
  27. if (show == 'all')
  28. $('.participant-row').show()
  29. @updatecounts()
  30. this.subgroupfilter = null
  31. else if (show == 'withoutgroup')
  32. selector = "tr.participant-row.success:not([data-subgroup-id])"
  33. $('.participant-row').hide()
  34. $(selector).show()
  35. @updatecounts()
  36. this.subgroupfilter = show
  37. else
  38. selector = "[data-subgroup-id=" + e.target.value + "]"
  39. $('.participant-row').hide()
  40. $(selector).show()
  41. @updatecounts(show)
  42. this.subgroupfilter = show
  43. @updatecounts = (subgroupid) ->
  44. selector = 'tr.countable.participant-row'
  45. selectorend = '[style!="display: none;"]'
  46. if (subgroupid)
  47. selectorend = '[data-subgroup-id=' + subgroupid + ']' + selectorend
  48. pselect = selector + '.success' + selectorend
  49. uselect = selector + '.warning' + selectorend
  50. aselect = selector + '.danger' + selectorend
  51. numall = $(selector + selectorend).length
  52. numpresent = $(pselect).length
  53. numunknown = $(uselect).length
  54. numabsent = $(aselect).length
  55. $('.state-count.all-count').html(numall)
  56. $('.state-count.present-count').html(numpresent)
  57. $('.state-count.unknown-count').html(numunknown)
  58. $('.state-count.absent-count').html(numabsent)
  59. [numpresent, numabsent, numunknown]