BikeBikeBike/app/helpers/registration_helper.rb

157 lines
5.4 KiB
Ruby
Raw Normal View History

2016-12-25 09:10:49 -08:00
module RegistrationHelper
2017-04-09 11:37:16 -07:00
def registration_steps(conference = @conference)
{
pre: [:policy, :contact_info, :workshops],
open: [:policy, :contact_info, :questions, :hosting, :payment, :workshops]
}[@this_conference.registration_status]
end
def registration_status(registration)
return :unregistered if registration.nil?
return :cancelled if registration.is_attending == 'n' && !registration.can_provide_housing
2017-04-09 11:37:16 -07:00
return registration.status
end
2016-12-25 09:10:49 -08:00
def current_registration_steps(registration = @registration)
return nil unless registration.present?
steps = registration_steps(registration.conference)
current_steps = []
disable_steps = false
completed_steps = registration.steps_completed || []
2017-01-09 22:43:39 -08:00
2017-01-10 19:37:00 -08:00
if potential_provider(registration)
2017-01-09 22:43:39 -08:00
steps -= [:questions]
else
steps -= [:hosting]
end
2017-04-09 11:37:16 -07:00
steps -= [:payment] unless registration.conference.paypal_email_address.present? && registration.conference.paypal_username.present? && registration.conference.paypal_password.present? && registration.conference.paypal_signature.present?
steps -= [:payment, :workshops] if registration.is_attending == 'n'
2017-01-09 22:43:39 -08:00
2017-04-09 11:37:16 -07:00
steps.each do |step|
2016-12-25 09:10:49 -08:00
# disable the step if we've already found an incomplete step
2017-04-09 11:37:16 -07:00
# enabled = !disable_steps# || registration_complete
2016-12-25 09:10:49 -08:00
# record whether or not we've found an incomplete step
current_steps << {
name: step,
2017-04-09 11:37:16 -07:00
enabled: !disable_steps
2016-12-25 09:10:49 -08:00
}
2017-04-09 11:37:16 -07:00
disable_steps ||= !completed_steps.include?(step.to_s)# && ![:payment, :workshops].include?(step)
2016-12-25 09:10:49 -08:00
end
2017-04-09 11:37:16 -07:00
2016-12-25 09:10:49 -08:00
return current_steps
end
def current_step(registration = @registration)
completed_steps = registration.steps_completed || []
2017-01-10 16:29:48 -08:00
last_step = nil
2017-04-09 11:37:16 -07:00
steps = current_registration_steps(registration) || []
2017-07-04 09:41:10 -07:00
steps.each do |step|
2017-01-10 16:29:48 -08:00
# return the last enabled step if this one is disabled
return last_step unless step[:enabled]
# save the last step
last_step = step[:name]
# return this step if it hasn't been completed yet
return last_step unless completed_steps.include?(last_step.to_s)
2016-12-25 09:10:49 -08:00
end
2017-01-10 16:29:48 -08:00
# if all else fails, return the first step
2017-04-09 11:37:16 -07:00
return steps.last[:name]
2016-12-25 09:10:49 -08:00
end
2017-05-30 19:17:02 -07:00
def registration_step_header(step = @step, vars = nil)
if step.is_a?(Hash)
vars = step
step = @step
end
vars ||= {}
row do
columns(medium: 12) do
registration_step_header_title(step, vars[:header])
end.html_safe +
columns(medium: 12) do
registration_step_header_description(step, vars[:description])
end.html_safe
end.html_safe
end
2017-05-30 19:24:44 -07:00
def registration_step_header_title_string(step = @step, vars = nil)
2017-05-30 19:17:02 -07:00
if step.is_a?(Hash)
vars = step
step = @step
end
2017-05-30 19:24:44 -07:00
_("articles.conference_registration.headings.#{step}", :t, 2, vars: vars || {})
end
def registration_step_header_title(step = @step, vars = nil)
content_tag(:h2, registration_step_header_title_string(step, vars)).html_safe
2017-05-30 19:17:02 -07:00
end
def registration_step_header_description(step = @step, vars = nil)
if step.is_a?(Hash)
vars = step
step = @step
end
2017-05-30 19:24:44 -07:00
content_tag(:p, (_"articles.conference_registration.paragraphs.#{step}", :p, 2, vars: vars || {})).html_safe
2017-05-30 19:17:02 -07:00
end
2017-05-30 19:24:44 -07:00
def save_registration_step(conference = @this_conference, step = @step, registration = nil, &block)
registration ||= ConferenceRegistration.find_by(user_id: current_user.id, conference_id: conference.id)
2017-05-30 19:17:02 -07:00
buttons = [:back]
case step.to_sym
when :policy
buttons = [:agree]
2017-05-30 19:24:44 -07:00
when :name, :languages, :org_location, :org_create_name, :org_create_address, :org_create_email, :org_create_mailing_address,
:housing_companion_email, :housing_companion_invite, :housing_allergies, :housing_other, :org_non_member_interest,
:hosting_address, :hosting_phone, :hosting_space_beds, :hosting_space_floor, :hosting_info, :hosting_other
2017-05-30 19:17:02 -07:00
buttons = [:next, :back]
when :org_location_confirm
buttons = [:yes, :back]
2017-05-30 19:24:44 -07:00
when :confirm_payment
buttons = [:confirm, :cancel]
2017-05-30 19:17:02 -07:00
when :review
buttons = nil
end
2017-05-30 19:24:44 -07:00
if buttons.present? && registration.present? && registration.registration_complete?
buttons << :review
end
2017-05-30 19:17:02 -07:00
content = block.present? ? capture(&block) : ''
actions = ''
if buttons.present?
buttons.each do |button_name|
attrs = { value: button_name }
attrs[:formnovalidate] = true if button_name == :back
actions += (button button_name, attrs)
2017-05-30 19:17:02 -07:00
end
end
2017-05-30 19:48:08 -07:00
actions = columns(medium: 12, class: [:actions, :center]) do
content_tag(:div, actions.html_safe, class: :buttons).html_safe
end
form_tag(register_path(conference.slug), class: (LinguaFranca.recording? || @no_ajax ? nil : 'js-xhr')) do
2017-05-30 19:17:02 -07:00
content.html_safe +
(hidden_field_tag :step, step).html_safe +
2017-05-30 19:48:08 -07:00
actions.html_safe
2017-05-30 19:17:02 -07:00
end.html_safe
end
2017-06-03 12:55:13 -07:00
def step_message
if @update_message.present? && @update_status.present?
return row do
columns(medium: 12, class: @update_status, id: 'action-message') do
content_tag(:div, (_"articles.conference_registration.#{@update_status}.#{@update_message}", :s), class: :message).html_safe
end.html_safe
end.html_safe
end
return ''
end
2016-12-25 09:10:49 -08:00
end