|
| 1 | +<p id="notice"><%= notice %></p> |
| 2 | + |
| 3 | +<h1>Events</h1> |
| 4 | + |
| 5 | +<%= form_with url: bulk_create_event_registrations_path, method: :post, local: true, id: 'bulk-registration-form' do |form| %> |
| 6 | + <table> |
| 7 | + <thead> |
| 8 | + <tr> |
| 9 | + <th></th> |
| 10 | + <th>Title</th> |
| 11 | + <th>Start Date</th> |
| 12 | + <th>End Date</th> |
| 13 | + <th>Actions</th> |
| 14 | + </tr> |
| 15 | + </thead> |
| 16 | + |
| 17 | + <tbody> |
| 18 | + <% @events.each do |event| %> |
| 19 | + <tr> |
| 20 | + <td style="padding-right: 10px;"> |
| 21 | + <%= check_box_tag "event_ids[]", event.id, false, class: "event-checkbox" %> |
| 22 | + </td> |
| 23 | + <td style="padding-right: 10px;"><%= event.title %></td> |
| 24 | + <td style="padding-right: 10px;"><%= event.start_date.strftime("%B %d, %Y") if event.start_date %></td> |
| 25 | + <td style="padding-right: 10px;"><%= event.end_date.strftime("%B %d, %Y") if event.end_date %></td> |
| 26 | + <td style="padding-right: 10px;"> |
| 27 | + <%= link_to 'Show', event %> | |
| 28 | + <%= link_to 'Edit', edit_event_path(event) %> | |
| 29 | + <%= link_to 'Destroy', event, method: :delete, data: { confirm: 'Are you sure?' } %> |
| 30 | + </td> |
| 31 | + </tr> |
| 32 | + <% end %> |
| 33 | + </tbody> |
| 34 | + </table> |
| 35 | + |
| 36 | + <br> |
| 37 | + |
| 38 | + <div> |
| 39 | + <%= form.submit "Register for Selected Events", class: "btn btn-primary", id: "register-button", disabled: true %> |
| 40 | + <%= link_to 'New Event', new_event_path, class: "btn btn-primary" %> |
| 41 | + </div> |
| 42 | +<% end %> |
| 43 | + |
| 44 | +<script> |
| 45 | + document.addEventListener('DOMContentLoaded', function() { |
| 46 | + const checkboxes = document.querySelectorAll('.event-checkbox'); |
| 47 | + const registerButton = document.getElementById('register-button'); |
| 48 | + |
| 49 | + function updateRegisterButton() { |
| 50 | + const checkedBoxes = document.querySelectorAll('.event-checkbox:checked'); |
| 51 | + registerButton.disabled = checkedBoxes.length === 0; |
| 52 | + } |
| 53 | + |
| 54 | + checkboxes.forEach(checkbox => { |
| 55 | + checkbox.addEventListener('change', updateRegisterButton); |
| 56 | + }); |
| 57 | + |
| 58 | + updateRegisterButton(); |
| 59 | + }); |
| 60 | +</script> |
0 commit comments