Add registration_limit to conference model. Added the input for registration limit in the edit conference form. In the controller, if the limit has exceeded redirect to root_path with an alert. fix #761

This commit is contained in:
David Sedeño 2016-02-02 00:16:43 +01:00
parent 2034c0f965
commit 28fbc518f3
12 changed files with 124 additions and 16 deletions

View file

@ -211,7 +211,7 @@ module Admin
:vpositions_attributes, :use_volunteers, :color,
:sponsorship_levels_attributes, :sponsors_attributes,
:photos_attributes, :targets, :targets_attributes,
:campaigns, :campaigns_attributes)
:campaigns, :campaigns_attributes, :registration_limit)
end
def get_users(role_name)

View file

@ -20,6 +20,11 @@ class ConferenceRegistrationsController < ApplicationController
redirect_to edit_conference_conference_registrations_path(@conference.short_title)
end
if @conference.registration_limit_exceeded?
redirect_to root_path, alert: "Sorry, registration limit exceeded for #{@conference.title}"
return
end
@registration = Registration.new
# @user variable needs to be set so that _sign_up_form_embedded works properly

View file

@ -65,6 +65,7 @@ class Conference < ActiveRecord::Base
validates_uniqueness_of :short_title
validates_format_of :short_title, with: /\A[a-zA-Z0-9_-]*\z/
validates :registration_limit, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
# This validation is needed since a conference with a start date greater than the end date is not possible
validate :valid_date_range?
@ -536,6 +537,10 @@ class Conference < ActiveRecord::Base
email_settings.conference_registration_dates_updated_body
end
def registration_limit_exceeded?
registration_limit > 0 && registrations.count >= registration_limit
end
private
after_create do

View file

@ -26,6 +26,7 @@ class Registration < ActiveRecord::Base
validates :user, presence: true
validates_uniqueness_of :user_id, scope: :conference_id, message: 'already Registered!'
validate :registration_limit_not_exceed, on: :create
after_create :set_week, :subscribe_to_conference, :send_registration_mail
@ -49,4 +50,10 @@ class Registration < ActiveRecord::Base
self.week = created_at.strftime('%W')
save!
end
def registration_limit_not_exceed
if self.conference.registration_limit>0 && self.conference.registrations(:reload).count >= self.conference.registration_limit
errors.add(:base, 'Registration limit exceeded')
end
end
end

View file

@ -18,5 +18,6 @@
= f.input :timezone, :as => :time_zone, :hint => "The conference time zone"
= f.input :start_date, :as => :string, :input_html => { :id => "conference-start-datepicker", :readonly => "readonly" }
= f.input :end_date, :as => :string, :input_html => { :id => "conference-end-datepicker", :readonly => "readonly" }
= f.inputs name: "Registrations" do
= f.input :registration_limit, as: :number, in: 0..9999, hint: "Limit the number of registrations to the conference (0 no limit)"
= f.action :submit, :as => :button, :button_html => {:class => "btn btn-primary"}

View file

@ -27,7 +27,9 @@
- if conference.user_registered?(current_user)
= link_to "My Registration", conference_conference_registrations_path(conference.short_title), :class =>"btn btn-default"
- else
= link_to "Register", new_conference_conference_registrations_path(conference.short_title), :class =>"btn btn-default"
= link_to "Register", new_conference_conference_registrations_path(conference.short_title), class: "btn btn-default", disabled: conference.registration_limit_exceeded?
- if conference.registration_limit_exceeded?
Sorry, no places left
- if !current_user.nil? && current_user.proposal_count(conference) > 0
= link_to "My Proposals", conference_program_proposal_index_path(conference.short_title), :class =>"btn btn-default"
- elsif conference.program.cfp_open?

View file

@ -6,19 +6,25 @@
.row
.col-md-12.text-center
%h1 Registration
- if @conference.tickets.empty?
%p.lead
Going to
= @conference.short_title
is free of charge.
- if @conference.registration_limit_exceeded?
%p
We only ask you to register yourself until
= @conference.registration_period.end_date.strftime('%A, %B %-d. %Y')
so we can plan for the right amount of people.
Sorry, the conference registration limit has exceeded
- else
%p
The registration period ends on
= @conference.registration_period.end_date.strftime('%A, %B %-d. %Y')
%p.cta-button
- if @conference.tickets.empty?
%p.lead
Going to
= @conference.short_title
is free of charge.
%p
We only ask you to register yourself until
= @conference.registration_period.end_date.strftime('%A, %B %-d. %Y')
so we can plan for the right amount of people.
%p.cta-button
- else
%p
The registration period ends on
= @conference.registration_period.end_date.strftime('%A, %B %-d. %Y')
%p.cta-button
= link_to(new_conference_conference_registrations_path(@conference.short_title), class: 'btn btn-lg btn-success') do
Register Now