Big refactoring of registration
- Added datatable gem - Addaed datatable to events, users (#422), registrations
This commit is contained in:
parent
0f1051d24e
commit
d21e19b977
34 changed files with 435 additions and 12988 deletions
|
|
@ -2,114 +2,46 @@ module Admin
|
|||
class RegistrationsController < Admin::BaseController
|
||||
load_and_authorize_resource :conference, find_by: :short_title
|
||||
load_and_authorize_resource through: :conference
|
||||
before_filter :set_user, except: [:index]
|
||||
|
||||
def index
|
||||
authorize! :show, Registration.new(conference_id: @conference.id)
|
||||
session[:return_to] ||= request.referer
|
||||
@pdf_filename = "#{@conference.title}.pdf"
|
||||
@registrations = @conference.registrations.includes(:user)
|
||||
@registrations = @registrations.order('registrations.created_at ASC')
|
||||
@registrations = @conference.registrations.includes(:user).order('registrations.created_at ASC')
|
||||
@attended = @conference.registrations.where('attended = ?', true).count
|
||||
@headers = %w(name email nickname other_needs arrival departure attended)
|
||||
end
|
||||
|
||||
def change_field
|
||||
field = params[:view_field]
|
||||
if @registration.send(field.to_sym)
|
||||
@registration.update_attribute(:"#{field}", 0)
|
||||
def toogle_attended
|
||||
@registration.attended = !@registration.attended
|
||||
if @registration.save
|
||||
flash[:notice] = "Successfully updated Attended for #{@user.email}"
|
||||
redirect_to admin_conference_registrations_path(@conference.short_title)
|
||||
else
|
||||
@registration.update_attribute(:"#{field}", 1)
|
||||
flash[:notice] = "Update Attended for #{@user.email} failed!"
|
||||
redirect_to admin_conference_registrations_path(@conference.short_title)
|
||||
end
|
||||
|
||||
redirect_to admin_conference_registrations_path(@conference.short_title)
|
||||
flash[:notice] = "Updated '#{params[:view_field]}' => #{@registration.attended} for
|
||||
#{(User.where('id = ?', @registration.user_id).first).email}"
|
||||
end
|
||||
|
||||
def edit
|
||||
@user = User.where('id = ?', @registration.user_id).first
|
||||
end
|
||||
|
||||
def update
|
||||
@user = User.where('id = ?', @registration.user_id).first
|
||||
begin
|
||||
@user.update_attributes!(params[:registration][:user_attributes])
|
||||
params[:registration].delete :user_attributes
|
||||
if params[:registration][:supporter_registration]
|
||||
@registration.supporter_registration.
|
||||
update_attributes(params[:registration][:supporter_registration_attributes])
|
||||
params[:registration].delete :supporter_registration_attributes
|
||||
end
|
||||
@registration.update_attributes!(params[:registration])
|
||||
flash[:success] = "Successfully updated registration for #{@user.name} #{@user.email}"
|
||||
redirect_to(admin_conference_registrations_path(@conference.short_title))
|
||||
rescue => e
|
||||
Rails.logger.debug e.backtrace.join("\n")
|
||||
redirect_to(admin_conference_registrations_path(@conference.short_title),
|
||||
alert: 'Failed to update registration:' + e.message)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
@user = User.new
|
||||
@registration = @user.registrations.new
|
||||
@registration.conference_id = @conference.id
|
||||
@supporter_registration = @conference.supporter_registrations.new
|
||||
end
|
||||
|
||||
def create
|
||||
@user = User.prepare(user_params['user'])
|
||||
@registration = Registration.new
|
||||
|
||||
unless @user.save
|
||||
render action: 'new'
|
||||
return
|
||||
end
|
||||
|
||||
if @conference.user_registered? @user # Check if user is already registered to the conference
|
||||
redirect_to admin_conference_registrations_path(@conference.short_title)
|
||||
flash[:alert] = "#{@user.email} is already registred!"
|
||||
return
|
||||
end
|
||||
|
||||
# Build registration
|
||||
@registration = @user.registrations.build
|
||||
@registration.attributes = registration_params
|
||||
@registration.conference_id = @conference.id
|
||||
@registration.attended = true
|
||||
|
||||
if params[:registration][:supporter_registration]
|
||||
@supporter_registration = @registration.build_supporter_registration
|
||||
@supporter_registration.attributes = supporter_params['supporter_registration']
|
||||
@supporter_registration.conference_id = @conference.id
|
||||
else
|
||||
# If we render action: 'new' we need the @supporter_registration variable to be set
|
||||
@supporter_registration = @conference.supporter_registrations.new
|
||||
end
|
||||
|
||||
@registration.update_attributes(registration_params)
|
||||
if @registration.save
|
||||
flash[:success] = "Successfully created new registration for #{@user.email}."
|
||||
redirect_to admin_conference_registrations_path(@conference.short_title)
|
||||
redirect_to admin_conference_registrations_path(@conference.short_title),
|
||||
notice: 'Successfully updated registration!'
|
||||
else
|
||||
render action: 'new'
|
||||
flash[:alert] = "A error prohibited the Registration for #{@conference.title}: "\
|
||||
"#{@registration.errors.full_messages.join('. ')}."
|
||||
render :edit
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if can? :destroy, @registration
|
||||
registration = @conference.registrations.where(id: params[:id]).first
|
||||
user = User.where('id = ?', registration.user_id).first
|
||||
|
||||
begin registration.destroy
|
||||
redirect_to admin_conference_registrations_path
|
||||
flash[:notice] = "Deleted registration for #{user.name} #{user.email}"
|
||||
rescue => e
|
||||
Rails.logger.debug e.backtrace.join("\n")
|
||||
redirect_to(admin_conference_registrations_path(@conference.short_title),
|
||||
alert: 'Failed to delete registration:' + e.message)
|
||||
return
|
||||
end
|
||||
@registration.destroy
|
||||
redirect_to admin_conference_registrations_path(@conference.short_title),
|
||||
notice: "Deleted registration for #{@user.name}!"
|
||||
else
|
||||
redirect_to(admin_conference_registrations_path(@conference.short_title),
|
||||
alert: 'You must be an admin to delete a registration.')
|
||||
|
|
@ -118,18 +50,23 @@ module Admin
|
|||
|
||||
protected
|
||||
|
||||
def set_user
|
||||
@user = User.where('id = ?', @registration.user_id).first
|
||||
end
|
||||
|
||||
def registration_params
|
||||
params.require(:registration).permit(:attending_with_partner, :using_affiliated_lodging,
|
||||
:handicapped_access_required, :other_special_needs,
|
||||
:attended)
|
||||
end
|
||||
|
||||
def user_params
|
||||
params.require(:registration).permit(user: [:email, :name, :nickname, :affiliation])
|
||||
end
|
||||
|
||||
def supporter_params
|
||||
params.require(:registration).permit(supporter_registration: [:supporter_level_id, :code])
|
||||
params.require(:registration).
|
||||
permit(
|
||||
:conference_id, :arrival, :departure,
|
||||
:volunteer,
|
||||
vchoice_ids: [], qanswer_ids: [],
|
||||
qanswers_attributes: [],
|
||||
user_attributes: [
|
||||
:id, :name, :tshirt, :mobile, :volunteer_experience, :languages,
|
||||
:nickname, :affiliation ],
|
||||
supporter_registration_attributes: [
|
||||
:id, :supporter_level_id, :code
|
||||
])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,124 +0,0 @@
|
|||
class ConferenceRegistrationController < ApplicationController
|
||||
before_filter :verify_user
|
||||
load_resource :conference, find_by: :short_title
|
||||
authorize_resource :conference_registration, class: Registration
|
||||
|
||||
def register
|
||||
@workshops = @conference.events.where('require_registration = ? AND state LIKE ?',
|
||||
true, 'confirmed')
|
||||
@user = current_user
|
||||
|
||||
@registration = @user.registrations.where(conference_id: @conference.id).first
|
||||
@registered = true
|
||||
if @registration.nil?
|
||||
@registered = false
|
||||
@registration = @user.registrations.new(conference_id: @conference.id)
|
||||
end
|
||||
|
||||
# Check if there's an existing SupporterRegistration for this email and link it when appropriate
|
||||
@registration.supporter_registration ||= @conference.supporter_registrations.where(
|
||||
email: @user.email).first
|
||||
@registration.supporter_registration ||= SupporterRegistration.new(conference_id: @conference.id)
|
||||
end
|
||||
|
||||
# TODO this is ugly
|
||||
def update
|
||||
user = current_user
|
||||
registration = user.registrations.where(conference_id: @conference.id).first
|
||||
update_registration = true
|
||||
# First verify that the supporter code is legit
|
||||
if !params[:registration][:supporter_registration_attributes].nil? &&
|
||||
!params[:registration][:supporter_registration_attributes][:code].empty?
|
||||
regs = conference.supporter_registrations.where(
|
||||
code: params[:registration][:supporter_registration_attributes][:code])
|
||||
|
||||
if regs.count != 0
|
||||
if regs.where(email: user.email).count == 0
|
||||
redirect_to(conference_register_path(conference_id: @conference.short_title),
|
||||
alert: "This code is already in use.
|
||||
Please contact #{conference.contact.email} for assistance.")
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
begin
|
||||
if registration.nil?
|
||||
update_registration = false
|
||||
user.update_attributes(registration_params[:user_attributes])
|
||||
params[:registration].delete :user_attributes
|
||||
supporter_reg = params[:registration][:supporter_registration_attributes]
|
||||
params[:registration].delete :supporter_registration_attributes
|
||||
registration = user.registrations.new(registration_params)
|
||||
if @conference.use_supporter_levels? && !supporter_reg.nil?
|
||||
if !supporter_reg[:id].blank?
|
||||
# Means that their supporter registration was entered ahead of time, by an admin
|
||||
registration.supporter_registration = SupporterRegistration.find(supporter_reg[:id])
|
||||
if registration.supporter_registration.email != user.email
|
||||
raise 'Invalid code'
|
||||
end
|
||||
else
|
||||
registration.supporter_registration = @conference.
|
||||
supporter_registrations.new(registration_params[:supporter_registration_attributes])
|
||||
end
|
||||
end
|
||||
|
||||
registration.conference_id = @conference.id
|
||||
registration.save!
|
||||
if user.subscriptions.where(conference: @conference).blank?
|
||||
subscription = Subscription.new(conference_id: @conference.id, user_id: user.id)
|
||||
redirect_message = subscription.save ? 'You are now Registered and will be receiving Email Notifications.' : 'You are now Registered.'
|
||||
end
|
||||
else
|
||||
registration.update_attributes!(registration_params)
|
||||
end
|
||||
rescue => e
|
||||
Rails.logger.debug e.backtrace.join('\n')
|
||||
redirect_to(conference_register_path(conference_id: @conference.short_title),
|
||||
alert: 'Registration failed:' + e.message)
|
||||
return
|
||||
end
|
||||
|
||||
if update_registration
|
||||
redirect_message = 'Registration updated.'
|
||||
else
|
||||
# Track ahoy event
|
||||
ahoy.track 'Registered', title: 'New registration'
|
||||
if @conference.email_settings.send_on_registration?
|
||||
Mailbot.delay.registration_mail(@conference, current_user)
|
||||
end
|
||||
end
|
||||
redirect_to(conference_register_path(conference_id: @conference.short_title),
|
||||
notice: redirect_message)
|
||||
end
|
||||
|
||||
def unregister
|
||||
user = current_user
|
||||
registration = user.registrations.where(conference_id: @conference.id).first
|
||||
subscription = user.subscriptions.where(conference: @conference)
|
||||
unless subscription.blank?
|
||||
subscription.first.destroy
|
||||
end
|
||||
registration.destroy
|
||||
redirect_to :root
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def registration_params
|
||||
params.require(:registration).
|
||||
permit(
|
||||
:conference_id, :attending_social_events, :attending_with_partner,
|
||||
:using_affiliated_lodging, :arrival, :departure,
|
||||
:other_dietary_choice, :handicapped_access_required, :dietary_choice_id,
|
||||
:volunteer, :other_special_needs,
|
||||
social_event_ids: [],
|
||||
vchoice_ids: [],
|
||||
qanswer_ids: [],
|
||||
qanswers_attributes: [],
|
||||
user_attributes: [
|
||||
:id, :name],
|
||||
supporter_registration_attributes: [
|
||||
:id, :supporter_level_id, :code
|
||||
])
|
||||
end
|
||||
end
|
||||
85
app/controllers/conference_registrations_controller.rb
Normal file
85
app/controllers/conference_registrations_controller.rb
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
class ConferenceRegistrationsController < ApplicationController
|
||||
before_filter :verify_user
|
||||
load_resource :conference, find_by: :short_title
|
||||
authorize_resource :conference_registrations, class: Registration
|
||||
before_action :set_registration, only: [:edit, :update, :destroy]
|
||||
before_action :set_workshops, only: [:new, :edit, :update, :create]
|
||||
|
||||
def new
|
||||
@registration = current_user.registrations.build(conference_id: @conference.id)
|
||||
@registration.build_supporter_registration
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def create
|
||||
user_attributes = registration_params[:user_attributes]
|
||||
params[:registration].delete :user_attributes
|
||||
|
||||
@registration = current_user.registrations.build(registration_params)
|
||||
@registration.conference_id = @conference.id
|
||||
|
||||
if @registration.save && current_user.update_attributes(user_attributes)
|
||||
# Trigger ahoy event
|
||||
ahoy.track 'Registered', title: 'New registration'
|
||||
|
||||
# Send registration mail
|
||||
if @conference.email_settings.send_on_registration?
|
||||
Mailbot.delay.registration_mail(@conference, current_user)
|
||||
end
|
||||
|
||||
# Set subscription for the conference
|
||||
Subscription.create(conference_id: @conference.id, user_id: current_user.id)
|
||||
|
||||
redirect_to edit_conference_conference_registrations_path(@conference.short_title),
|
||||
notice: 'You are now registered and will be receiving E-Mail notifications.'
|
||||
else
|
||||
flash[:alert] = "A error prohibited the registration for #{@conference.title}: "\
|
||||
"#{@registration.errors.full_messages.join('. ')}."
|
||||
render :new
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
if @registration.update(registration_params)
|
||||
redirect_to edit_conference_conference_registrations_path(@conference.short_title),
|
||||
notice: 'Registration was successfully updated.'
|
||||
else
|
||||
flash[:alert] = "A error prohibited the registration for #{@conference.title}: "\
|
||||
"#{@registration.errors.full_messages.join('. ')}."
|
||||
render :edit
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@registration.destroy
|
||||
redirect_to root_path,
|
||||
notice: "You are not registered for #{@conference.title} anymore!"
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def set_workshops
|
||||
@workshops = @conference.events.where('require_registration = ? AND state LIKE ?', true, 'confirmed')
|
||||
end
|
||||
|
||||
def set_registration
|
||||
@registration = current_user.registrations.where(conference_id: @conference.id).first
|
||||
end
|
||||
|
||||
def registration_params
|
||||
params.require(:registration).
|
||||
permit(
|
||||
:conference_id, :arrival, :departure,
|
||||
:volunteer,
|
||||
vchoice_ids: [], qanswer_ids: [],
|
||||
qanswers_attributes: [],
|
||||
event_ids: [],
|
||||
user_attributes: [
|
||||
:id, :name, :tshirt, :mobile, :volunteer_experience, :languages],
|
||||
supporter_registration_attributes: [
|
||||
:id, :supporter_level_id, :code
|
||||
])
|
||||
end
|
||||
end
|
||||
|
|
@ -45,15 +45,13 @@ class ProposalController < ApplicationController
|
|||
return
|
||||
end
|
||||
|
||||
registration = current_user.registrations.where(conference_id: @conference.id).first
|
||||
ahoy.track 'Event submission', title: 'New submission'
|
||||
if registration.nil?
|
||||
redirect_to(conference_register_path(@conference.short_title),
|
||||
alert: 'Event was successfully submitted.
|
||||
You should register for the conference now.')
|
||||
else
|
||||
redirect_to(conference_proposal_index_path(conference_id: @conference.short_title),
|
||||
if @conference.user_registered?(current_user)
|
||||
redirect_to(conference_proposal_index_path(@conference.short_title),
|
||||
notice: 'Event was successfully submitted.')
|
||||
else
|
||||
redirect_to(new_conference_conference_registrations_path(conference_id: @conference.short_title),
|
||||
alert: 'Event was successfully submitted. You should register for the conference now.')
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -114,13 +112,12 @@ class ProposalController < ApplicationController
|
|||
return
|
||||
end
|
||||
|
||||
if !@conference.user_registered?(current_user)
|
||||
redirect_to(conference_register_path(@conference.short_title),
|
||||
alert: 'The proposal was confirmed. Please register to attend the conference.')
|
||||
return
|
||||
if @conference.user_registered?(current_user)
|
||||
redirect_to(conference_proposal_index_path(@conference.short_title),
|
||||
notice: 'The proposal was confirmed.')
|
||||
end
|
||||
redirect_to(conference_proposal_index_path(conference_id: @conference.short_title),
|
||||
notice: 'The proposal was confirmed.')
|
||||
redirect_to(new_conference_conference_registrations_path(conference_id: @conference.short_title),
|
||||
alert: 'The proposal was confirmed. Please register to attend the conference.')
|
||||
end
|
||||
|
||||
def restart
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue