Registration form more-or-less working, workshop scaffold is up
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://coffeescript.org/
|
||||
@@ -0,0 +1,3 @@
|
||||
// Place all the styles related to the workshops controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
@@ -37,6 +37,7 @@ class ConferencesController < ApplicationController
|
||||
registration = ConferenceRegistration.find_by(:user_id => current_user.id, :conference_id => @conference.id)
|
||||
if registration
|
||||
registration.conference_registration_responses.destroy_all
|
||||
registration.is_attending = params[:is_attending]
|
||||
else
|
||||
registration = ConferenceRegistration.new(user_id: current_user.id, conference_id: @conference.id, is_attending: params[:is_attending])
|
||||
end
|
||||
@@ -53,7 +54,7 @@ class ConferencesController < ApplicationController
|
||||
end
|
||||
end
|
||||
data.each do |key, value|
|
||||
registration.conference_registration_responses << ConferenceRegistrationResponse.new(registration_form_field_id: key.to_i, data: value.to_json.to_s)
|
||||
registration.conference_registration_responses << ConferenceRegistrationResponse.new(registration_form_field_id: key.to_i, data: value.to_json)
|
||||
end
|
||||
registration.save!
|
||||
render action: 'show'
|
||||
@@ -134,6 +135,16 @@ class ConferencesController < ApplicationController
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_conference
|
||||
@conference = Conference.find_by(slug: params[:slug] || params[:conference_slug])
|
||||
set_conference_registration
|
||||
end
|
||||
|
||||
def set_conference_registration
|
||||
if !@conference || !current_user
|
||||
@conference_registration = nil
|
||||
return
|
||||
end
|
||||
|
||||
@conference_registration = ConferenceRegistration.find_by(conference_id: @conference.id, user_id: current_user.id)
|
||||
end
|
||||
|
||||
# Only allow a trusted parameter "white list" through.
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
class WorkshopsController < ApplicationController
|
||||
before_action :set_workshop, only: [:show, :edit, :update, :destroy]
|
||||
|
||||
# GET /workshops
|
||||
def index
|
||||
@workshops = Workshop.all
|
||||
end
|
||||
|
||||
# GET /workshops/1
|
||||
def show
|
||||
end
|
||||
|
||||
# GET /workshops/new
|
||||
def new
|
||||
@workshop = Workshop.new
|
||||
end
|
||||
|
||||
# GET /workshops/1/edit
|
||||
def edit
|
||||
end
|
||||
|
||||
# POST /workshops
|
||||
def create
|
||||
@workshop = Workshop.new(workshop_params)
|
||||
|
||||
if @workshop.save
|
||||
redirect_to @workshop, notice: 'Workshop was successfully created.'
|
||||
else
|
||||
render action: 'new'
|
||||
end
|
||||
end
|
||||
|
||||
# PATCH/PUT /workshops/1
|
||||
def update
|
||||
if @workshop.update(workshop_params)
|
||||
redirect_to @workshop, notice: 'Workshop was successfully updated.'
|
||||
else
|
||||
render action: 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /workshops/1
|
||||
def destroy
|
||||
@workshop.destroy
|
||||
redirect_to workshops_url, notice: 'Workshop was successfully destroyed.'
|
||||
end
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_workshop
|
||||
@workshop = Workshop.find(params[:id])
|
||||
end
|
||||
|
||||
# Only allow a trusted parameter "white list" through.
|
||||
def workshop_params
|
||||
params.require(:workshop).permit(:title, :slug, :info, :conference_id, :workshop_stream_id, :workshop_presentation_style, :min_facilitators, :location_id, :start_time, :end_time)
|
||||
end
|
||||
end
|
||||
@@ -90,7 +90,7 @@ module ApplicationHelper
|
||||
return nil
|
||||
end
|
||||
|
||||
def _(key, behavior = nil, behavior_size = nil, fake: nil, vars: {}, html: nil, blockData: {}, &block)
|
||||
def _(key, behavior = nil, behavior_size = nil, vars: {}, html: nil, blockData: {}, &block)
|
||||
|
||||
queued_keys = nil
|
||||
result = nil
|
||||
@@ -201,7 +201,7 @@ module ApplicationHelper
|
||||
end
|
||||
end
|
||||
|
||||
def field(form, name, type = nil, param = nil, html: nil, help: false, attrs: [], classes: nil, label: nil, placeholder: nil)
|
||||
def field(form, name, type = nil, param = nil, html: nil, help: false, attrs: [], classes: nil, label: nil, placeholder: nil, value: nil, checked: nil)
|
||||
|
||||
if form.is_a?(Symbol) || form.is_a?(String)
|
||||
param = type
|
||||
@@ -228,18 +228,24 @@ module ApplicationHelper
|
||||
select_prompt = nil
|
||||
show_label = true
|
||||
label_after = true
|
||||
value_attribute = !form
|
||||
|
||||
if /select(_tag)?$/.match(type.to_s)
|
||||
placeholder = nil
|
||||
if !label
|
||||
select_prompt = 'Select a ' + name.to_s
|
||||
select_prompt = placeholder || (form ? 'Select a ' + name.to_s : 'Select one')
|
||||
label_html = ''
|
||||
show_label = false
|
||||
end
|
||||
label_after = false
|
||||
if param && param.is_a?(Array)
|
||||
param = options_for_select(param)
|
||||
placeholder = nil
|
||||
label_after = false
|
||||
if param
|
||||
if param.is_a?(Array)
|
||||
param = options_for_select(param, value)
|
||||
elsif param.is_a?(Hash)
|
||||
param = options_from_collection_for_select(param, :first, :last, value)
|
||||
end
|
||||
end
|
||||
value_attribute = false
|
||||
elsif type.to_s == 'image_field' || type.to_s == 'user_select_field' || type.to_s == 'organization_select_field'
|
||||
placeholder = nil
|
||||
label_html = ''
|
||||
@@ -316,14 +322,29 @@ module ApplicationHelper
|
||||
end
|
||||
else
|
||||
ph = ''
|
||||
va = ''
|
||||
if value_attribute
|
||||
if /^(check_box|radio_button)/.match(type.to_s)
|
||||
if checked === nil
|
||||
checked = value == "on" || value.to_s == "1"
|
||||
end
|
||||
if /^(radio_button)/.match(type.to_s)
|
||||
va = ', "' + value + '", checked'
|
||||
else
|
||||
va = ', "1", checked'
|
||||
end
|
||||
else
|
||||
va = ', value'
|
||||
end
|
||||
end
|
||||
if placeholder
|
||||
if form
|
||||
ph = ", :placeholder => '#{placeholder}'"
|
||||
else
|
||||
ph = ", nil, placeholder: '#{placeholder}'"
|
||||
ph = ", placeholder: '#{placeholder}'"
|
||||
end
|
||||
end
|
||||
form_html = (form ? "form.#{type} :#{name}" : "#{type} :#{name}") + ph + (param ? ', param' : '')
|
||||
form_html = (form ? "form.#{type} :#{name}" : "#{type} :#{name}") + va + ph + (param ? ', param' : '')
|
||||
attrs.each_index { |i| form_html += (i >= attrs_used ? ', attrs[' + i.to_s + ']' : '') }
|
||||
if select_prompt
|
||||
if form
|
||||
@@ -451,10 +472,11 @@ module ApplicationHelper
|
||||
('<p>' + object.send(attribute.to_s).strip.gsub(/\s*\n+\s*/, '</p><p>') + '</p>').html_safe
|
||||
end
|
||||
|
||||
def form_field(f)
|
||||
def form_field(f, response = nil)
|
||||
id = 'field_' + f.id.to_s
|
||||
html = p(f, 'title')#'<label for="' + id + '">' + f.title + '</label>'
|
||||
|
||||
#options = ActiveSupport::JSON.decode(options)#JSON.parse(f.options)
|
||||
options = JSON.parse(f.options)
|
||||
if f.field_type == 'multiple'
|
||||
if f.help
|
||||
@@ -466,12 +488,27 @@ module ApplicationHelper
|
||||
kv = value.split(/\s*\|\s*/, 2)
|
||||
opts[kv[0]] = kv[1]
|
||||
end
|
||||
opts.each do |key, value|
|
||||
#html += self.send(options['selection_type'] + '_tag', 'field-' + id)
|
||||
html += field((id + '_' + key), options['selection_type'] + '_tag', label: value)
|
||||
|
||||
val = response ? ActiveSupport::JSON.decode(response.data) : Hash.new
|
||||
#val = nil
|
||||
|
||||
if f.repeats?
|
||||
is_array = f.is_array?
|
||||
opts.each do |key, value|
|
||||
#html += self.send(options['selection_type'] + '_tag', 'field-' + id)
|
||||
#ActiveSupport::JSON.decode(key)
|
||||
if is_array
|
||||
#x
|
||||
end
|
||||
html += field((id + (is_array ? ('_' + key) : '')).to_sym, options['selection_type'] + '_tag', label: value, value: is_array ? (val ? val[key] : nil) : key, checked: is_array ? (val[key] == "1" || val[key] == "on") : val.to_s == key.to_s)
|
||||
end
|
||||
else
|
||||
html += field(id.to_sym, options['selection_type'] + '_tag', opts, value: val)
|
||||
end
|
||||
#html += collection_check_boxes nil, nil, opts, nil, :key
|
||||
else
|
||||
html += field(id.to_sym, options['input_type'] + '_tag', label: false, placeholder: f.help)
|
||||
#x
|
||||
html += field(id.to_sym, options['input_type'] + '_tag', label: false, placeholder: f.help, value: response ? ActiveSupport::JSON.decode(response.data) : nil)
|
||||
end
|
||||
|
||||
html.html_safe
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
module WorkshopsHelper
|
||||
end
|
||||
@@ -56,6 +56,14 @@ class RegistrationFormField < ActiveRecord::Base
|
||||
o
|
||||
end
|
||||
|
||||
def repeats?()
|
||||
field_type.to_s == 'multiple' && selection_type.to_s != 'select'
|
||||
end
|
||||
|
||||
def is_array?()
|
||||
field_type.to_s == 'multiple' && selection_type.to_s != 'radio_button'
|
||||
end
|
||||
|
||||
private
|
||||
def get_from_options(key)
|
||||
if options
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
class Workshop < ActiveRecord::Base
|
||||
end
|
||||
@@ -1,7 +1,8 @@
|
||||
.columns.medium-8
|
||||
= field :is_attending, :select_tag, ConferenceRegistration::AttendingOptions, label: 'Are you attending?'
|
||||
= field :is_attending, :select_tag, ConferenceRegistration::AttendingOptions, label: 'Are you attending?', value: @conference_registration.try(:is_attending)
|
||||
%ol
|
||||
- @conference.registration_form_fields.each do |ff|
|
||||
%li
|
||||
= form_field ff
|
||||
- response = @conference_registration ? ConferenceRegistrationResponse.find_by(conference_registration_id: @conference_registration.id, registration_form_field_id: ff.id) : nil
|
||||
= form_field ff, response
|
||||
= actions :register
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
= form_for @workshop do |f|
|
||||
- if @workshop.errors.any?
|
||||
#error_explanation
|
||||
%h2= "#{pluralize(@workshop.errors.count, "error")} prohibited this workshop from being saved:"
|
||||
%ul
|
||||
- @workshop.errors.full_messages.each do |msg|
|
||||
%li= msg
|
||||
|
||||
.field
|
||||
= f.label :title
|
||||
= f.text_field :title
|
||||
.field
|
||||
= f.label :slug
|
||||
= f.text_field :slug
|
||||
.field
|
||||
= f.label :info
|
||||
= f.text_area :info
|
||||
.field
|
||||
= f.label :conference_id
|
||||
= f.number_field :conference_id
|
||||
.field
|
||||
= f.label :workshop_stream_id
|
||||
= f.number_field :workshop_stream_id
|
||||
.field
|
||||
= f.label :workshop_presentation_style
|
||||
= f.number_field :workshop_presentation_style
|
||||
.field
|
||||
= f.label :min_facilitators
|
||||
= f.number_field :min_facilitators
|
||||
.field
|
||||
= f.label :location_id
|
||||
= f.number_field :location_id
|
||||
.field
|
||||
= f.label :start_time
|
||||
= f.datetime_select :start_time
|
||||
.field
|
||||
= f.label :end_time
|
||||
= f.datetime_select :end_time
|
||||
.actions
|
||||
= f.submit 'Save'
|
||||
@@ -0,0 +1,7 @@
|
||||
%h1 Editing workshop
|
||||
|
||||
= render 'form'
|
||||
|
||||
= link_to 'Show', @workshop
|
||||
\|
|
||||
= link_to 'Back', workshops_path
|
||||
@@ -0,0 +1,37 @@
|
||||
%h1 Listing workshops
|
||||
|
||||
%table
|
||||
%tr
|
||||
%th Title
|
||||
%th Slug
|
||||
%th Info
|
||||
%th Conference
|
||||
%th Workshop stream
|
||||
%th Workshop presentation style
|
||||
%th Min facilitators
|
||||
%th Location
|
||||
%th Start time
|
||||
%th End time
|
||||
%th
|
||||
%th
|
||||
%th
|
||||
|
||||
- @workshops.each do |workshop|
|
||||
%tr
|
||||
%td= workshop.title
|
||||
%td= workshop.slug
|
||||
%td= workshop.info
|
||||
%td= workshop.conference_id
|
||||
%td= workshop.workshop_stream_id
|
||||
%td= workshop.workshop_presentation_style
|
||||
%td= workshop.min_facilitators
|
||||
%td= workshop.location_id
|
||||
%td= workshop.start_time
|
||||
%td= workshop.end_time
|
||||
%td= link_to 'Show', workshop
|
||||
%td= link_to 'Edit', edit_workshop_path(workshop)
|
||||
%td= link_to 'Destroy', workshop, :method => :delete, :data => { :confirm => 'Are you sure?' }
|
||||
|
||||
%br
|
||||
|
||||
= link_to 'New Workshop', new_workshop_path
|
||||
@@ -0,0 +1,5 @@
|
||||
%h1 New workshop
|
||||
|
||||
= render 'form'
|
||||
|
||||
= link_to 'Back', workshops_path
|
||||
@@ -0,0 +1,36 @@
|
||||
%p#notice= notice
|
||||
|
||||
%p
|
||||
%b Title:
|
||||
= @workshop.title
|
||||
%p
|
||||
%b Slug:
|
||||
= @workshop.slug
|
||||
%p
|
||||
%b Info:
|
||||
= @workshop.info
|
||||
%p
|
||||
%b Conference:
|
||||
= @workshop.conference_id
|
||||
%p
|
||||
%b Workshop stream:
|
||||
= @workshop.workshop_stream_id
|
||||
%p
|
||||
%b Workshop presentation style:
|
||||
= @workshop.workshop_presentation_style
|
||||
%p
|
||||
%b Min facilitators:
|
||||
= @workshop.min_facilitators
|
||||
%p
|
||||
%b Location:
|
||||
= @workshop.location_id
|
||||
%p
|
||||
%b Start time:
|
||||
= @workshop.start_time
|
||||
%p
|
||||
%b End time:
|
||||
= @workshop.end_time
|
||||
|
||||
= link_to 'Edit', edit_workshop_path(@workshop)
|
||||
\|
|
||||
= link_to 'Back', workshops_path
|
||||
Reference in New Issue
Block a user