Skip to content

Commit

Permalink
Merge pull request #64 from fauxparse/waitlist_limit
Browse files Browse the repository at this point in the history
apply show limits to waitlists
  • Loading branch information
fauxparse committed Oct 14, 2018
2 parents dcbbb9b + e7bf16c commit b97d1f2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
22 changes: 19 additions & 3 deletions app/javascript/controllers/activity_selector_controller.js
Expand Up @@ -109,12 +109,28 @@ export default class extends Controller {
const id = e.target.closest('.activity').getAttribute('data-id')
const activity = this.activities[id]
if (activity && !this.addActivity(activity)) {
const event =
new CustomEvent('activities:limit', { detail: activity, bubbles: true })
this.element.dispatchEvent(event)
this.limitReached(activity)
}
}

checkWaitlistLimit = e => {
const waitlistCount =
this.element.querySelectorAll('.join-waitlist:checked').length

if (this.count + waitlistCount > this.maximum) {
const id = e.target.closest('.activity').getAttribute('data-id')
const activity = this.activities[id]
e.target.checked = false
this.limitReached(activity)
}
}

limitReached(activity) {
const event =
new CustomEvent('activities:limit', { detail: activity, bubbles: true })
this.element.dispatchEvent(event)
}

addActivity(activity) {
if (this.perSlot === 1) {
this.preferences[activity.slot] = []
Expand Down
2 changes: 1 addition & 1 deletion app/views/registrations/_activity.html.haml
Expand Up @@ -21,7 +21,7 @@
.button__text= t('.add')
- unless activity.clash? || activity.compulsory?
%label.activity__waitlist
= check_box_tag "registration[waitlist][]", activity.id, activity.waitlisted?
= check_box_tag "registration[waitlist][]", activity.id, activity.waitlisted?, class: 'join-waitlist', data: { action: 'change->activity-selector#checkWaitlistLimit' }
.button.activity__waitlisted--no
= icon :waitlist, class: 'button__icon'
.button__text= t('.add_to_waitlist')
Expand Down

0 comments on commit b97d1f2

Please sign in to comment.