2017 refactor
This commit is contained in:
@@ -0,0 +1,163 @@
|
||||
module AdminHelper
|
||||
|
||||
def administration_steps
|
||||
{
|
||||
info: [:administrators, :dates, :description, :poster],
|
||||
payment: [:payment_message, :suggested_amounts, :paypal],
|
||||
registration: [:registration_status, :stats, :registrations, :broadcast],
|
||||
housing: [:providers, :housing],
|
||||
events: [:locations, :meals, :events],
|
||||
schedule: [:workshop_times, :schedule, :publish_schedule]
|
||||
}
|
||||
end
|
||||
|
||||
def administration_sub_steps
|
||||
{
|
||||
location_edit: :locations,
|
||||
event_edit: :events
|
||||
}
|
||||
end
|
||||
|
||||
def get_administration_group(administration_step)
|
||||
admin_step = administration_step.to_sym
|
||||
admin_step = administration_sub_steps[admin_step] if administration_sub_steps[admin_step].present?
|
||||
administration_steps.each do | group, steps |
|
||||
steps.each do | step |
|
||||
return group if step == admin_step
|
||||
end
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
def broadcast_to(to, conference = nil)
|
||||
conference ||= @this_conference || @conference
|
||||
|
||||
users = []
|
||||
|
||||
case to.to_sym
|
||||
when :registered
|
||||
ConferenceRegistration.where(conference_id: conference.id).each do | r |
|
||||
users << r.user if ((r.steps_completed || []).include? 'questions') && r.user.present? && r.is_attending != 'n'
|
||||
end
|
||||
when :pre_registered
|
||||
ConferenceRegistration.where(conference_id: conference.id).each do | r |
|
||||
users << r.user if registration_status(r) == :preregistered && r.is_attending != 'n'
|
||||
end
|
||||
when :workshop_facilitators
|
||||
user_hash = {}
|
||||
Workshop.where(conference_id: conference.id).each do | w |
|
||||
w.active_facilitators.each do | u |
|
||||
user_hash[u.id] ||= u if u.present?
|
||||
end
|
||||
end
|
||||
users = user_hash.values
|
||||
when :unregistered
|
||||
ConferenceRegistration.where(conference_id: conference.id).each do | r |
|
||||
users << r.user if registration_status(r) == :unregistered && r.is_attending != 'n'
|
||||
end
|
||||
when :housing_providers
|
||||
ConferenceRegistration.where(conference_id: conference.id, can_provide_housing: true).each do | r |
|
||||
users << r.user if r.user.present?
|
||||
end
|
||||
when :guests
|
||||
ConferenceRegistration.where(conference_id: conference.id, housing: 'house').each do | r |
|
||||
users << r.user if r.user.present? && r.is_attending != 'n'
|
||||
end
|
||||
when :all
|
||||
User.all.each do | u |
|
||||
users << u if u.present? && (u.is_subscribed.nil? || u.is_subscribed)
|
||||
end
|
||||
end
|
||||
|
||||
return users
|
||||
end
|
||||
|
||||
def get_housing_match(host, guest, space)
|
||||
housing_data = guest.housing_data || []
|
||||
|
||||
if housing_data['host'].present?
|
||||
if housing_data['host'] == host.id
|
||||
return space == housing_data['space'] ? :selected_space : :other_space
|
||||
end
|
||||
|
||||
return :other_host
|
||||
end
|
||||
|
||||
if space_matches?(space, guest.housing) && available_dates_match?(host, guest)
|
||||
return :good_match
|
||||
end
|
||||
|
||||
return :bad_match
|
||||
end
|
||||
|
||||
def get_workshop_match(workshop, day, block, location)
|
||||
if workshop.event_location_id.present? && workshop.present?
|
||||
if (Date.parse params[:day]).wday == workshop.block['day'] && block == workshop.block['block'].to_i
|
||||
return :selected_space
|
||||
end
|
||||
|
||||
if location.present? && location.id == workshop.event_location_id
|
||||
return :other_space
|
||||
end
|
||||
|
||||
return :other_host
|
||||
end
|
||||
|
||||
if location.present?
|
||||
needs = JSON.parse(workshop.needs || '[]').map &:to_sym
|
||||
amenities = JSON.parse(location.amenities || '[]').map &:to_sym
|
||||
|
||||
if (needs & amenities).length < needs.length
|
||||
return :bad_match
|
||||
end
|
||||
end
|
||||
|
||||
(((((@schedule[@day] || {})[:times] || {})[@time] || {})[:item] || {})[:workshops] || {}).each do | l, w |
|
||||
if w[:workshop].id != workshop.id
|
||||
f_a = w[:workshop].active_facilitators.map { | f | f.id }
|
||||
f_b = workshop.active_facilitators.map { | f | f.id }
|
||||
if (f_a & f_b).present?
|
||||
return :bad_match
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# housing_data = guest.housing_data || []
|
||||
|
||||
# if housing_data['host'].present?
|
||||
# if housing_data['host'] == host.id
|
||||
# return space == housing_data['space'] ? :selected_space : :other_space
|
||||
# end
|
||||
|
||||
# return :other_host
|
||||
# end
|
||||
|
||||
# if space_matches?(space, guest.housing) && available_dates_match?(host, guest)
|
||||
# return :good_match
|
||||
# end
|
||||
|
||||
# return :bad_match
|
||||
return :good_match
|
||||
end
|
||||
|
||||
def space_matches?(host_space, guest_space)
|
||||
return false unless host_space.present? && guest_space.present?
|
||||
|
||||
if host_space.to_s == 'bed_space' || host_space.to_s == 'floor_space'
|
||||
return guest_space.to_s == 'house'
|
||||
end
|
||||
|
||||
return host_space.to_s == 'tent_space' && guest_space.to_s == 'tent'
|
||||
end
|
||||
|
||||
def available_dates_match?(host, guest)
|
||||
return false unless host.housing_data['availability'].present? && host.housing_data['availability'][1].present?
|
||||
if host.housing_data['availability'][0] <= guest.arrival &&
|
||||
host.housing_data['availability'][1] >= guest.departure
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
end
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,407 +0,0 @@
|
||||
|
||||
module BikeBikeFormHelper
|
||||
include ActionView::Helpers::FormTagHelper
|
||||
|
||||
TEMPLATE_DIR = 'layouts/fields'
|
||||
|
||||
def check_box_tag(name, value = "1", checked = false, options = {})
|
||||
render_field(name, options = get_options(name, options), super(name, value, checked, options), value)
|
||||
end
|
||||
|
||||
def color_field_tag(name, value = nil, options = {})
|
||||
render_field(name, options = get_options(name, options), super(name, value, options), value)
|
||||
end
|
||||
|
||||
def date_field_tag(name, value = nil, options = {})
|
||||
render_field(name, options = get_options(name, options), super(name, value, options), value)
|
||||
end
|
||||
|
||||
def datetime_field_tag(name, value = nil, options = {})
|
||||
render_field(name, options = get_options(name, options), super(name, value, options), value)
|
||||
end
|
||||
|
||||
def datetime_local_field_tag(name, value = nil, options = {})
|
||||
render_field(name, options = get_options(name, options), super(name, value, options), value)
|
||||
end
|
||||
|
||||
def email_field_tag(name, value = nil, options = {})
|
||||
render_field(name, options = get_options(name, options), super(name, value, options), value)
|
||||
end
|
||||
|
||||
def file_field_tag(name, options = {})
|
||||
render_field(name, options = get_options(name, options), super(name, options))
|
||||
end
|
||||
|
||||
def hidden_field_tag(name, value = nil, options = {})
|
||||
super(name, value, options)
|
||||
end
|
||||
|
||||
def month_field_tag(name, value = nil, options = {})
|
||||
render_field(name, options = get_options(name, options), super(name, value, options), value)
|
||||
end
|
||||
|
||||
def number_field_tag(name, value = nil, options = {})
|
||||
options[:_no_wrapper] = true
|
||||
render_field(name, options = get_options(name, options), super(name, value, options), value)
|
||||
end
|
||||
|
||||
def password_field_tag(name = "password", value = nil, options = {})
|
||||
render_field(name, options = get_options(name, options), super(name, value, options), value)
|
||||
end
|
||||
|
||||
def phone_field_tag(name, value = nil, options = {})
|
||||
render_field(name, options = get_options(name, options), super(name, value, options), value)
|
||||
end
|
||||
|
||||
def radio_button_tag(name, value, checked = false, options = {})
|
||||
render_field(name, options = get_options(name, options), super(name, value, checked, options), value)
|
||||
end
|
||||
|
||||
def range_field_tag(name, value = nil, options = {})
|
||||
render_field(name, options = get_options(name, options), super(name, value, options), value)
|
||||
end
|
||||
|
||||
def search_field_tag(name, value = nil, options = {})
|
||||
render_field(name, options = get_options(name, options), super(name, value, options), value)
|
||||
end
|
||||
|
||||
def select_tag(name, option_tags = nil, options = {})
|
||||
render_field(name, options = get_options(name, options), super(name, option_tags, options))
|
||||
end
|
||||
|
||||
def telephone_field_tag(name, value = nil, options = {})
|
||||
render_field(name, options = get_options(name, options), super(name, value, options), value)
|
||||
end
|
||||
|
||||
def text_area_tag(name, content = nil, options = {})
|
||||
render_field(name, options = get_options(name, options), super(name, content, options), content)
|
||||
end
|
||||
|
||||
def text_field_tag(name, value = nil, options = {})
|
||||
if options[:_no_wrapper]
|
||||
options.delete(:_no_wrapper)
|
||||
options[:no_wrapper] = true
|
||||
end
|
||||
render_field(name, options = get_options(name, options), super(name, value, options), value)
|
||||
end
|
||||
|
||||
def time_field_tag(name, value = nil, options = {})
|
||||
render_field(name, options = get_options(name, options), super(name, value, options), value)
|
||||
end
|
||||
|
||||
def url_field_tag(name, value = nil, options = {})
|
||||
render_field(name, options = get_options(name, options), super(name, value, options), value)
|
||||
end
|
||||
|
||||
def week_field_tag(name, value = nil, options = {})
|
||||
render_field(name, options = get_options(name, options), super(name, value, options), value)
|
||||
end
|
||||
|
||||
def country_select_tag(name, value, options={})
|
||||
#options[:no_wrapper] = true
|
||||
render_field(name, options = get_options(name, options), super(name, value, options), value)
|
||||
end
|
||||
|
||||
def subregion_select_tag(name, value, parent_region_or_code, options = {}, html_options = {})
|
||||
render_field(name, options = get_options(name, options), super(name, value, parent_region_or_code, options), value)
|
||||
end
|
||||
|
||||
#def button_tag
|
||||
#def field_set_tag
|
||||
#def form_tag
|
||||
#def image_submit_tag
|
||||
#def label_tag
|
||||
#def submit_tag
|
||||
#def utf8_enforcer_tag
|
||||
|
||||
# FormHelper methods
|
||||
|
||||
def check_box(object_name, method, options = {}, checked_value = "1", unchecked_value = "0")
|
||||
render_field(method, options = get_options(method, options), super(object_name, method, options, checked_value, unchecked_value))
|
||||
end
|
||||
|
||||
def color_field(object_name, method, options = {})
|
||||
render_field(method, options = get_options(method, options), super(object_name, method, options))
|
||||
end
|
||||
|
||||
def date_field(object_name, method, options = {})
|
||||
render_field(method, options = get_options(method, options), super(object_name, method, options))
|
||||
end
|
||||
|
||||
def datetime_field(object_name, method, options = {})
|
||||
render_field(method, options = get_options(method, options), super(object_name, method, options))
|
||||
end
|
||||
|
||||
def datetime_local_field(object_name, method, options = {})
|
||||
render_field(method, options = get_options(method, options), super(object_name, method, options))
|
||||
end
|
||||
|
||||
def email_field(object_name, method, options = {})
|
||||
render_field(method, options = get_options(method, options), super(object_name, method, options))
|
||||
end
|
||||
|
||||
def file_field(object_name, method, options = {})
|
||||
render_field(method, options = get_options(method, options), super(object_name, method, options))
|
||||
end
|
||||
|
||||
def hidden_field(object_name, method, options = {})
|
||||
super(object_name, method, options)
|
||||
end
|
||||
|
||||
def month_field(object_name, method, options = {})
|
||||
render_field(method, options = get_options(method, options), super(object_name, method, options), get_value(method, options))
|
||||
end
|
||||
|
||||
def number_field(object_name, method, options = {})
|
||||
options[:_no_wrapper] = true
|
||||
render_field(method, options = get_options(method, options), super(object_name, method, options), get_value(method, options))
|
||||
end
|
||||
|
||||
def password_field(object_name, method, options = {})
|
||||
render_field(method, options = get_options(method, options), super(object_name, method, options), get_value(method, options))
|
||||
end
|
||||
|
||||
def phone_field(object_name, method, options = {})
|
||||
render_field(method, options = get_options(method, options), super(object_name, method, options), get_value(method, options))
|
||||
end
|
||||
|
||||
def radio_button(object_name, method, tag_value, options = {})
|
||||
render_field(method, options = get_options(method, options), super(object_name, method, tag_value, options), get_value(method, options))
|
||||
end
|
||||
|
||||
def range_field(object_name, method, options = {})
|
||||
render_field(method, options = get_options(method, options), super(object_name, method, options), get_value(method, options))
|
||||
end
|
||||
|
||||
def search_field(object_name, method, options = {})
|
||||
render_field(method, options = get_options(method, options), super(object_name, method, options), get_value(method, options))
|
||||
end
|
||||
|
||||
def telephone_field(object_name, method, options = {})
|
||||
render_field(method, options = get_options(method, options), super(object_name, method, options), get_value(method, options))
|
||||
end
|
||||
|
||||
def text_area(object_name, method, options = {})
|
||||
render_field(method, options = get_options(method, options), super(object_name, method, options), get_value(method, options))
|
||||
end
|
||||
|
||||
def text_field(object_name, method, options = {})
|
||||
if options[:_no_wrapper]
|
||||
options.delete(:_no_wrapper)
|
||||
options[:no_wrapper] = true
|
||||
end
|
||||
render_field(method, options = get_options(method, options), super(object_name, method, options), get_value(method, options))
|
||||
end
|
||||
|
||||
def time_field(object_name, method, options = {})
|
||||
render_field(method, options = get_options(method, options), super(object_name, method, options), get_value(method, options))
|
||||
end
|
||||
|
||||
def url_field(object_name, method, options = {})
|
||||
render_field(method, options = get_options(method, options), super(object_name, method, options), get_value(method, options))
|
||||
end
|
||||
|
||||
def week_field(object_name, method, options = {})
|
||||
render_field(method, options = get_options(method, options), super(object_name, method, options), get_value(method, options))
|
||||
end
|
||||
|
||||
def form_for(*args, &block)
|
||||
@record = args.first
|
||||
|
||||
template = 'errors_' + @record.class.name.underscore
|
||||
template = 'errors_default' unless lookup_context.exists?(template, [TEMPLATE_DIR], true)
|
||||
|
||||
( render (TEMPLATE_DIR + '/' + template) ) + super(*args, &block)
|
||||
end
|
||||
|
||||
def collection_check_boxes(object, method, collection, value_method, text_method, options = {}, html_options = {}, &block)
|
||||
render_field(method, options = get_options(method, options), super(object, method, collection, value_method, text_method, options, html_options, &block), get_value(method, options))
|
||||
end
|
||||
|
||||
def collection_radio_buttons(object, method, collection, value_method, text_method, options = {}, html_options = {}, &block)
|
||||
render_field(method, options = get_options(method, options), super(object, method, collection, value_method, text_method, options, html_options, &block), get_value(method, options))
|
||||
end
|
||||
|
||||
def collection_select(object, method, collection, value_method, text_method, options = {}, html_options = {})
|
||||
render_field(method, options = get_options(method, options), super(object, method, collection, value_method, text_method, options, html_options), get_value(method, options))
|
||||
end
|
||||
|
||||
def grouped_collection_select(object, method, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {})
|
||||
render_field(method, options = get_options(method, options), super(object, method, collection, group_method, group_label_method, option_key_method, option_value_method, options, html_options), get_value(method, options))
|
||||
end
|
||||
|
||||
def select(object, method, choices = nil, options = {}, html_options = {}, &block)
|
||||
render_field(method, options = get_options(method, options), super(object, method, choices, options, html_options, &block), get_value(method, options))
|
||||
end
|
||||
|
||||
def time_zone_select(object, method, priority_zones = nil, options = {}, html_options = {})
|
||||
render_field(method, options = get_options(method, options), super(object, method, priority_zones, options, html_options), get_value(method, options))
|
||||
end
|
||||
|
||||
def country_select(object, method, priorities_or_options = {}, options_or_html_options = {}, html_options = {})
|
||||
if priorities_or_options.is_a? Array
|
||||
options = options_or_html_options = get_options(method, priorities_or_options)
|
||||
else
|
||||
options = priorities_or_options = get_options(method, priorities_or_options)
|
||||
end
|
||||
render_field(method, options, super(object, method, priorities_or_options, options_or_html_options, html_options), get_value(method, options))
|
||||
end
|
||||
|
||||
def subregion_select(object, method, parent_region_or_code, options = {}, html_options = {})
|
||||
render_field(method, options = get_options(method, options), super(object, method, parent_region_or_code, options, html_options), get_value(method, options))
|
||||
end
|
||||
|
||||
# Custom fields
|
||||
|
||||
def image_field_tag(name, value = nil, options = {})
|
||||
render_field(name, options = get_options(name, options), BikeBikeFormHelper.image_field_tag(name, value, options), value)
|
||||
end
|
||||
|
||||
def organization_select_field_tag(name, value = nil, options = {})
|
||||
render_field(name, options = get_options(name, options), BikeBikeFormHelper.organization_select_field_tag(name, value, options), value)
|
||||
end
|
||||
|
||||
def user_select_field_tag(name, value = nil, options = {})
|
||||
render_field(name, options = get_options(name, options), BikeBikeFormHelper.user_select_field_tag(name, value, options), value)
|
||||
end
|
||||
|
||||
#def grouped_options_for_select
|
||||
#def option_groups_from_collection_for_select
|
||||
#def options_for_select
|
||||
#def options_from_collection_for_select
|
||||
#def time_zone_options_for_select
|
||||
|
||||
def form_actions(actions = [])
|
||||
BikeBikeFormHelper.form_actions(actions)
|
||||
end
|
||||
|
||||
class << self
|
||||
|
||||
def form_actions(actions = [])
|
||||
render(:actions, {:actions => actions.is_a?(Array) ? actions : [actions]})
|
||||
end
|
||||
|
||||
def image_field_tag(name, value, options, form = nil)
|
||||
render(:field_image_field, {:name => name, :value => value, :options => options, :form => form})
|
||||
end
|
||||
|
||||
def organization_select_field_tag(name, value, options, form = nil)
|
||||
render(:field_organization_select_field, {:name => name, :value => value, :options => options, :form => form})
|
||||
end
|
||||
|
||||
def user_select_field_tag(name, value, options, form = nil)
|
||||
render(:field_user_select_field, {:name => name, :value => value, :options => options, :form => form})
|
||||
end
|
||||
|
||||
def get_options(name, options, type)
|
||||
if options[:placeholder] === false
|
||||
options.delete(:placeholder)
|
||||
elsif (['email_field', 'number_field', 'phone_field', 'search_field', 'telephone_field', 'text_area', 'text_field', 'url_field'].include? type)
|
||||
options[:placeholder] ||= I18n.translate('form.placeholder.Enter_your_' + name.to_s)
|
||||
end
|
||||
return options
|
||||
end
|
||||
|
||||
def render_field(type, name, options, html, value = nil)
|
||||
options.symbolize_keys!
|
||||
if (options.has_key?(:no_wrapper) && options[:no_wrapper]) || /country/.match(name.to_s) && /^subregion_select/.match(type.to_s) || options[:type] == 'hidden'
|
||||
return html
|
||||
end
|
||||
|
||||
params = Hash.new
|
||||
params[:name] = name.to_sym
|
||||
params[:options] = options
|
||||
params[:html] = html
|
||||
params[:type] = type
|
||||
params[:value] = value
|
||||
|
||||
template = template_exists?(type) ? type : 'default'
|
||||
params[:label_template] = options[:label] === false ? nil : get_label_template(type, options)
|
||||
params[:label_position] = options[:label] === false ? :none : label_position(type, options)
|
||||
|
||||
render(template, params)
|
||||
end
|
||||
|
||||
def get_label_template(type, options)
|
||||
if !options[:label] && /select(_field)?$/.match(type.to_s)
|
||||
return nil
|
||||
end
|
||||
template_exists?('label_' + type) ? type : 'default'
|
||||
end
|
||||
|
||||
def label_position(type, options)
|
||||
# one of: :before, :after, :inside, or :none
|
||||
case type
|
||||
when 'image_field'
|
||||
return :inside
|
||||
when 'organization_select_field'
|
||||
return :none
|
||||
#when 'select_field'
|
||||
# return :before
|
||||
end
|
||||
return :before
|
||||
end
|
||||
|
||||
private
|
||||
def render (template, params)
|
||||
view = ActionView::Base.new(ActionController::Base.view_paths, params)
|
||||
view.extend ApplicationHelper
|
||||
view.render (TEMPLATE_DIR + '/' + template.to_s)
|
||||
end
|
||||
|
||||
def template_exists? (template)
|
||||
view = ActionView::Base.new(ActionController::Base.view_paths, {})
|
||||
view.extend ApplicationHelper
|
||||
view.lookup_context.exists?(template, [TEMPLATE_DIR], true)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def get_type()
|
||||
caller[1][/`.*'/][1..-2].gsub(/^(.*?)(_tag)?$/, '\1')
|
||||
end
|
||||
|
||||
def get_value(method, options)
|
||||
options && options[:object] ? options[:object][method] : nil
|
||||
end
|
||||
|
||||
def get_options(name, options)
|
||||
options[:_controller] = params[:controller]
|
||||
BikeBikeFormHelper.get_options(name, options, get_type())
|
||||
end
|
||||
|
||||
def render_field(name, options, html, value = nil)
|
||||
BikeBikeFormHelper.render_field(get_type(), name, options, html, value)
|
||||
end
|
||||
|
||||
class BikeBikeFormBuilder < ActionView::Helpers::FormBuilder
|
||||
ActionView::Base.default_form_builder = BikeBikeFormHelper::BikeBikeFormBuilder
|
||||
|
||||
def image_field(method, value, options = {})
|
||||
custom_field(method, value, options, 'image_field')
|
||||
end
|
||||
|
||||
def organization_select_field(method, value, options = {})
|
||||
custom_field(method, value, options, 'organization_select_field')
|
||||
end
|
||||
|
||||
def user_select_field(method, value, options = {})
|
||||
custom_field(method, value, options, 'user_select_field')
|
||||
end
|
||||
|
||||
def actions(actions = [])
|
||||
BikeBikeFormHelper.form_actions(actions)
|
||||
end
|
||||
|
||||
private
|
||||
def custom_field(method, value, options, type)
|
||||
if defined? params
|
||||
options[:_controller] = params[:controller]
|
||||
end
|
||||
options[:_record] = object
|
||||
options = BikeBikeFormHelper.get_options(method, options, type)
|
||||
html = BikeBikeFormHelper.send(type + '_tag', method, value, options, self)
|
||||
BikeBikeFormHelper.render_field(type, method, options, html, value)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,729 @@
|
||||
|
||||
module FormHelper
|
||||
def off_screen(text, id = nil)
|
||||
content_tag(:span, text.html_safe, id: id, class: 'screen-reader-text')
|
||||
end
|
||||
|
||||
def translate_fields(object, field_options = {}, options = {})
|
||||
html = ''
|
||||
nav = ''
|
||||
|
||||
# set the selected locale
|
||||
selected_locale = (options[:locale] || object.locale || I18n.locale).to_sym
|
||||
|
||||
I18n.backend.enabled_locales.each do | locale |
|
||||
# ses if this should b the selected field
|
||||
class_name = selected_locale == locale.to_sym ? 'selected' : nil
|
||||
|
||||
# add the locale to the nav
|
||||
nav += content_tag(:li,
|
||||
content_tag(:a, _("languages.#{locale}"), href: 'javascript:void(0)'),
|
||||
class: class_name, data: { locale: locale }).html_safe
|
||||
|
||||
fields = ''
|
||||
field_options.each do | name, __options |
|
||||
_options = __options.deep_dup
|
||||
# add the field
|
||||
value = object.is_a?(Hash) ? object[locale.to_sym] : object.get_column_for_locale!(name, locale, false)
|
||||
|
||||
# use the default value if we need to
|
||||
if _options[:default].present? && value.blank?
|
||||
value = _(_options[:default], locale: locale)
|
||||
end
|
||||
|
||||
_options[:index] = locale
|
||||
_options[:lang] = locale
|
||||
_options[:parent_options] = { lang: locale }
|
||||
type = "#{_options[:type].to_s}"
|
||||
_options.delete(:type)
|
||||
|
||||
fields += self.send(type, name, value, _options).html_safe
|
||||
end
|
||||
|
||||
html += content_tag(:li, fields.html_safe, class: class_name, data: { locale: locale }).html_safe
|
||||
end
|
||||
|
||||
if options[:class].nil?
|
||||
options[:class] = []
|
||||
elsif options[:class].is_a?(String)
|
||||
options[:class] = [options[:class]]
|
||||
end
|
||||
options[:class] += ['translator', 'multi-field-translator']
|
||||
|
||||
(fieldset(nil, options) do
|
||||
content_tag(:ul, nav.html_safe, class: 'locale-select').html_safe +
|
||||
content_tag(:ul, html.html_safe, class: 'text-editors').html_safe
|
||||
end).html_safe
|
||||
end
|
||||
|
||||
def translate_textarea(name, object, property = nil, options = {})
|
||||
html = ''
|
||||
nav = ''
|
||||
|
||||
# see if options was passed in as property
|
||||
if options.blank? && property.is_a?(Hash)
|
||||
options = property
|
||||
property = nil
|
||||
end
|
||||
|
||||
# set the selected locale
|
||||
selected_locale = (options[:locale] || object.locale || I18n.locale).to_sym
|
||||
|
||||
I18n.backend.enabled_locales.each do | locale |
|
||||
# ses if this should b the selected field
|
||||
class_name = selected_locale == locale.to_sym ? 'selected' : nil
|
||||
|
||||
# add the locale to the nav
|
||||
nav += content_tag(:li,
|
||||
content_tag(:a, _("languages.#{locale}"), href: 'javascript:void(0)'),
|
||||
class: class_name, data: { locale: locale }).html_safe
|
||||
|
||||
# add the field
|
||||
value = object.is_a?(Hash) ? object[locale.to_sym] : object.get_column_for_locale!(name, locale, false)
|
||||
|
||||
# use the default value if we need to
|
||||
if options[:default].present? && value.blank?
|
||||
value = _(options[:default], locale: locale)
|
||||
end
|
||||
|
||||
html += content_tag(:li, textarea(name, value, {
|
||||
label: false,
|
||||
edit_on: options[:edit_on],
|
||||
parent_options: {
|
||||
lang: locale
|
||||
},
|
||||
index: locale
|
||||
}).html_safe, class: class_name, data: { locale: locale }).html_safe
|
||||
end
|
||||
|
||||
if options[:class].nil?
|
||||
options[:class] = []
|
||||
elsif options[:class].is_a?(String)
|
||||
options[:class] = [options[:class]]
|
||||
end
|
||||
options[:class] += ['translator']
|
||||
|
||||
(fieldset(name, options) do
|
||||
content_tag(:ul, nav.html_safe, class: 'locale-select').html_safe +
|
||||
content_tag(:ul, html.html_safe, class: 'text-editors').html_safe
|
||||
end).html_safe
|
||||
end
|
||||
|
||||
def textarea(name, value = nil, options = {})
|
||||
id = unique_id(name)
|
||||
label_id = "#{id}-label"
|
||||
description_id = nil
|
||||
html = ''
|
||||
|
||||
if options[:heading].present?
|
||||
label_id = "#{name.to_s}-label" unless options[:label]
|
||||
html += content_tag(:h3, _(options[:heading], :t, vars: options[:vars] || {}), id: label_id)
|
||||
end
|
||||
|
||||
if options[:label] == false
|
||||
label_id = options[:labelledby]
|
||||
elsif options[:label].present?
|
||||
html += label_tag([name, id], nil, id: label_id) do
|
||||
_(options[:label], :t, vars: options[:vars] || {})
|
||||
end
|
||||
else
|
||||
html += label_tag([name, id], nil, id: label_id)
|
||||
end
|
||||
|
||||
if options[:help].present?
|
||||
description_id ||= "#{id}-desc"
|
||||
html += content_tag(:div, _(options[:help], :s, 2), id: description_id, class: 'input-field-help')
|
||||
end
|
||||
|
||||
if options[:warning].present?
|
||||
description_id ||= "#{id}-desc"
|
||||
html += content_tag(:div, _(options[:warning], :s, 2), id: description_id, class: 'warning-info')
|
||||
end
|
||||
|
||||
aria = {}
|
||||
aria[:labelledby] = label_id if label_id.present?
|
||||
aria[:describedby] = description_id if description_id.present?
|
||||
css_class = [
|
||||
options[:short] === true ? :short : nil
|
||||
].compact
|
||||
|
||||
html_name = name.to_s + (options[:index] ? "[#{options[:index]}]" : '')
|
||||
if options[:plain]
|
||||
html += (text_area_tag html_name, value,
|
||||
id: id,
|
||||
lang: options[:lang],
|
||||
aria: aria,
|
||||
class: css_class
|
||||
)
|
||||
else
|
||||
html += content_tag(:div, value.present? ? value.html_safe : '',
|
||||
id: id,
|
||||
data: { name: html_name, 'edit-on': options[:edit_on] || :load },
|
||||
lang: options[:lang],
|
||||
aria: aria,
|
||||
tabindex: 0,
|
||||
class: [:textarea] + css_class
|
||||
)
|
||||
|
||||
add_stylesheet :editor
|
||||
add_inline_script :pen
|
||||
add_inline_script :markdown
|
||||
add_inline_script :editor
|
||||
end
|
||||
|
||||
parent_options = options[:parent_options] || {}
|
||||
if parent_options[:class].nil?
|
||||
parent_options[:class] = []
|
||||
elsif parent_options[:class].is_a?(String)
|
||||
parent_options[:class] = [parent_options[:class]]
|
||||
end
|
||||
|
||||
parent_options[:class] += ['text-area-field', 'input-field']
|
||||
html = content_tag(:div, html.html_safe, parent_options).html_safe
|
||||
html += _original_content(options[:original_value], options[:original_lang]) if options[:original_value].present?
|
||||
|
||||
return html.html_safe
|
||||
end
|
||||
|
||||
def fieldset(name = nil, options = {}, &block)
|
||||
html = ''
|
||||
label = ''
|
||||
description = ''
|
||||
description_id = nil
|
||||
errors = ''
|
||||
|
||||
if name.present?
|
||||
if options[:label] != false
|
||||
label = content_tag(:legend,
|
||||
_((
|
||||
options[:label].is_a?(String) ?
|
||||
options[:label] :
|
||||
"forms.labels.generic.#{name}"), :t, vars: options[:vars] || {}))
|
||||
end
|
||||
|
||||
if options[:help].present?
|
||||
description_id = unique_id("#{name.to_s}-desc")
|
||||
description = content_tag(:div, _(options[:help], :s, 2), class: 'input-field-help', id: description_id)
|
||||
end
|
||||
|
||||
errors = (show_errors name)
|
||||
end
|
||||
|
||||
html = label + errors + description + content_tag(:div, class: :fieldgroup, &block)
|
||||
|
||||
aria = description_id.present? ? { describedby: description_id } : nil
|
||||
(content_tag(:fieldset, html.html_safe,
|
||||
aria: aria,
|
||||
class: ((options[:class] || []) + [
|
||||
options[:inline] ? :inline : nil,
|
||||
options[:inline_label] ? 'inline-label' : nil,
|
||||
errors.present? ? 'has-error' : nil
|
||||
]).compact
|
||||
)
|
||||
).html_safe
|
||||
end
|
||||
|
||||
def selectfield(name, value, select_options, options = {})
|
||||
unless select_options.first.is_a?(Array)
|
||||
so = select_options
|
||||
select_options = []
|
||||
so.each do | opt |
|
||||
select_options << [ I18n.t("forms.options.#{name.to_s}.#{opt.to_s}"), opt]
|
||||
end
|
||||
end
|
||||
textfield(name, value, options.merge({type: :select, options: select_options}))
|
||||
end
|
||||
|
||||
def telephonefield(name, value, options = {})
|
||||
textfield(name, value, options.merge({type: :telephone}))
|
||||
end
|
||||
|
||||
def numberfield(name, value, options = {})
|
||||
textfield(name, value, options.merge({type: :number}))
|
||||
end
|
||||
|
||||
def searchfield(name, value, options = {})
|
||||
textfield(name, value, options.merge({type: :search}))
|
||||
end
|
||||
|
||||
def userfield(name, value, options = {})
|
||||
# eventually this will be a dynamic field to find users, for now we'll just use emails
|
||||
# add_inline_script :userfield
|
||||
emailfield(name, value, options)# .merge({
|
||||
# parent_options: { class: ['user-field'] },
|
||||
# after: content_tag(:div, '', class: 'user-name')
|
||||
# }))
|
||||
end
|
||||
|
||||
def emailfield(name, value, options = {})
|
||||
textfield(name, value, options.merge({type: :email}))
|
||||
end
|
||||
|
||||
def filefield(name, value, options = {})
|
||||
textfield(name, value, options.merge({type: :file}))
|
||||
end
|
||||
|
||||
def passwordfield(name, value, options = {})
|
||||
textfield(name, value, options.merge({type: :password}))
|
||||
end
|
||||
|
||||
def textfield(name, value, options = {})
|
||||
html = ''
|
||||
id = unique_id(name)
|
||||
html_name = name.to_s + (options[:index] ? "[#{options[:index]}]" : '')
|
||||
description_id = nil
|
||||
|
||||
if options[:heading].present?
|
||||
description_id ||= "#{id.to_s}-desc"
|
||||
html += content_tag(:h3, _(options[:heading], :t, vars: options[:vars] || {}), id: description_id)
|
||||
end
|
||||
|
||||
if options[:help].present?
|
||||
description_id ||= "#{id.to_s}-desc"
|
||||
html += content_tag(:div, _(options[:help], :s, 2, vars: options[:vars] || {}), class: 'input-field-help', id: description_id)
|
||||
end
|
||||
|
||||
html += show_errors name, value
|
||||
|
||||
inside_label = ''
|
||||
|
||||
if options[:type] == :file
|
||||
inside_label = (content_tag(:div, class: 'file-field-selector') do
|
||||
(options[:preview] ? content_tag(:img, nil, src: value.present? ? value.url : nil).html_safe : '').html_safe +
|
||||
content_tag(:div, (value.present? ? File.basename(value.url) : (_'forms.labels.generic.no_file_selected')), class: 'file-field-name ' + (value.present? ? 'selected' : 'unselected')).html_safe +
|
||||
content_tag(:a, (_'forms.actions.generic.select_file'), class: :button)
|
||||
end)
|
||||
end
|
||||
|
||||
label_text = nil
|
||||
if options[:label].present?
|
||||
label_text = _(options[:label], :t, vars: options[:vars] || {})
|
||||
elsif options[:label] != false
|
||||
label_text = (_"forms.labels.generic.#{name}")
|
||||
elsif options[:type] == :select || options[:type] == :file
|
||||
# add an empty label so that the drop down button will still appear
|
||||
label_text = ''
|
||||
end
|
||||
|
||||
label_options = {}
|
||||
# let the label be selected if the input is hidden
|
||||
label_options[:tabindex] = 0 if options[:type] == :file
|
||||
|
||||
unless label_text.nil?
|
||||
html += label_tag id, (label_text + inside_label).html_safe
|
||||
end
|
||||
|
||||
input_options = {
|
||||
id: id,
|
||||
required: options[:required],
|
||||
lang: options[:lang],
|
||||
min: options[:min],
|
||||
max: options[:max],
|
||||
step: options[:step],
|
||||
aria: description_id ? { describedby: description_id } : nil
|
||||
}
|
||||
|
||||
case name
|
||||
when :address
|
||||
input_options[:autocomplete] = 'address-line1'
|
||||
when :name
|
||||
input_options[:autocomplete] = 'name'
|
||||
when :location
|
||||
input_options[:autocomplete] = 'address-level2'
|
||||
when :email
|
||||
input_options[:autocomplete] = 'email'
|
||||
when :phone
|
||||
input_options[:autocomplete] = 'tel'
|
||||
when :paypal_email_address, :paypal_username, :paypal_password, :paypal_signature
|
||||
input_options[:autocomplete] = 'off'
|
||||
end
|
||||
|
||||
case options[:type]
|
||||
when :select
|
||||
option_list = options_for_select(options[:options], value)
|
||||
|
||||
# make sure that we have an empty option if the select is required
|
||||
if options[:required] && options[:options].first.present? && options[:options].first.last.present?
|
||||
option_list = ('<option value=""> </option>' + option_list).html_safe
|
||||
end
|
||||
html += select_tag(html_name, option_list, input_options)
|
||||
when :file
|
||||
add_inline_script :filefield
|
||||
input_options[:tabindex] = '-1'
|
||||
html += off_screen(file_field_tag html_name, input_options)
|
||||
else
|
||||
input_options[:autocomplete] = 'off' if options[:type] == :search
|
||||
html += send("#{(options[:type] || :text).to_s}_field_tag", html_name, value, input_options)
|
||||
end
|
||||
|
||||
if options[:after].present?
|
||||
html += options[:after].html_safe
|
||||
end
|
||||
|
||||
html = content_tag(:div, html.html_safe,
|
||||
class: [
|
||||
"#{(options[:type] || :text).to_s}-field",
|
||||
'input-field',
|
||||
value.present? ? nil : 'empty',
|
||||
options[:big] ? 'big' : nil,
|
||||
options[:small] ? 'small' : nil,
|
||||
options[:stretch] ? 'stretch-item' : nil,
|
||||
options[:full] ? 'full' : nil,
|
||||
options[:inline_label] ? 'inline-label' : nil,
|
||||
(@errors || {})[name].present? ? 'has-error' : nil
|
||||
].compact + (((options[:parent_options] || {})[:class]) || []))
|
||||
|
||||
html += _original_content(options[:original_value], options[:original_lang]) if options[:original_value].present?
|
||||
|
||||
return html.html_safe
|
||||
end
|
||||
|
||||
def radiobuttons(name, boxes, value, label_key, options = {})
|
||||
checkboxes(name, boxes, [value], label_key, options.merge({radiobuttons: true}))
|
||||
end
|
||||
|
||||
def checkbox(name, value, label_key, options = {})
|
||||
checkboxes(name, [true], value, label_key, options)
|
||||
end
|
||||
|
||||
def unique_id(id)
|
||||
id = id.to_s.gsub('[', '_').gsub(']', '')
|
||||
|
||||
@_ids ||= {}
|
||||
@_ids[id] ||= 0
|
||||
|
||||
new_id = id
|
||||
|
||||
if @_ids[id] > 0
|
||||
new_id += "--#{@_ids[id]}"
|
||||
end
|
||||
|
||||
@_ids[id] += 1
|
||||
|
||||
return new_id
|
||||
end
|
||||
|
||||
def checkboxes(name, boxes, values, label_key, options = {})
|
||||
html = ''
|
||||
boxes.map! { |box| box.is_a?(String) ? box.to_sym : box }
|
||||
values.map! { |value| value.is_a?(String) ? value.to_sym : value } if values.is_a?(Array)
|
||||
|
||||
label_id = nil
|
||||
description_id = nil
|
||||
|
||||
if options[:heading].present?
|
||||
label_id ||= unique_id("#{name.to_s}-label")
|
||||
html += content_tag(:h3, _(options[:heading], :t, vars: options[:vars] || {}), id: label_id)
|
||||
end
|
||||
|
||||
help = nil
|
||||
|
||||
if options[:help].present?
|
||||
description_id ||= unique_id("#{name.to_s}-desc")
|
||||
help = content_tag(:div, _(options[:help], :s, 2), class: 'input-field-help', id: description_id)
|
||||
end
|
||||
|
||||
html += help if help.present? && !options[:right_help]
|
||||
|
||||
boxes_html = ''
|
||||
|
||||
labels = nil
|
||||
is_single = !values.is_a?(Array)
|
||||
if boxes.length > 0
|
||||
if boxes.first.is_a?(Array)
|
||||
labels = boxes.map(&:first)
|
||||
boxes = boxes.map(&:last)
|
||||
end
|
||||
elsif !boxes.first.is_a?(Integer)
|
||||
values = values.present? ? values.map(&:to_s) : [] unless is_single
|
||||
boxes = boxes.map(&:to_s)
|
||||
end
|
||||
|
||||
# convert the required value into a pure boolean
|
||||
required = !!options[:required]
|
||||
|
||||
boxes.each_with_index do |box, i|
|
||||
checked = (is_single ? values.present? : values.include?(box))
|
||||
values -= [box] if checked && !is_single
|
||||
id = nil
|
||||
if options[:radiobuttons].present?
|
||||
id = unique_id("#{name.to_s}_#{box}")
|
||||
boxes_html += radio_button_tag(name, box, checked, id: id, required: required)
|
||||
else
|
||||
_name = (is_single ? name : "#{name.to_s}[#{box}]")
|
||||
id = unique_id(_name)
|
||||
boxes_html += check_box_tag(_name, 1, checked, data: { toggles: options[:toggles] }.compact, id: id, required: required)
|
||||
end
|
||||
|
||||
# we only need the required attribute on one element
|
||||
required = false
|
||||
|
||||
if labels.present?
|
||||
label = labels[i]
|
||||
elsif is_single
|
||||
label = _(label_key.to_s)
|
||||
elsif box.is_a?(Integer)
|
||||
label = I18n.t(label_key.to_s)[box]
|
||||
else
|
||||
label = _("#{label_key.to_s}.#{box}")
|
||||
end
|
||||
|
||||
boxes_html += label_tag(id, label)
|
||||
end
|
||||
|
||||
if options[:other].present? && !is_single
|
||||
id = nil
|
||||
if options[:radiobuttons].present?
|
||||
id = unique_id("#{name.to_s}_other")
|
||||
boxes_html += radio_button_tag(name, :other, values.present?, id: id)
|
||||
else
|
||||
_name = "#{name.to_s}[other]"
|
||||
id = unique_id(_name)
|
||||
boxes_html += check_box_tag(_name, 1, values.present?, id: id)
|
||||
end
|
||||
boxes_html += label_tag id,
|
||||
content_tag(:div,
|
||||
text_field_tag("other_#{name.to_s}", values.first, placeholder: (_"#{label_key}.other"), required: values.present?),
|
||||
class: 'other')
|
||||
end
|
||||
|
||||
html += content_tag(:fieldset, content_tag(:div, boxes_html.html_safe,
|
||||
class: [
|
||||
'check-box-field',
|
||||
'input-field',
|
||||
options[:vertical] ? 'vertical' : nil,
|
||||
options[:inline] ? 'inline' : nil,
|
||||
options[:small] ? 'small' : nil,
|
||||
options[:big] ? 'big' : nil
|
||||
].compact).html_safe,
|
||||
aria: {
|
||||
labelledby: label_id,
|
||||
describedby: description_id
|
||||
},
|
||||
class: [
|
||||
options[:centered] ? 'centered' : nil,
|
||||
options[:right_help] ? 'right-help' : nil
|
||||
].compact
|
||||
)
|
||||
|
||||
html += help if help.present? && options[:right_help]
|
||||
|
||||
return html.html_safe
|
||||
end
|
||||
|
||||
def button(value = nil, options = {}, &block)
|
||||
if !block_given? && (value.nil? || value.is_a?(Symbol))
|
||||
return button_tag(I18n.t("forms.actions.generic.#{(value || :button)}"), options)
|
||||
end
|
||||
|
||||
button_tag(value, options, &block)
|
||||
end
|
||||
|
||||
def conference_days_options(conference = nil)
|
||||
conference ||= @this_conference || @conference
|
||||
return [] unless conference
|
||||
|
||||
dates = []
|
||||
day = conference.start_date - 7.days
|
||||
last_day = conference.end_date + 7.days
|
||||
|
||||
while day <= last_day
|
||||
dates << day
|
||||
day += 1.day
|
||||
end
|
||||
|
||||
return dates
|
||||
end
|
||||
|
||||
def conference_days_options_list(period, conference = nil, format = nil)
|
||||
conference ||= @this_conference || @conference
|
||||
return [] unless conference
|
||||
|
||||
days = []
|
||||
|
||||
conference_days_options(conference).each do |day|
|
||||
belongs_to_periods = []
|
||||
belongs_to_periods << :before if day <= conference.start_date
|
||||
belongs_to_periods << :after if day >= conference.end_date
|
||||
belongs_to_periods << :before_plus_one if day <= (conference.start_date + 1.day)
|
||||
belongs_to_periods << :after_minus_one if day >= (conference.end_date - 1.day)
|
||||
belongs_to_periods << :during if day >= conference.start_date && day <= conference.end_date
|
||||
days << [date(day.to_date, format || :span_same_year_date_1), day.to_date] if belongs_to_periods.include?(period)
|
||||
end
|
||||
return days
|
||||
end
|
||||
|
||||
def registration_status_options_list(conference = nil)
|
||||
conference ||= @this_conference || @conference
|
||||
return [] unless conference
|
||||
|
||||
options = Array.new
|
||||
[:closed, :pre, :open].each do | opt |
|
||||
options << [(_"forms.labels.generic.registration_statuses.#{opt}"), opt]
|
||||
end
|
||||
|
||||
return options
|
||||
end
|
||||
|
||||
def month_select(value = nil, args = {})
|
||||
options = (1..12).to_a.map { |month| [ (I18n.t "date.#{args[:format] || 'month_names'}")[month], month ] }
|
||||
selectfield args[:name] || :month, value, options, args
|
||||
end
|
||||
|
||||
def month_day_select(value = nil, args = {})
|
||||
options = (1..31).to_a.map { |day| [ day, day ] }
|
||||
selectfield args[:name] || :month_day, value, options, args
|
||||
end
|
||||
|
||||
def day_select(value = nil, args = {})
|
||||
selectfield :day, value, conference_days_options_list(:during, nil, args[:format]), args
|
||||
end
|
||||
|
||||
def hour_select(value = nil, args = {}, start_time = 8, end_time = 23.5, step = 0.5)
|
||||
time = start_time
|
||||
times = []
|
||||
while time <= end_time
|
||||
times << [time(DateTime.now.midnight + time.hours), time]
|
||||
time += step
|
||||
end
|
||||
selectfield :time, value, times, args
|
||||
end
|
||||
|
||||
def length_select(value = nil, args = {}, min_length = 0.5, max_length = 6, step = 0.5)
|
||||
length = min_length
|
||||
lengths = []
|
||||
while length <= max_length
|
||||
lengths << [time_length(length), length]
|
||||
length += step
|
||||
end
|
||||
selectfield :time_span, value, lengths, args
|
||||
end
|
||||
|
||||
def contact_reason_select
|
||||
reasons = []
|
||||
[:website, :conference].each do | reason |
|
||||
reasons << [ _("forms.labels.generic.reasons.#{reason.to_s}"), reason ]
|
||||
end
|
||||
[['Something about the website', :website]]
|
||||
selectfield :reason, nil, reasons, required: true, heading: 'articles.contact.headings.reason', label: false, full: true
|
||||
end
|
||||
|
||||
def block_select(value = nil, args = {})
|
||||
blocks = {}
|
||||
@workshop_blocks.each_with_index do | info, block |
|
||||
info['days'].each do | day |
|
||||
blocks[(day.to_i * 10) + block] = [ "#{(I18n.t 'date.day_names')[day.to_i]} Block #{block + 1}", "#{day}:#{block}" ]
|
||||
end
|
||||
end
|
||||
selectfield :workshop_block, value, blocks.sort.to_h.values, args
|
||||
end
|
||||
|
||||
def location_select(value = nil, args = {})
|
||||
locations = []
|
||||
if @this_conference.event_locations.present?
|
||||
@this_conference.event_locations.each do | location |
|
||||
locations << [ location.title, location.id ] unless ((args[:invalid_locations] || []).include? location.id)
|
||||
end
|
||||
end
|
||||
selectfield :event_location, value, locations, args
|
||||
end
|
||||
|
||||
def location_name(id)
|
||||
begin
|
||||
location = EventLocation.find(id)
|
||||
rescue
|
||||
return ''
|
||||
end
|
||||
return '' unless location.present?
|
||||
return location.title
|
||||
end
|
||||
|
||||
def host_options_list(hosts)
|
||||
options = [[nil, nil]]
|
||||
hosts.each do | id, registration |
|
||||
options << [registration.user.name, id]
|
||||
end
|
||||
return options
|
||||
end
|
||||
|
||||
def registration_step_menu
|
||||
steps = current_registration_steps(@registration)
|
||||
return '' unless steps.present? && steps.length > 1
|
||||
|
||||
pre_registration_steps = ''
|
||||
post_registration_steps = ''
|
||||
post_registration = false
|
||||
|
||||
steps.each do | step |
|
||||
text = _"articles.conference_registration.headings.#{step[:name].to_s}"
|
||||
|
||||
if step[:name] == :workshops
|
||||
post_registration = true
|
||||
end
|
||||
|
||||
h = content_tag :li, class: [step[:enabled] ? :enabled : nil, @register_template == step[:name] ? :current : nil, post_registration ? :post : :pre].compact do
|
||||
if step[:enabled]
|
||||
content_tag :div, (link_to text, register_step_path(@this_conference.slug, step[:name])).html_safe, class: :step
|
||||
else
|
||||
content_tag :div, text, class: :step
|
||||
end
|
||||
end
|
||||
|
||||
if post_registration
|
||||
post_registration_steps += h.html_safe
|
||||
else
|
||||
pre_registration_steps += h.html_safe
|
||||
end
|
||||
end
|
||||
|
||||
html = (
|
||||
row class: 'flow-steps' do
|
||||
columns do
|
||||
(content_tag :ul, id: 'registration-steps' do
|
||||
pre_registration_steps.html_safe +
|
||||
post_registration_steps.html_safe
|
||||
end).html_safe
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
return html.html_safe
|
||||
end
|
||||
|
||||
def broadcast_options(conference = nil)
|
||||
conference ||= @this_conference || @conference
|
||||
|
||||
options = [
|
||||
:registered,
|
||||
:pre_registered,
|
||||
:workshop_facilitators,
|
||||
:unregistered,
|
||||
:housing_providers,
|
||||
:guests,
|
||||
:all
|
||||
]
|
||||
|
||||
if conference.registration_status != :open
|
||||
options -= [:registered, :guests]
|
||||
options -= [:pre_registered] unless conference.registration_status != :pre
|
||||
end
|
||||
|
||||
return options
|
||||
end
|
||||
|
||||
def show_errors(field, value = nil)
|
||||
return '' unless @errors && @errors[field].present?
|
||||
|
||||
error_txt = _"errors.messages.fields.#{field.to_s}.#{@errors[field]}", :s, vars: { value: value }
|
||||
|
||||
content_tag(:div, error_txt, class: 'field-error').html_safe
|
||||
end
|
||||
|
||||
private
|
||||
def _original_content(value, lang)
|
||||
content_tag(:div, (
|
||||
content_tag(:h4, _('translate.content.Translation_of')) +
|
||||
content_tag(:div, value, class: 'value', lang: lang)
|
||||
).html_safe, class: 'original-text')
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,100 @@
|
||||
module GeocoderHelper
|
||||
def lookup_ip
|
||||
if request.remote_ip == '127.0.0.1' || request.remote_ip == '::1'
|
||||
session['remote_ip'] || (session['remote_ip'] = open("http://checkip.dyndns.org").first.gsub(/^.*\s([\d\.]+).*$/s, '\1').gsub(/[^\.\d]/, ''))
|
||||
else
|
||||
request.remote_ip
|
||||
end
|
||||
end
|
||||
|
||||
def get_remote_location
|
||||
Geocoder.search(session['remote_ip'] || (session['remote_ip'] = open("http://checkip.dyndns.org").first.gsub(/^.*\s([\d\.]+).*$/s, '\1').gsub(/[^\.\d]/, '')), language: 'en').first
|
||||
end
|
||||
|
||||
def lookup_ip_location
|
||||
begin
|
||||
if is_test? && ApplicationController::get_location.present?
|
||||
Geocoder.search(ApplicationController::get_location, language: 'en').first
|
||||
elsif request.remote_ip == '127.0.0.1' || request.remote_ip == '::1'
|
||||
get_remote_location
|
||||
else
|
||||
request.location || get_remote_location
|
||||
end
|
||||
rescue
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def potential_provider(registration)
|
||||
return false unless registration.present? && registration.city.present? && registration.conference.present?
|
||||
conditions = registration.conference.provider_conditions ||
|
||||
Conference.default_provider_conditions
|
||||
return city_distance_less_than(registration.conference.city, registration.city,
|
||||
conditions['distance']['number'], conditions['distance']['unit'])
|
||||
end
|
||||
|
||||
def city_distance_less_than(city1, city2, max_distance, unit)
|
||||
return false if city1.nil? || city2.nil?
|
||||
return true if city1.id == city2.id
|
||||
return false if max_distance < 1
|
||||
return Geocoder::Calculations.distance_between(
|
||||
[city1.latitude, city1.longitude], [city2.latitude, city2.longitude],
|
||||
units: unit.to_sym) < max_distance
|
||||
end
|
||||
|
||||
def location(location, locale = I18n.locale)
|
||||
return nil if location.blank?
|
||||
|
||||
city = nil
|
||||
region = nil
|
||||
country = nil
|
||||
if location.is_a?(Location) || location.is_a?(City)
|
||||
country = location.country
|
||||
region = location.territory
|
||||
city = location.city
|
||||
elsif location.data.present? && location.data['address_components'].present?
|
||||
component_map = {
|
||||
'locality' => :city,
|
||||
'administrative_area_level_1' => :region,
|
||||
'country' => :country
|
||||
}
|
||||
location.data['address_components'].each do | component |
|
||||
types = component['types']
|
||||
country = component['short_name'] if types.include? 'country'
|
||||
region = component['short_name'] if types.include? 'administrative_area_level_1'
|
||||
city = component['long_name'] if types.include? 'locality'
|
||||
end
|
||||
else
|
||||
country = location.data['country_code']
|
||||
region = location.data['region_code']
|
||||
city = location.data['city']
|
||||
end
|
||||
|
||||
# we need cities for our logic, don't let this continue if we don't have one
|
||||
return nil unless city.present?
|
||||
|
||||
hash = Hash.new
|
||||
region_translation = region.present? && country.present? ? _("geography.subregions.#{country}.#{region}", locale: locale) : ''
|
||||
country_translation = country.present? ? _("geography.countries.#{country}", locale: locale) : ''
|
||||
hash[:city] = _!(city) if city.present?
|
||||
hash[:region] = region_translation if region_translation.present?
|
||||
hash[:country] = country_translation if country_translation.present?
|
||||
|
||||
# return the formatted location or the first value if we only have one value
|
||||
return hash.length > 1 ? _("geography.formats.#{hash.keys.join('_')}", locale: locale, vars: hash) : hash.values.first
|
||||
end
|
||||
|
||||
def location_link(location)
|
||||
return '' unless location.present? && location.address.present?
|
||||
content_tag(:a, (_!location.address), href: "http://www.google.com/maps/place/#{location.latitude},#{location.longitude}")
|
||||
end
|
||||
|
||||
def same_city?(location1, location2)
|
||||
return false unless location1.present? && location2.present?
|
||||
|
||||
location1 = location(location1) unless location1.is_a?(String)
|
||||
location2 = location(location2) unless location2.is_a?(String)
|
||||
|
||||
location1.eql? location2
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,74 @@
|
||||
|
||||
module I18nHelper
|
||||
def url_for_locale(locale, url = nil)
|
||||
return url unless locale.present?
|
||||
|
||||
unless url.present?
|
||||
new_params = params.merge({action: (params[:_original_action] || params[:action])})
|
||||
new_params.delete(:_original_action)
|
||||
|
||||
if Rails.env.development? || Rails.env.test?
|
||||
return url_for(new_params.merge({lang: locale.to_s}))
|
||||
end
|
||||
|
||||
subdomain = Rails.env.preview? ? "preview-#{locale.to_s}" : locale.to_s
|
||||
return url_for(new_params.merge(host: "#{subdomain}.bikebike.org"))
|
||||
end
|
||||
|
||||
return url if Rails.env.development? || Rails.env.test?
|
||||
return "https://preview-#{locale.to_s}.bikebike.org#{url}" if Rails.env.preview?
|
||||
"https://#{locale.to_s}.bikebike.org#{url}"
|
||||
end
|
||||
|
||||
def date(date, format = :long)
|
||||
I18n.l(date.is_a?(String) ? Date.parse(date) : date, :format => format)
|
||||
end
|
||||
|
||||
def time(time, format = :short)
|
||||
if time.is_a?(String)
|
||||
time = Date.parse(time)
|
||||
elsif time.is_a?(Float) || time.is_a?(Integer)
|
||||
time = DateTime.now.midnight + time.hours
|
||||
end
|
||||
|
||||
I18n.l(time, format: format)
|
||||
end
|
||||
|
||||
def date_span(date1, date2)
|
||||
key = 'same_month'
|
||||
if date1.year != date2.year
|
||||
key = 'different_year'
|
||||
elsif date1.month != date2.month
|
||||
key = 'same_year'
|
||||
end
|
||||
d1 = I18n.l(date1.to_date, format: "span_#{key}_date_1".to_sym)
|
||||
d2 = I18n.l(date2.to_date, format: "span_#{key}_date_2".to_sym)
|
||||
_('date.date_span', vars: {:date_1 => d1, :date_2 => d2})
|
||||
end
|
||||
|
||||
def time_length(length)
|
||||
hours = length.to_i
|
||||
minutes = ((length - hours) * 60).to_i
|
||||
hours = hours > 0 ? (I18n.t 'datetime.distance_in_words.x_hours', count: hours) : nil
|
||||
minutes = minutes > 0 ? (I18n.t 'datetime.distance_in_words.x_minutes', count: minutes) : nil
|
||||
return hours.present? ? (minutes.present? ? (I18n.t 'datetime.distance_in_words.x_and_y', x: hours, y: minutes) : hours) : minutes
|
||||
end
|
||||
|
||||
def hour_span(time1, time2)
|
||||
(time2 - time1) / 3600
|
||||
end
|
||||
|
||||
def hours(time1, time2)
|
||||
time_length hour_span(time1, time2)
|
||||
end
|
||||
|
||||
def money(amount)
|
||||
return _!('$0.00') if amount == 0
|
||||
_!((amount * 100).to_i.to_s.gsub(/^(.*)(\d\d)$/, '$\1.\2'))
|
||||
end
|
||||
|
||||
def percent(p)
|
||||
return _!('0.00%') if p == 0
|
||||
_!((p * 10000).to_i.to_s.gsub(/^(.*)(\d\d)$/, '\1.\2%'))
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,88 @@
|
||||
|
||||
module PageHelper
|
||||
@@no_banner = true
|
||||
@@banner_image = nil
|
||||
@@has_content = true
|
||||
@@body_class = nil
|
||||
|
||||
def title(page_title)
|
||||
content_for(:title) { page_title.to_s }
|
||||
end
|
||||
|
||||
def description(page_description)
|
||||
content_for(:description) { page_description.to_s }
|
||||
end
|
||||
|
||||
def banner_image(banner_image, name: nil, id: nil, user_id: nil, src: nil)
|
||||
@@no_banner = false
|
||||
@@banner_image = banner_image
|
||||
content_for(:banner_image) { banner_image.to_s }
|
||||
end
|
||||
|
||||
def has_content?
|
||||
@@has_content
|
||||
end
|
||||
|
||||
def add_stylesheet(sheet)
|
||||
@stylesheets ||= []
|
||||
@stylesheets << sheet unless @stylesheets.include?(sheet)
|
||||
end
|
||||
|
||||
def stylesheets
|
||||
html = ''
|
||||
Rack::MiniProfiler.step('inject_css') do
|
||||
html += inject_css!
|
||||
end
|
||||
(@stylesheets || []).each do |css|
|
||||
Rack::MiniProfiler.step("inject_css #{css}") do
|
||||
html += inject_css! css.to_s
|
||||
end
|
||||
end
|
||||
html += stylesheet_link_tag 'i18n-debug' if request.params['i18nDebug']
|
||||
return html.html_safe
|
||||
end
|
||||
|
||||
def add_inline_script(script)
|
||||
@_inline_scripts ||= []
|
||||
script = Rails.application.assets.find_asset("#{script.to_s}.js").to_s
|
||||
@_inline_scripts << script unless @_inline_scripts.include?(script)
|
||||
end
|
||||
|
||||
def inline_scripts
|
||||
return '' unless @_inline_scripts.present?
|
||||
"<script>#{@_inline_scripts.join("\n")}</script>".html_safe
|
||||
end
|
||||
|
||||
def dom_ready(&block)
|
||||
content_for(:dom_ready, &block)
|
||||
end
|
||||
|
||||
def body_class(c)
|
||||
@@body_class ||= Array.new
|
||||
@@body_class << (c.is_a?(Array) ? c.join(' ') : c)
|
||||
end
|
||||
|
||||
def page_style
|
||||
classes = Array.new
|
||||
|
||||
classes << 'no-content' unless @@has_content
|
||||
classes << 'has-banner-image' if @@banner_image
|
||||
classes << @@body_class.join(' ') if @@body_class
|
||||
|
||||
if params[:controller]
|
||||
classes << params[:action]
|
||||
unless params[:controller] == 'application'
|
||||
classes << params[:controller]
|
||||
|
||||
if params[:action]
|
||||
classes << "#{params[:controller]}-#{params[:action]}"
|
||||
end
|
||||
end
|
||||
end
|
||||
return classes
|
||||
end
|
||||
|
||||
def yield_or_default(section, default = '')
|
||||
content_for?(section) ? content_for(section) : default
|
||||
end
|
||||
end
|
||||
@@ -1,4 +1,16 @@
|
||||
module RegistrationHelper
|
||||
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 registration.status
|
||||
end
|
||||
|
||||
def current_registration_steps(registration = @registration)
|
||||
return nil unless registration.present?
|
||||
|
||||
@@ -6,32 +18,36 @@ module RegistrationHelper
|
||||
current_steps = []
|
||||
disable_steps = false
|
||||
completed_steps = registration.steps_completed || []
|
||||
# registration_complete = registration_complete?(registration)
|
||||
|
||||
if potential_provider(registration)
|
||||
steps -= [:questions]
|
||||
else
|
||||
steps -= [:hosting]
|
||||
end
|
||||
|
||||
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'
|
||||
|
||||
steps.each do | step |
|
||||
steps.each do |step|
|
||||
# disable the step if we've already found an incomplete step
|
||||
enabled = !disable_steps# || registration_complete
|
||||
# enabled = !disable_steps# || registration_complete
|
||||
# record whether or not we've found an incomplete step
|
||||
disable_steps ||= !completed_steps.include?(step.to_s) && ![:payment, :workshops].include?(step)
|
||||
|
||||
current_steps << {
|
||||
name: step,
|
||||
enabled: enabled
|
||||
enabled: !disable_steps
|
||||
}
|
||||
disable_steps ||= !completed_steps.include?(step.to_s)# && ![:payment, :workshops].include?(step)
|
||||
end
|
||||
|
||||
return current_steps
|
||||
end
|
||||
|
||||
def current_step(registration = @registration)
|
||||
completed_steps = registration.steps_completed || []
|
||||
last_step = nil
|
||||
(current_registration_steps(registration) || []).each do | step |
|
||||
steps = current_registration_steps(registration) || []
|
||||
steps.each do | step |
|
||||
# return the last enabled step if this one is disabled
|
||||
return last_step unless step[:enabled]
|
||||
|
||||
@@ -43,6 +59,6 @@ module RegistrationHelper
|
||||
end
|
||||
|
||||
# if all else fails, return the first step
|
||||
return registration_steps(registration.conference).last
|
||||
return steps.last[:name]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,366 @@
|
||||
module TableHelper
|
||||
def html_edit_table(excel_data, options = {})
|
||||
attributes = { class: options[:class], id: options[:id] }
|
||||
attributes[:data] = { 'update-url' => options[:editable] } if options[:editable].present?
|
||||
|
||||
if options[:column_names].is_a? Hash
|
||||
return content_tag(:table, attributes) do
|
||||
max_columns = 0
|
||||
column_names = {}
|
||||
(content_tag(:thead) do
|
||||
headers = ''
|
||||
options[:column_names].each do | header_name, columns |
|
||||
column_names[header_name] ||= []
|
||||
headers += content_tag(:th, excel_data[:keys][header_name].present? ? _(excel_data[:keys][header_name]) : '', colspan: 2)
|
||||
row_count = columns.size
|
||||
columns.each do | column |
|
||||
column_names[header_name] << column
|
||||
if (options[:row_spans] || {})[column].present?
|
||||
row_count += (options[:row_spans][column] - 1)
|
||||
for i in 1...options[:row_spans][column]
|
||||
column_names[header_name] << false
|
||||
end
|
||||
end
|
||||
end
|
||||
max_columns = row_count if row_count > max_columns
|
||||
end
|
||||
content_tag(:tr, headers.html_safe)
|
||||
end) + (content_tag(:tbody) do
|
||||
rows = ''
|
||||
|
||||
for i in 0...max_columns
|
||||
columns_html = ''
|
||||
column_names.each do | header_name, columns |
|
||||
column = columns[i]
|
||||
if column.present?
|
||||
attributes = { class: [excel_data[:column_types][column]], data: { 'column-id' => column } }
|
||||
if (options[:row_spans] || {})[column].present?
|
||||
attributes[:rowspan] = options[:row_spans][column]
|
||||
end
|
||||
columns_html += content_tag(:th, excel_data[:keys][column].present? ? _(excel_data[:keys][column]) : '', rowspan: attributes[:rowspan]) +
|
||||
edit_column(nil, column, nil, attributes, excel_data, options)
|
||||
elsif column != false
|
||||
columns_html += content_tag(:td, ' ', colspan: 2, class: :empty)
|
||||
end
|
||||
end
|
||||
rows += content_tag(:tr, columns_html.html_safe, { class: 'always-edit', data: { key: '' } })
|
||||
end
|
||||
rows.html_safe
|
||||
end)
|
||||
end
|
||||
else
|
||||
return content_tag(:table, attributes) do
|
||||
(content_tag(:tbody) do
|
||||
rows = ''
|
||||
excel_data[:columns].each do |column|
|
||||
if (excel_data[:column_types] || {})[column] != :table && ((options[:column_names] || []).include? column)
|
||||
rows += content_tag(:tr, { class: 'always-edit', data: { key: '' } }) do
|
||||
attributes = { class: [excel_data[:column_types][column]], data: { 'column-id' => column } }
|
||||
columns = content_tag(:th, excel_data[:keys][column].present? ? _(excel_data[:keys][column]) : '') +
|
||||
edit_column(nil, column, nil, attributes, excel_data, options)
|
||||
end
|
||||
end
|
||||
end
|
||||
rows.html_safe
|
||||
end)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def html_table(excel_data, options = {})
|
||||
options[:html] = true
|
||||
attributes = { class: options[:class], id: options[:id] }
|
||||
attributes[:data] = { 'update-url' => options[:editable] } if options[:editable].present?
|
||||
content_tag(:table, attributes) do
|
||||
(content_tag(:thead) do
|
||||
content_tag(:tr, excel_header_columns(excel_data))
|
||||
end) +
|
||||
content_tag(:tbody, excel_rows(excel_data, {}, options))
|
||||
end
|
||||
end
|
||||
|
||||
def excel_table(excel_data)
|
||||
format_xls 'table' do
|
||||
workbook use_autowidth: true
|
||||
format bg_color: '333333'
|
||||
format 'td', font_name: 'Calibri', fg_color: '333333'
|
||||
format 'th', font_name: 'Calibri', b: true, bg_color: '333333', fg_color: 'ffffff'
|
||||
format 'th.sub-table', font_name: 'Calibri', b: true, bg_color: 'DDDDDD', fg_color: '333333'
|
||||
format 'td.datetime', num_fmt: 22, font_name: 'Courier New', sz: 10, fg_color: '333333'
|
||||
format 'td.date.day', num_fmt: 14, font_name: 'Courier New', sz: 10, fg_color: '333333'
|
||||
format 'td.money', num_fmt: 2, font_name: 'Courier New', sz: 10, fg_color: '333333'
|
||||
format 'td.number', font_name: 'Courier New', sz: 10, fg_color: '333333'
|
||||
format 'td.bold', font_name: 'Calibri', fg_color: '333333', b: true
|
||||
end
|
||||
|
||||
content_tag(:table) do
|
||||
(content_tag(:thead) do
|
||||
content_tag(:tr, excel_header_columns(excel_data))
|
||||
end) +
|
||||
content_tag(:tbody, excel_rows(excel_data))
|
||||
end
|
||||
end
|
||||
|
||||
def excel_header_columns(data, padding = {}, class_name = nil)
|
||||
columns = ''
|
||||
|
||||
data[:columns].each do |column|
|
||||
unless data[:column_types].present? && data[:column_types][column] == :table
|
||||
columns += content_tag(:th, data[:keys][column].present? ? _(data[:keys][column]) : '', class: class_name)
|
||||
end
|
||||
end
|
||||
|
||||
pad_columns(columns, padding, :th)
|
||||
end
|
||||
|
||||
def excel_empty_row(data, padding = {})
|
||||
columns = ''
|
||||
|
||||
data[:columns].each do |column|
|
||||
unless data[:column_types].present? && data[:column_types][column] == :table
|
||||
columns += content_tag(:td)
|
||||
end
|
||||
end
|
||||
|
||||
content_tag(:tr, pad_columns(columns, padding))
|
||||
end
|
||||
|
||||
def pad_columns(columns, padding, column_type = :td)
|
||||
left = ''
|
||||
|
||||
for i in 1..(padding['left'] || 0)
|
||||
left += content_tag(:td)
|
||||
end
|
||||
|
||||
right = ''
|
||||
for i in 1..(padding['right'] || 0)
|
||||
right += content_tag(:td)
|
||||
end
|
||||
|
||||
(left + columns + right).html_safe
|
||||
end
|
||||
|
||||
def excel_columns(row, data, padding = {}, options = {})
|
||||
columns = ''
|
||||
|
||||
data[:columns].each do |column|
|
||||
value = row[column].present? ? (_!row[column].to_s) : ''
|
||||
class_name = nil
|
||||
is_sub_table = false
|
||||
|
||||
if data[:column_types].present? && data[:column_types][column].present?
|
||||
if data[:column_types][column] == :table
|
||||
is_sub_table = true
|
||||
else
|
||||
class_name = data[:column_types][column]
|
||||
end
|
||||
end
|
||||
|
||||
unless is_sub_table
|
||||
attributes = { class: [class_name] }
|
||||
if options[:html] && row[:html_values].present? && row[:html_values][column].present?
|
||||
value = row[:html_values][column]
|
||||
end
|
||||
|
||||
if options[:editable]
|
||||
attributes[:data] = { 'column-id' => column }
|
||||
end
|
||||
|
||||
if (options[:column_names] || []).include? column
|
||||
attributes[:tabindex] = 0
|
||||
end
|
||||
|
||||
columns += content_tag(:td, value, attributes)
|
||||
end
|
||||
end
|
||||
|
||||
pad_columns(columns, padding)
|
||||
end
|
||||
|
||||
def editor_columns(row, data, padding = {}, options = {})
|
||||
columns = ''
|
||||
|
||||
data[:columns].each do |column|
|
||||
value = row[column].present? ? (_!row[column].to_s) : ''
|
||||
class_name = nil
|
||||
is_sub_table = false
|
||||
|
||||
if data[:column_types].present? && data[:column_types][column].present?
|
||||
if data[:column_types][column] == :table
|
||||
is_sub_table = true
|
||||
else
|
||||
class_name = data[:column_types][column]
|
||||
end
|
||||
end
|
||||
|
||||
unless is_sub_table
|
||||
attributes = { class: [class_name] }
|
||||
|
||||
if options[:editable]
|
||||
attributes[:data] = { 'column-id' => column }
|
||||
end
|
||||
|
||||
if (options[:column_names] || []).include? column
|
||||
columns += edit_column(row, column, value, attributes, data, options)
|
||||
else
|
||||
columns += content_tag(:td, value, attributes)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
pad_columns(columns, padding)
|
||||
end
|
||||
|
||||
def edit_column(row, column, value, attributes, data, options)
|
||||
attributes[:class] << 'has-editor'
|
||||
raw_value = row.present? ? (row[:raw_values][column] || value) : nil
|
||||
|
||||
if row.present? && options[:html] && row[:html_values].present? && row[:html_values][column].present?
|
||||
value = row[:html_values][column]
|
||||
end
|
||||
|
||||
editor_attributes = { class: 'cell-editor', data: { value: raw_value.to_s } }
|
||||
|
||||
# create the control but add the original value to set the width and height
|
||||
editor_value = content_tag(:div, value, class: 'value')
|
||||
if (options[:column_options] || {})[column].present?
|
||||
value = (editor_value.html_safe + select_tag(column, options_for_select([['', '']] + options[:column_options][column], raw_value), editor_attributes)).html_safe
|
||||
elsif data[:column_types][column] == :text
|
||||
editor_attributes[:name] = column
|
||||
value = (editor_value.html_safe + content_tag(:textarea, raw_value, editor_attributes)).html_safe
|
||||
else
|
||||
editor_attributes[:name] = column
|
||||
editor_attributes[:value] = raw_value
|
||||
editor_attributes[:required] = :required if (options[:required_columns] || []).include? column
|
||||
type = data[:column_types][column] || :unknown
|
||||
editor_attributes[:type] = { money: :number, number: :number, email: :email }[type] || :text
|
||||
value = (editor_value.html_safe + content_tag(:input, nil, editor_attributes)).html_safe
|
||||
end
|
||||
|
||||
return content_tag(:td, value, attributes)
|
||||
end
|
||||
|
||||
def excel_sub_tables(row, data, padding = {}, options = {})
|
||||
rows = ''
|
||||
|
||||
# shift the table right
|
||||
new_padding = {
|
||||
'left' => (padding['right'] || 0) + 1,
|
||||
'right' => (padding['right'] || 0) - 1
|
||||
}
|
||||
|
||||
data[:columns].each do |column|
|
||||
if data[:column_types].present? && data[:column_types][column] == :table
|
||||
rows += content_tag(:tr, excel_header_columns(row[column], new_padding, 'sub-table'))
|
||||
rows += excel_rows(row[column], new_padding)
|
||||
rows += excel_empty_row(row[column], new_padding)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
rows.html_safe
|
||||
end
|
||||
|
||||
def excel_rows(data, padding = {}, options = {})
|
||||
rows = ''
|
||||
data[:data].each do |row|
|
||||
attributes = {}
|
||||
|
||||
if options[:primary_key].present?
|
||||
attributes[:data] = { key: row[options[:primary_key]] }
|
||||
end
|
||||
|
||||
attributes[:class] = []
|
||||
|
||||
if options[:editable]
|
||||
attributes[:class] << :editable
|
||||
end
|
||||
|
||||
rows += content_tag(:tr, excel_columns(row, data, padding, options), attributes) +
|
||||
excel_sub_tables(row, data, padding)
|
||||
rows += content_tag(:tr, editor_columns(row, data, padding, options), class: :editor) if options[:editable]
|
||||
end
|
||||
rows.html_safe
|
||||
end
|
||||
|
||||
def registrations_edit_table_options
|
||||
{
|
||||
id: 'create-table',
|
||||
class: ['registrations', 'admin-edit', 'always-editing'],
|
||||
primary_key: :id,
|
||||
column_names: {
|
||||
contact_info: [
|
||||
:name,
|
||||
:email,
|
||||
:is_subscribed,
|
||||
:city,
|
||||
:preferred_language
|
||||
] + User.AVAILABLE_LANGUAGES.map { |l| "language_#{l}".to_sym },
|
||||
questions: [
|
||||
:registration_fees_paid,
|
||||
:is_attending,
|
||||
:arrival,
|
||||
:departure,
|
||||
:housing,
|
||||
:bike,
|
||||
:food,
|
||||
:companion_email,
|
||||
:allergies,
|
||||
:other
|
||||
],
|
||||
hosting: [
|
||||
:can_provide_housing,
|
||||
:address,
|
||||
:phone,
|
||||
:first_day,
|
||||
:last_day
|
||||
] + ConferenceRegistration.all_spaces +
|
||||
ConferenceRegistration.all_considerations + [
|
||||
:notes
|
||||
]
|
||||
},
|
||||
row_spans: {
|
||||
allergies: 3,
|
||||
other: 2
|
||||
},
|
||||
required_columns: [:name, :email],
|
||||
editable: administration_update_path(@this_conference.slug, @admin_step),
|
||||
column_options: @column_options
|
||||
}
|
||||
end
|
||||
|
||||
def registrations_table_options
|
||||
{
|
||||
id: 'search-table',
|
||||
class: ['registrations', 'admin-edit'],
|
||||
primary_key: :id,
|
||||
column_names: [
|
||||
:registration_fees_paid,
|
||||
:is_attending,
|
||||
:is_subscribed,
|
||||
:city,
|
||||
:preferred_language,
|
||||
:arrival,
|
||||
:departure,
|
||||
:housing,
|
||||
:bike,
|
||||
:food,
|
||||
:companion_email,
|
||||
:allergies,
|
||||
:other,
|
||||
:can_provide_housing,
|
||||
:address,
|
||||
:phone,
|
||||
:first_day,
|
||||
:last_day,
|
||||
:notes
|
||||
] +
|
||||
User.AVAILABLE_LANGUAGES.map { |l| "language_#{l}".to_sym } +
|
||||
ConferenceRegistration.all_spaces +
|
||||
ConferenceRegistration.all_considerations,
|
||||
editable: administration_update_path(@this_conference.slug, @admin_step),
|
||||
column_options: @column_options
|
||||
}
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,288 @@
|
||||
require 'redcarpet'
|
||||
|
||||
module WidgetsHelper
|
||||
|
||||
def m(*args)
|
||||
_(*args) { |t|
|
||||
markdown(t)
|
||||
}
|
||||
end
|
||||
|
||||
def markdown(object, attribute = nil)
|
||||
return '' unless object
|
||||
content = attribute ? object.send(attribute.to_s) : object
|
||||
@markdown ||= Redcarpet::Markdown.new(Redcarpet::Render::HTML.new({
|
||||
filter_html: true,
|
||||
hard_wrap: true,
|
||||
space_after_headers: true,
|
||||
fenced_code_blocks: true,
|
||||
link_attributes: { target: "_blank" }
|
||||
}), {
|
||||
autolink: true,
|
||||
disable_indented_code_blocks: true,
|
||||
superscript: true
|
||||
})
|
||||
@markdown.render(content).html_safe
|
||||
end
|
||||
|
||||
def paragraph(object, attribute = nil)
|
||||
return '' unless object
|
||||
content = attribute ? object.send(attribute.to_s) : object
|
||||
result = ''
|
||||
if content =~ /<(p|span|h\d|div)[^>]*>/
|
||||
result = content.gsub(/\s*(style|class|id|width|height|font)=\".*?\"/, '')
|
||||
.gsub(/ /, ' ')
|
||||
.gsub(/<(\/)?\s*h\d\s*>/, '<\1h3>')
|
||||
.gsub(/<p>(.*?)<br\s\/?>\s*(<br\s\/?>)+/, '<p>\1</p><p>')
|
||||
.gsub(/<span[^>]*>\s*(.*?)\s*<\/span>/, '\1')
|
||||
.gsub(/<p>\s*<\/p>/, '')
|
||||
.gsub(/<(\/)?div>/, '<\1p>')
|
||||
if !(result =~ /<p[^>]*>/)
|
||||
result = '<p>' + result + '</p>'
|
||||
end
|
||||
else
|
||||
result = markdown(object, attribute)
|
||||
end
|
||||
result.html_safe
|
||||
end
|
||||
|
||||
def nav_link(link, title = nil, class_name = nil)
|
||||
if title.nil? && link.is_a?(Symbol)
|
||||
title = link
|
||||
link = send("#{link.to_s}_path")
|
||||
end
|
||||
if class_name.nil? && title.is_a?(Symbol)
|
||||
class_name = title
|
||||
end
|
||||
title = _"page_titles.#{title.to_s.titlecase.gsub(/\s/, '_')}"
|
||||
classes = []
|
||||
classes << class_name if class_name.present?
|
||||
classes << "strlen-#{strip_tags(title).length}"
|
||||
classes << 'current' if request.fullpath.start_with?(link.gsub(/^(.*?)\/$/, '\1'))
|
||||
link_to "<span class=\"title\">#{title}</span>".html_safe, link, :class => classes
|
||||
end
|
||||
|
||||
def data_set(header_type, header_key, attributes = {}, &block)
|
||||
raw_data_set(header_type, _(header_key), attributes, &block)
|
||||
end
|
||||
|
||||
def raw_data_set(header_type, header, attributes = {}, &block)
|
||||
attributes[:class] = attributes[:class].split(' ') if attributes[:class].is_a?(String)
|
||||
attributes[:class] = [attributes[:class].to_s] if attributes[:class].is_a?(Symbol)
|
||||
attributes[:class] ||= []
|
||||
attributes[:class] << 'data-set'
|
||||
content_tag(:div, attributes) do
|
||||
content_tag(header_type, header, class: 'data-set-key') +
|
||||
content_tag(:div, class: 'data-set-value', &block)
|
||||
end
|
||||
end
|
||||
|
||||
def admin_update_form(options = {}, &block)
|
||||
form_tag(administration_update_path(@this_conference.slug, @admin_step), options, &block)
|
||||
end
|
||||
|
||||
def interest_button(workshop)
|
||||
interested = workshop.interested?(current_user) ? :remove_interest : :show_interest
|
||||
id = "#{interested.to_s.gsub('_', '-')}-#{workshop.id}"
|
||||
return (off_screen (_"forms.actions.aria.#{interested.to_s}"), id) +
|
||||
(button interested, :value => :toggle_interest, :class => (workshop.interested?(current_user) ? :delete : :add), aria: { labelledby: id })
|
||||
end
|
||||
|
||||
def interest_text(workshop)
|
||||
if workshop.interested?(current_user)
|
||||
return _'articles.workshops.info.you_are_interested_count', :vars => {:count => (workshop.interested_count - 1)}
|
||||
end
|
||||
|
||||
return _'articles.workshops.info.interested_count', :vars => {:count => workshop.interested_count}
|
||||
end
|
||||
|
||||
def host_guests_table(registration)
|
||||
id = registration.id
|
||||
html = ''
|
||||
|
||||
@housing_data[id][:guests].each do | area, guests |
|
||||
guest_rows = ''
|
||||
guests.each do | guest_id, guest |
|
||||
status_html = ''
|
||||
|
||||
@housing_data[id][:guest_data][guest_id][:errors].each do | error, value |
|
||||
if value.is_a?(Array)
|
||||
value.each do | v |
|
||||
status_html += content_tag(:li, _("errors.messages.housing.space.#{error.to_s}", vars: v))
|
||||
end
|
||||
else
|
||||
status_html += content_tag(:li, _("errors.messages.housing.space.#{error.to_s}", vars: value))
|
||||
end
|
||||
end
|
||||
|
||||
@housing_data[id][:guest_data][guest_id][:warnings].each do | error, value |
|
||||
if value.is_a?(Array)
|
||||
value.each do | v |
|
||||
status_html += content_tag(:li, _("warnings.messages.housing.space.#{error.to_s}", v))
|
||||
end
|
||||
else
|
||||
status_html += content_tag(:li, _("warnings.messages.housing.space.#{error.to_s}", vars: value))
|
||||
end
|
||||
end
|
||||
|
||||
if status_html.present?
|
||||
status_html = content_tag(:ul, status_html.html_safe)
|
||||
end
|
||||
|
||||
guest_rows += content_tag :tr, id: "hosted-guest-#{guest_id}" do
|
||||
(content_tag :td, guest[:guest].user.name) +
|
||||
(content_tag :td do
|
||||
(guest[:guest].city +
|
||||
(content_tag :a, (_'actions.workshops.Remove'), href: '#', class: 'remove-guest', data: { guest: guest_id })).html_safe
|
||||
end) +
|
||||
(content_tag :td, status_html.html_safe, class: [:state, status_html.present? ? :unhappy : :happy])
|
||||
end
|
||||
end
|
||||
|
||||
space_size = (@housing_data[id][:space][area] || 0)
|
||||
|
||||
# add empty rows to represent empty guest spots
|
||||
for i in guests.size...space_size
|
||||
guest_rows += content_tag :tr, class: 'empty-space' do
|
||||
(content_tag :td, ' '.html_safe, colspan: 2) +
|
||||
(content_tag :td)
|
||||
end
|
||||
end
|
||||
|
||||
status_html = ''
|
||||
if @housing_data[id][:warnings].present? && @housing_data[id][:warnings][:space].present? && @housing_data[id][:warnings][:space][area].present?
|
||||
@housing_data[id][:warnings][:space][area].each do | w |
|
||||
status_html += content_tag(:li, _("warnings.messages.housing.space.#{w.to_s}"))
|
||||
end
|
||||
end
|
||||
if status_html.present?
|
||||
status_html = content_tag(:ul, status_html.html_safe)
|
||||
end
|
||||
|
||||
html += content_tag :tr do
|
||||
(content_tag :th, (_"forms.labels.generic.#{area}"), colspan: 2) +
|
||||
(content_tag :th, status_html.html_safe, class: [:state, status_html.present? ? :unhappy : :happy])
|
||||
end
|
||||
html += guest_rows
|
||||
html += content_tag :tr, class: 'place-guest' do
|
||||
content_tag :td, class: guests.size >= space_size ? 'full' : nil, colspan: 3 do
|
||||
content_tag :a, (_'forms.actions.generic.place_guest'), class: 'select-guest', href: '#', data: { host: id, space: area }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
content_tag :table, html.html_safe, class: 'host-table'
|
||||
end
|
||||
|
||||
def host_guests_widget(registration)
|
||||
html = ''
|
||||
classes = ['host']
|
||||
|
||||
id = registration.id
|
||||
@housing_data[id][:guests].each do | area, guests |
|
||||
max_space = @housing_data[id][:space][area] || 0
|
||||
area_name = (_"forms.labels.generic.#{area}")
|
||||
status_html = ''
|
||||
if @housing_data[id][:warnings].present? && @housing_data[id][:warnings][:space].present? && @housing_data[id][:warnings][:space][area].present?
|
||||
@housing_data[id][:warnings][:space][area].each do | w |
|
||||
status_html += content_tag(:div, _("warnings.housing.space.#{w.to_s}"), class: 'warning')
|
||||
end
|
||||
end
|
||||
space_html = content_tag(:h5, area_name + _!(" (#{guests.size.to_s}/#{max_space.to_s})") + status_html.html_safe)
|
||||
guest_items = ''
|
||||
guests.each do | guest_id, guest |
|
||||
guest_items += content_tag(:li, guest[:guest].user.name, id: "hosted-guest-#{guest_id}")
|
||||
end
|
||||
space_html += content_tag(:ul, guest_items.html_safe)
|
||||
space_html += button :place_guest, type: :button, value: "#{area}:#{id}", class: [:small, 'place-guest', 'on-top-only', guests.size >= max_space ? (guests.size > max_space ? :overbooked : :booked) : nil, max_space > 0 ? nil : :unwanted]
|
||||
html += content_tag(:div, space_html, class: [:space, area, max_space > 0 || guests.size > 0 ? nil : 'on-top-only'])
|
||||
end
|
||||
|
||||
classes << 'status-warning' if @housing_data[id][:warnings].present?
|
||||
classes << 'status-error' if @housing_data[id][:errors].present?
|
||||
|
||||
return { html: html.html_safe, class: classes.join(' ') }
|
||||
end
|
||||
|
||||
def signin_link
|
||||
@login_dlg ||= true
|
||||
link_to (_'forms.actions.generic.login'), settings_path, data: { 'sign-in': true }
|
||||
end
|
||||
|
||||
def link_with_confirmation(link_text, confirmation_text, path, args = {})
|
||||
@confirmation_dlg ||= true
|
||||
args[:data] ||= {}
|
||||
args[:data][:confirmation] = true
|
||||
link_to path, args do
|
||||
(link_text.to_s + content_tag(:template, confirmation_text, class: 'message')).html_safe
|
||||
end
|
||||
end
|
||||
|
||||
def link_info_dlg(link_text, info_text, info_title, args = {})
|
||||
@info_dlg ||= true
|
||||
args[:data] ||= {}
|
||||
args[:data]['info-title'] = info_title
|
||||
args[:data]['info-text'] = true
|
||||
content_tag(:a, args) do
|
||||
(link_text.to_s + content_tag(:template, info_text, class: 'message')).html_safe
|
||||
end
|
||||
end
|
||||
|
||||
def button_with_confirmation(button_name, confirmation_text = nil, args = {})
|
||||
if confirmation_text.is_a? Hash
|
||||
args = confirmation_text
|
||||
confirmation_text = nil
|
||||
end
|
||||
|
||||
confirmation_text ||= (_"forms.confirmations.#{button_name.to_s}", :p)
|
||||
@confirmation_dlg ||= true
|
||||
args[:data] ||= {}
|
||||
args[:data][:confirmation] = true
|
||||
button button_name, args do
|
||||
((_"forms.actions.generic.#{button_name.to_s}") + content_tag(:template, confirmation_text, class: 'message')).html_safe
|
||||
end
|
||||
end
|
||||
|
||||
def richtext(text, reduce_headings = 2)
|
||||
return '' unless text.present?
|
||||
return _!(text).
|
||||
gsub(/<(\/?)h4>/, '<\1h' + (reduce_headings + 4).to_s + '>').
|
||||
gsub(/<(\/?)h3>/, '<\1h' + (reduce_headings + 3).to_s + '>').
|
||||
gsub(/<(\/?)h2>/, '<\1h' + (reduce_headings + 2).to_s + '>').
|
||||
gsub(/<(\/?)h1>/, '<\1h' + (reduce_headings + 1).to_s + '>').
|
||||
html_safe
|
||||
end
|
||||
|
||||
def truncate(text)
|
||||
strip_tags(text.gsub('>', '> ')).gsub(/^(.{40,60})\s.*$/m, '\1…').html_safe
|
||||
end
|
||||
|
||||
def companion(registration)
|
||||
if registration.housing_data.present? && registration.housing_data['companions'].present? && registration.housing_data['companions'].first.present?
|
||||
companion_user = User.find_user(registration.housing_data['companions'].first)
|
||||
|
||||
if companion_user.present?
|
||||
cr = ConferenceRegistration.where(user_id: companion_user.id).order(created_at: :desc).limit(1).first
|
||||
|
||||
if cr.present? && ((cr.steps_completed || []).include? 'questions')
|
||||
return companion_user
|
||||
end
|
||||
end
|
||||
return :unregistered
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
def comment(comment)
|
||||
add_inline_script :time
|
||||
add_js_translation('datetime.distance_in_words')
|
||||
|
||||
content_tag(:div, class: 'comment-body') do
|
||||
content_tag(:h4, _!(comment.user.name), class: 'comment-title') +
|
||||
content_tag(:time, time(comment.created_at, :default), datetime: comment.created_at.to_s) +
|
||||
content_tag(:div, class: 'comment-text') do
|
||||
_!(markdown comment.comment)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user