2014-06-23 19:07:50 +03:00
|
|
|
module Admin
|
2014-08-13 14:37:05 +03:00
|
|
|
class RegistrationsController < Admin::BaseController
|
2014-08-12 11:51:59 +03:00
|
|
|
load_and_authorize_resource :conference, find_by: :short_title
|
|
|
|
|
load_and_authorize_resource through: :conference
|
2014-08-22 15:08:54 +02:00
|
|
|
before_filter :set_user, except: [:index]
|
2013-01-07 09:04:09 +01:00
|
|
|
|
2014-06-23 19:07:50 +03:00
|
|
|
def index
|
2014-08-12 11:51:59 +03:00
|
|
|
authorize! :show, Registration.new(conference_id: @conference.id)
|
2014-06-23 19:07:50 +03:00
|
|
|
@pdf_filename = "#{@conference.title}.pdf"
|
2014-08-22 15:08:54 +02:00
|
|
|
@registrations = @conference.registrations.includes(:user).order('registrations.created_at ASC')
|
2014-06-24 12:14:53 +03:00
|
|
|
@attended = @conference.registrations.where('attended = ?', true).count
|
2014-06-23 19:07:50 +03:00
|
|
|
end
|
2013-07-12 10:45:40 +03:00
|
|
|
|
2014-08-22 15:08:54 +02:00
|
|
|
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)
|
2014-06-24 12:14:53 +03:00
|
|
|
else
|
2014-08-28 15:21:05 +02:00
|
|
|
flash[:notice] = "Update Attended for #{@user.email} failed!" \
|
|
|
|
|
"#{@registration.errors.full_messages.join('. ')}"
|
2014-08-22 15:08:54 +02:00
|
|
|
redirect_to admin_conference_registrations_path(@conference.short_title)
|
2014-06-24 12:14:53 +03:00
|
|
|
end
|
2014-06-23 19:07:50 +03:00
|
|
|
end
|
2013-07-15 13:11:18 +03:00
|
|
|
|
2014-08-28 15:21:05 +02:00
|
|
|
def edit; end
|
2013-07-12 11:43:31 +03:00
|
|
|
|
2014-06-23 19:07:50 +03:00
|
|
|
def update
|
2014-08-22 15:08:54 +02:00
|
|
|
@registration.update_attributes(registration_params)
|
2014-06-23 19:07:50 +03:00
|
|
|
if @registration.save
|
2014-08-22 15:08:54 +02:00
|
|
|
redirect_to admin_conference_registrations_path(@conference.short_title),
|
|
|
|
|
notice: 'Successfully updated registration!'
|
2014-06-23 19:07:50 +03:00
|
|
|
else
|
2014-08-22 15:08:54 +02:00
|
|
|
flash[:alert] = "A error prohibited the Registration for #{@conference.title}: "\
|
|
|
|
|
"#{@registration.errors.full_messages.join('. ')}."
|
|
|
|
|
render :edit
|
2013-07-16 16:03:36 +02:00
|
|
|
end
|
|
|
|
|
end
|
2013-07-12 17:40:27 +03:00
|
|
|
|
2014-06-23 19:07:50 +03:00
|
|
|
def destroy
|
2014-08-12 11:51:59 +03:00
|
|
|
if can? :destroy, @registration
|
2014-08-22 15:08:54 +02:00
|
|
|
@registration.destroy
|
|
|
|
|
redirect_to admin_conference_registrations_path(@conference.short_title),
|
|
|
|
|
notice: "Deleted registration for #{@user.name}!"
|
2014-06-23 19:07:50 +03:00
|
|
|
else
|
2014-05-15 21:04:08 +03:00
|
|
|
redirect_to(admin_conference_registrations_path(@conference.short_title),
|
2014-06-23 19:07:50 +03:00
|
|
|
alert: 'You must be an admin to delete a registration.')
|
2013-07-12 11:06:16 +03:00
|
|
|
end
|
2013-07-12 10:54:59 +03:00
|
|
|
end
|
2014-06-23 19:07:50 +03:00
|
|
|
|
|
|
|
|
protected
|
2014-06-24 12:14:53 +03:00
|
|
|
|
2014-08-22 15:08:54 +02:00
|
|
|
def set_user
|
2014-08-28 15:21:05 +02:00
|
|
|
@user = User.find_by(id: @registration.user_id)
|
2014-06-24 12:14:53 +03:00
|
|
|
end
|
|
|
|
|
|
2014-08-22 15:08:54 +02:00
|
|
|
def registration_params
|
|
|
|
|
params.require(:registration).
|
|
|
|
|
permit(
|
|
|
|
|
:conference_id, :arrival, :departure,
|
|
|
|
|
:volunteer,
|
|
|
|
|
vchoice_ids: [], qanswer_ids: [],
|
|
|
|
|
qanswers_attributes: [],
|
|
|
|
|
user_attributes: [
|
|
|
|
|
:id, :name, :tshirt, :mobile, :volunteer_experience, :languages,
|
2014-08-28 15:21:05 +02:00
|
|
|
:nickname, :affiliation ])
|
2014-06-24 12:14:53 +03:00
|
|
|
end
|
2013-07-12 10:54:59 +03:00
|
|
|
end
|
2014-06-23 19:07:50 +03:00
|
|
|
end
|