Add email notifications for events registrations, add switch-checkboxes, create EventsRegistrations controller, separate page for events that require registration

This commit is contained in:
Stella Rouzi 2016-06-06 12:31:57 +03:00
parent 139a8565e2
commit 77af75f319
38 changed files with 1313 additions and 403 deletions

View file

@ -30,7 +30,13 @@ module Admin
:send_on_conference_registration_dates_updated, :conference_registration_dates_updated_subject, :conference_registration_dates_updated_body,
:send_on_venue_updated, :venue_updated_subject, :venue_updated_body,
:send_on_cfp_dates_updated, :cfp_dates_updated_subject, :cfp_dates_updated_body,
:send_on_program_schedule_public, :program_schedule_public_subject, :program_schedule_public_body)
:send_on_program_schedule_public, :program_schedule_public_subject, :program_schedule_public_body,
:send_on_updated_max_attendees_automatically,
:updated_max_attendees_automatically_subject, :updated_max_attendees_automatically_body,
:send_on_deleted_event_registration_automatically, :deleted_event_registration_automatically_subject,
:deleted_event_registration_automatically_body,
:send_on_new_event_registration,
:new_event_registration_subject, :new_event_registration_body)
end
end
end

View file

@ -171,16 +171,6 @@ module Admin
@event_registrations = @event.events_registrations
end
def toggle_attendance
@events_registration.attended = !@events_registration.attended
if @events_registration.save
head :ok
else
head :unprocessable_entity
end
end
private
def event_params

View file

@ -0,0 +1,72 @@
module Admin
class EventsRegistrationsController < Admin::BaseController
load_resource :conference, find_by: :short_title
load_resource :program, through: :conference, singleton: true
load_resource :event
load_resource :registration, through: :conference
before_action :load_events_registration
authorize_resource only: :toggle_attendance
after_action :prepare_unobtrusive_flash, only: [:toggle, :toggle_attendance]
def show
authorize! :update, @event
end
def toggle_attendance
@events_registration = EventsRegistration.find_by(event_id: @event.id, registration_id: @registration.id)
@events_registration.attended = !@events_registration.attended
if @events_registration.attended
if @events_registration.save
flash[:notice] = "You have marked #{@registration.email} as attended."
else
flash[:error] = "Failed to mark #{@registration.email} as attended."
end
elsif @events_registration.save
flash[:notice] = "You have marked #{@registration.email} as NOT attended."
else
flash[:error] = "Failed to mark #{@registration.email} as NOT attended."
end
respond_to do |format|
format.js
end
end
def toggle
authorize! :toggle, @events_registration
if params[:state] == 'false'
# Destroy the registration to the event
if @events_registration.destroy
flash[:notice] = "You successfully unregistered #{@registration.email} from '#{@event.title}'"
else
flash[:error] = "Failed to unregister #{@registration.email} from '#{@event.title}'. Please try again."
end
elsif params[:state] == 'true'
# Create the registration to the event
if @events_registration.save
flash[:notice] = "You successfully registered #{@registration.email} to '#{@event.title}'"
else
flash[:error] = "Failed to register #{@registration.email} to '#{@event.title}'. Please try again."
end
else
flash[:error] = 'Something went wrong. Please take action again.'
end
respond_to do |format|
format.js
end
end
private
def events_registrations_params
params.require(:events_registrations).permit(:event_id, :registration_id)
end
def load_events_registration
@events_registration = EventsRegistration.find_or_initialize_by(event: @event, registration: @registration)
end
end
end

View file

@ -59,6 +59,21 @@ module Admin
start_time = DateTime.strptime(time, '%Y-%m-%d %k:%M')
event.start_time = start_time
event.save!
if event.require_registration && (event.registrations.length > room.size)
event_registrations = event.events_registrations.order(created_at: :desc).limit(event.registrations.length - room.size)
event_registrations.each do |er|
er.destroy!
DeletedEventRegistrationAutomaticallyJob.perform_later(event.program.conference, er.user, er.event) if er.send_email_on_deleted_event_registration_automatically?
end
event.max_attendees = room.size
event.save!
users_emails = event_registrations.map { |er| er.registration.email }.join(', ')
UpdatedMaxAttendeesAutomaticallyJob.perform_later(event, users_emails) if event.send_email_on_updated_max_attendees_automatically?
end
render json: { 'status' => 'ok' }
end