Browse Source

Moved form helpers from application_helper to a real FormHelper

development
Godwin 11 years ago
parent
commit
ffa8239e42
  1. 16
      Gemfile
  2. 2
      app/assets/javascripts/application.js.coffee
  3. 3
      app/assets/stylesheets/foundation_and_overrides.scss
  4. 5
      app/assets/stylesheets/sass/_layout.scss
  5. 11
      app/controllers/conferences_controller.rb
  6. 211
      app/helpers/application_helper.rb
  7. 394
      app/helpers/bike_bike_form_helper.rb
  8. 22
      app/views/conference_registrations/_form.html.haml
  9. 25
      app/views/conference_registraton_form_fields/_form.html.haml
  10. 35
      app/views/conferences/_form.html.haml
  11. 10
      app/views/conferences/_registration.html.haml
  12. 4
      app/views/conferences/_registration_register.html.haml
  13. 4
      app/views/conferences/hosts.html.haml
  14. 7
      app/views/conferences/registration.html.haml
  15. 8
      app/views/layouts/fields/_actions.html.haml
  16. 10
      app/views/layouts/fields/_default.html.haml
  17. 9
      app/views/layouts/fields/_errors_default.html.haml
  18. 7
      app/views/layouts/fields/_field_image_field.html.haml
  19. 11
      app/views/layouts/fields/_field_organization_select_field.html.haml
  20. 14
      app/views/layouts/fields/_field_user_select_field.html.haml
  21. 8
      app/views/layouts/fields/_label_default.html.haml
  22. 43
      app/views/organizations/_form.html.haml
  23. 6
      app/views/organizations/identity.html.haml
  24. 5
      app/views/organizations/members.html.haml
  25. 23
      app/views/registration_form_fields/_form.html.haml
  26. 6
      app/views/user_sessions/_form.html.haml
  27. 21
      app/views/users/_form.html.haml
  28. 22
      app/views/workshops/_form.html.haml
  29. 5
      config/application.rb
  30. 10
      config/initializers/i18n.rb

16
Gemfile

@ -60,7 +60,7 @@ gem 'acts_as_list'
gem 'geocoder'
gem 'forgery'
gem 'paper_trail'
# gem 'panoramio-rb' # make it easier to let users get nice backdrops for their conferences etc
group :development, :test do
gem 'debugger'
@ -70,13 +70,13 @@ group :development, :test do
end
group :development do
gem 'bullet'
gem 'better_errors'
gem 'binding_of_caller'
gem 'meta_request'
gem 'haml-rails'
gem 'awesome_print'
gem 'rails-footnotes', :github => 'josevalim/rails-footnotes'
gem 'bullet'
gem 'better_errors'
gem 'binding_of_caller'
gem 'meta_request'
gem 'haml-rails'
gem 'awesome_print'
gem 'rails-footnotes', :github => 'josevalim/rails-footnotes'
end
group :test do

2
app/assets/javascripts/application.js.coffee

@ -59,7 +59,7 @@ selectA = (type, event, $emptyObj) ->
$overlay = createOverlay()
objs = []
$('.' + type + '-select-field.added input.' + type + '-id').each () -> obj.push($(this).val())
$.post $emptyObj.data().url + (if type == 'organization' then '/nonhosts' else '/nonmembers'), {added: objs},
$.post window.location.href.replace(/^(.*\/)(.+?)$/, '$1non$2'), {added: objs},
(html) ->
setOverlayHTML(html).addClass('' + type + '-select')
$('#select-' + type + '-list a').click (event) ->

3
app/assets/stylesheets/foundation_and_overrides.scss

@ -182,7 +182,8 @@ $large: $large-up;
// We use this to control the maximum number of block grid elements per row
// $block-grid-elements: 12;
// $block-grid-default-spacing: rem-calc(20);
$block-grid-default-spacing: rem-calc(20);
$align-block-grid-to-grid: true;
// Enables media queries for block-grid classes. Set to false if writing semantic HTML.
// $block-grid-media-queries: true;

5
app/assets/stylesheets/sass/_layout.scss

@ -395,3 +395,8 @@ table {
background: transparent !important;
}
}
/*[class*="block-grid-"] {
margin: 0;
}
*/

11
app/controllers/conferences_controller.rb

@ -1,3 +1,6 @@
require 'geocoder/calculations'
require 'rest_client'
class ConferencesController < ApplicationController
before_action :set_conference, only: [:show, :edit, :update, :destroy]
@ -18,6 +21,14 @@ class ConferencesController < ApplicationController
# GET /conferences/1/edit
def edit
@host = @conference.organizations[0].locations[0]
#points = Geocoder::Calculations.bounding_box([@host.latitude, @host.longitude], 50, { :unit => :km })
result = Geocoder.search(@host.city + ', ' + @host.territory + ' ' + @host.country).first
points = Geocoder::Calculations.bounding_box([result.latitude, result.longitude], 5, { :unit => :km })
response = RestClient.get 'http://www.panoramio.com/map/get_panoramas.php', :params => {:set => :public, :size => :original, :from => 0, :to => 20, :mapfilter => false, :miny => points[0], :minx => points[1], :maxy => points[2], :maxx => points[3]}
if response.code == 200
@parse_data = JSON.parse(response.to_str)
end
end
# POST /conferences

211
app/helpers/application_helper.rb

@ -197,192 +197,6 @@ module ApplicationHelper
end
end
def field(form, name, type = nil, param = nil, html: nil, help: false, attrs: [], classes: nil, label: nil, placeholder: nil, value: nil, checked: nil, required: false)
if form.is_a?(Symbol) || form.is_a?(String)
param = type
type = name
name = form
form = nil
end
if attrs && !attrs.is_a?(Array)
attrs = [attrs]
end
attrs_used = 0
root = 'div'
lang_key = "form.#{name.to_s}"
if form
lang_key = form.object.class.name.underscore.pluralize + '.' + lang_key
elsif params[:controller]
lang_key = params[:controller] + '.' + lang_key
end
select_prompt = nil
show_label = !(/^hidden_field/.match(type.to_s))
label_after = true
value_attribute = !form
if /select(_tag)?$/.match(type.to_s)
if !label
select_prompt = placeholder || (form ? 'Select a ' + (_ ('form.select_' + name.to_s)) : 'form.Select_one')
label_html = ''
show_label = false
end
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 = ''
show_label = false
else
if /^password/.match(type.to_s)
placeholder = nil
elsif !placeholder
placeholder = (_ 'form.Enter_your_' + name.to_s)
end
end
if show_label
label_html = eval("(" + (form ? 'form.label' : 'label_tag') + " name, '<span>#{CGI.escapeHTML(_ (label || name.to_s))}</span>'.html_safe)")
end
if label === false || !show_label
label_html = ''
end
if /text_area(_tag)?$/.match(type.to_s)
root = nil
end
html_options = nil
if html
html_options = ''
html.each do |key, v|
html_options += ', ' + key.to_s + ": html[:" + key.to_s + "]"
end
end
if classes
if classes.is_a?(String)
classes = [classes]
end
else
classes = []
end
if type == :image_field
form_html = form.label name do
('<div>' + image_tag(param || 'http://placehold.it/300x300&text=Click%20to%20upload%20an%20Image') + (form.file_field name) + (form.hidden_field (name.to_s + '_cache')) + '</div><span><span>' + name.to_s + '</span></span>').html_safe
end
elsif type == :user_select_field
form_html = form.hidden_field(:id, { class: 'id' }).html_safe
form_html += form.check_box(:_destroy).html_safe
form_html += form.label(:_destroy, '×').html_safe
form_html += form.hidden_field(:user_id, { class: 'user-id'} ).html_safe
if param && param.id
form_html += image_tag(param.avatar.url :thumb).html_safe + ('<div class="username">' + param.username + '</div>').html_safe
if attrs && attrs.length > 0 && attrs[0].is_a?(UserOrganizationRelationship)
form_html += form.select(:relationship, options_for_select(UserOrganizationRelationship::AllRelationships, attrs[0].relationship), {}, {class: 'small'}).html_safe
attrs_used += 1
end
else
classes << 'new'
if attrs && attrs.length > 0 && attrs[0].is_a?(UserOrganizationRelationship)
form_html += ('<a href="#" class="select-user" data-url="' + url_for(attrs[0].organization) + '">' + image_tag('http://placehold.it/120x120&text=%252B').html_safe + '</a><div class="username"></div>').html_safe
form_html += form.select(:relationship, options_for_select(UserOrganizationRelationship::AllRelationships, UserOrganizationRelationship::DefaultRelationship), {}, {class: 'small'}).html_safe
attrs_used += 1
end
end
elsif type == :organization_select_field
form_html = form.hidden_field(:id, { class: 'id' }).html_safe
form_html += form.check_box(:_destroy).html_safe
form_html += form.label(:_destroy, '×').html_safe
form_html += form.hidden_field(:organization_id, { class: 'organzation-id'} ).html_safe
if param && param.id
form_html += image_tag(param.avatar.url :thumb).html_safe + ('<div class="organizationname">' + param.name + '</div>').html_safe
else
classes << 'new'
form_html += ('<a href="#" class="select-organization" data-url="' + url_for(param) + '">' + image_tag('http://placehold.it/120x120&text=%252B').html_safe + '</a><div class="organizationname"></div>').html_safe
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 = ", placeholder: '#{placeholder}'"
end
end
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
form_html += ', {prompt: select_prompt}'
else
form_html += ', prompt: select_prompt'
end
end
form_html += (html_options || '')
if required
form_html += ', :required => true'
end
form_html = eval(form_html)
if root
form_html = "<#{root}>" + form_html + "</#{root}>"
end
end
if help
form_html = ('<p>' + (_ (lang_key + '.help'), :w, 20) + '</p>').html_safe + form_html.html_safe
end
return ("<div class=\"field #{type.to_s.gsub('_', '-').gsub(/\-tag$/, '')} field-#{name.to_s.gsub('_', '-')}#{classes.length > 0 ? ' ' + classes.join(' ') : ''}\">" + (label_after ? '' : label_html) + form_html + (label_after ? label_html : '') + "</div>").html_safe
end
def actions(actions = [])
if !actions.is_a?(Array)
actions = [actions]
end
html = '<div class="actions">'
actions.each { |action|
if action == :facebook_sign_in
html += '<a href="' + url_for(auth_at_provider_path(:provider => :facebook)) + '" class="facebook-sign-in button">' + (_ action.to_s) + '</a>'
else
html += '<button id="' + action.to_s + '" name="' + action.to_s + '" type="submit">' + (_ action.to_s) + '</button>'
end
}
html += '</div>'
html.html_safe
end
def sortable(objects, id = 'id', url: nil, &block)
result = '<ul class="sortable sortable-' + objects[0].class.name.underscore.gsub('_', '-') + (url ? ('" data-url="' + url) : '') + '" data-id="' + id + '">'
objects.each_index do |i|
@ -518,13 +332,24 @@ module ApplicationHelper
if f.repeats?
is_array = f.is_array?
opts.each do |key, value|
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, required: f.required)
n = (id + (is_array ? ('_' + key) : '')).to_sym
v = is_array ? (val ? val[key] : nil) : key
o = {:label => value}
if f.required
options[:required] = true
end
html += _form_field(options['selection_type'], n, v, o)
end
else
html += field(id.to_sym, options['selection_type'] + '_tag', opts, value: val, required: f.required)
html += _form_field(options['selection_type'], id.to_sym, options_for_select(opts.invert, val), {})
end
else
html += field(id.to_sym, options['input_type'] + '_tag', label: false, placeholder: f.help, value: response ? ActiveSupport::JSON.decode(response.data) : nil, required: f.required)
#html += field(id.to_sym, options['input_type'] + '_tag', label: false, placeholder: f.help, value: response ? ActiveSupport::JSON.decode(response.data) : nil, required: f.required)
opts = {label: false, placeholder: f.help && f.help.length > 0 ? f.help : false}
if f.required
opts[:required] = true
end
html += _form_field(options['input_type'], id.to_sym, response ? ActiveSupport::JSON.decode(response.data) : nil, opts)
end
html.html_safe
@ -542,4 +367,12 @@ module ApplicationHelper
end
end
private
def _form_field(type, name, value, options)
if type == 'check_box'
self.send(type + '_tag', name, "1", value, options)
else
self.send(type + '_tag', name, value, options)
end
end
end

394
app/helpers/bike_bike_form_helper.rb

@ -0,0 +1,394 @@
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 = {})
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 = {})
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={})
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 = {})
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 = {})
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 fields_for
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 label
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)
if (options.has_key?(:no_wrapper) && options[:no_wrapper]) || 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)
params[:label_position] = options[:label] === false ? :none : label_position(type)
render(template, params)
end
def get_label_template(type)
if /select(_field)?$/.match(type.to_s)
return nil
end
template_exists?('label_' + type) ? type : 'default'
end
def label_position(type)
# one of: :before, :after, :inside, or :none
case type
when 'image_field'
return :inside
when 'organization_select_field'
return :none
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)
options[:_controller] = params[:controller]
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

22
app/views/conference_registrations/_form.html.haml

@ -1,19 +1,5 @@
= form_for @conference_registration do |f|
- if @conference_registration.errors.any?
#error_explanation
%h2= "#{pluralize(@conference_registration.errors.count, "error")} prohibited this conference_registration from being saved:"
%ul
- @conference_registration.errors.full_messages.each do |msg|
%li= msg
.field
= f.label :conference_id
= f.number_field :conference_id
.field
= f.label :user_id
= f.number_field :user_id
.field
= f.label :is_attending
= f.text_field :is_attending
.actions
= f.submit 'Save'
= f.number_field :conference_id
= f.number_field :user_id
= f.text_field :is_attending
= f.actions :Save

25
app/views/conference_registraton_form_fields/_form.html.haml

@ -1,19 +1,8 @@
= form_for @conference_registraton_form_field do |f|
- if @conference_registraton_form_field.errors.any?
#error_explanation
%h2= "#{pluralize(@conference_registraton_form_field.errors.count, "error")} prohibited this conference_registraton_form_field from being saved:"
%ul
- @conference_registraton_form_field.errors.full_messages.each do |msg|
%li= msg
.field
= f.label :conference_id
= f.number_field :conference_id
.field
= f.label :registration_form_field_id
= f.number_field :registration_form_field_id
.field
= f.label :order
= f.number_field :order
.actions
= f.submit 'Save'
= f.label :conference_id
= f.number_field :conference_id
= f.label :registration_form_field_id
= f.number_field :registration_form_field_id
= f.label :order
= f.number_field :order
= f.actions :Save

35
app/views/conferences/_form.html.haml

@ -1,27 +1,24 @@
= form_for @conference do |f|
.columns
- if @conference.errors.any?
#error_explanation
%h2= "#{pluralize(@conference.errors.count, "error")} prohibited this conference from being saved:"
%ul
- @conference.errors.full_messages.each do |msg|
%li= msg
= field f, :title, :text_field
= field f, :slug, :text_field
= f.text_field :title
= f.text_field :slug
.columns.medium-4
= field f, :poster, :image_field, @conference.poster_url
= field f, :cover, :image_field, @conference.cover_url
= f.image_field :poster, @conference.poster_url
= f.image_field :cover, @conference.cover_url
- # @parse_data['photos'].each do |img|
- # - if img['width'] > 980
- # %img{src: img['photo_file_url']}
.columns.medium-8
= field f, :conference_type_id, :collection_select, ConferenceType.all, attrs: [:id, :title]
= f.collection_select :conference_type_id, ConferenceType.all, :id, :title
.row
.columns.small-6
= field f, :start_date, :date_field
= f.date_field :start_date
.columns.small-6
= field f, :end_date, :date_field
= field f, :workshop_schedule_published, :check_box
= field f, :meals_provided, :check_box
= field f, :meal_info, :text_area
= field f, :travel_info, :text_area
= f.date_field :end_date
= f.check_box :workshop_schedule_published
= f.check_box :meals_provided
= f.text_area :meal_info
= f.text_area :travel_info
.columns
= field f, :info, :text_area
= actions :save
= f.text_area :info
= f.actions :save

10
app/views/conferences/_registration.html.haml

@ -1,7 +1,7 @@
.columns.medium-8
= field f, :registration_open, :check_box, help: true
= field f, :preregistration_info, :text_area, help: true
= field f, :registration_info, :text_area, help: true
= field f, :postregistration_info, :text_area, help: true
= f.check_box :registration_open, help: true
= f.text_area :preregistration_info, help: true
= f.text_area :registration_info, help: true
= f.text_area :postregistration_info, help: true
.columns
= actions :save
= f.actions :save

4
app/views/conferences/_registration_register.html.haml

@ -1,8 +1,8 @@
.columns.medium-8
= field :is_attending, :select_tag, ConferenceRegistration::AttendingOptions, label: 'Are you attending?', value: @conference_registration.try(:is_attending)
= select_tag :is_attending, ConferenceRegistration::AttendingOptions, label: 'Are you attending?', value: @conference_registration.try(:is_attending)
%ol
- @conference.registration_form_fields.each do |ff|
%li
- 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
= form_actions :register

4
app/views/conferences/hosts.html.haml

@ -9,5 +9,5 @@
.columns.medium-8
.clearfix
= f.fields_for :conference_host_organizations, :include_id => true do |u|
= field u, :id, :organization_select_field, @conference.organizations[u.index], attrs: @conference
= actions :save
= u.organization_select_field :id, @conference.organizations[u.index] #, attrs: @conference
= f.actions :save

7
app/views/conferences/registration.html.haml

@ -3,13 +3,6 @@
= tabs!
.row
= form_for @conference do |f|
.columns
- if @conference.errors.any?
#error_explanation
%h2= "#{pluralize(@conference.errors.count, "error")} prohibited this conference from being saved:"
%ul
- @conference.errors.full_messages.each do |msg|
%li= msg
.columns.medium-4
=sub_tabs!
%h2=_'conference.hosts.help.title', :t

8
app/views/layouts/fields/_actions.html.haml

@ -0,0 +1,8 @@
.actions
- @actions.each do |action|
- if action.to_sym == :facebook_sign_in
%a.facebook-sign-in.button{href: '/oauth/facebook'}
= _ action.to_s
- else
%button{id: action.to_s, name: action.to_s, type: 'submit'}
= _ action.to_s

10
app/views/layouts/fields/_default.html.haml

@ -0,0 +1,10 @@
- namekey = @name.to_s.gsub('_', '-')
- typekey = @type.gsub('_', '-').gsub(/^(.*?)(\-field)?$/, '\1-field')
%div{class: ['field', typekey, 'field-' + namekey, @value ? nil : 'new']}
- if @options[:help]
%p.help=_(("form.#{@options[:_controller]}.#{namekey}.help"), :w, 20)
- @label = @label_template ? (render ('layouts/fields/label_' + @label_template)) : nil
= @label_position == :before && @label ? @label : ''
- if @label_position != :inside
%div=@html
= @label_position == :after && @label ? '' : @label

9
app/views/layouts/fields/_errors_default.html.haml

@ -0,0 +1,9 @@
- # we should render errors here
- if @record.errors.any?
.form-errors
%ul
- @record.errors.full_messages.each do |msg|
- # not sure how this works, we may have to pull
- # some sort of error id out of this and construct
- # an I18n translation key
%li=msg

7
app/views/layouts/fields/_field_image_field.html.haml

@ -0,0 +1,7 @@
= image_tag (@value || 'http://placehold.it/300x300&text=Click%20to%20upload%20an%20Image')
- if @form
-# = @form.hidden_field (@name.to_s + '_cache')
= @form.file_field @name, {:no_wrapper => true}
- else
= file_field_tag @name, {:no_wrapper => true}
= hidden_field_tag (@name.to_s + '_cache')

11
app/views/layouts/fields/_field_organization_select_field.html.haml

@ -0,0 +1,11 @@
= @form.hidden_field(:id, { class: 'id' })
= @form.check_box(:_destroy, {:no_wrapper => true})
= @form.label(:_destroy, '×')
= @form.hidden_field(:organization_id, { class: 'organzation-id'} )
- if @value && @value.id
= form_html = image_tag(@value.avatar.url :thumb)
.organizationname=@value.name
- else
%a.select-organization{href: '#'}
= image_tag('http://placehold.it/120x120&text=%252B')
.organizationname

14
app/views/layouts/fields/_field_user_select_field.html.haml

@ -0,0 +1,14 @@
= @form.hidden_field(:id, { class: 'id' })
= @form.check_box(:_destroy, {:no_wrapper => true})
= @form.label(:_destroy, '×')
= @form.hidden_field(:user_id, { class: 'user-id'} )
- if @value && @value.id
= image_tag(@value.avatar.url :thumb)
.username=@value.username
- if @options[:relationship]
= @form.select(:relationship, options_for_select(UserOrganizationRelationship::AllRelationships, @options[:relationship]), {:no_wrapper => true}, {class: 'small'})
- else
- if @options[:relationship]
%a.select-user{href: '#'}=image_tag('http://placehold.it/120x120&text=%252B')
.username
= @form.select(:relationship, options_for_select(UserOrganizationRelationship::AllRelationships, UserOrganizationRelationship::DefaultRelationship), {:no_wrapper => true}, {class: 'small'})

8
app/views/layouts/fields/_label_default.html.haml

@ -0,0 +1,8 @@
- label = @options[:label] || _('form.label.' + @name.to_s)
= label_tag @name do
- if @label_position == :inside
%div=@html
%span
%span=label
- else
%span=label

43
app/views/organizations/_form.html.haml

@ -1,41 +1,20 @@
= form_for @organization do |f|
.columns
- if @organization.errors.any?
#error_explanation
%h2= "#{pluralize(@organization.errors.count, "error")} prohibited this organization from being saved:"
%ul
- @organization.errors.full_messages.each do |msg|
%li= msg
= field f, :name, :text_field
= field f, :slug, :text_field
= f.text_field :name
= f.text_field :slug
.columns.medium-4.small-text-centered
-#%h2=_'organization.create.intro-title', :t
-#%p=_'organization.create.intro', :p
=# field f, :avatar, :image_field
= field f, :avatar, :image_field, @organization.avatar_url
-#= field f, :year_founded, :number_field
=# f.label :avatar do
=# %div
=# = image_tag(@organization.avatar_url || ''
=# = f.hidden_field :avatar_cache
= f.image_field :avatar, @organization.avatar_url
.columns.medium-8
= field f, :email_address, :email_field
= f.email_field :email_address
= f.fields_for :locations do |b|
= field_set_tag 'Location' do
= field b, :country, :country_select, {help: 'Select a Country'}
= b.country_select :country, {help: 'Select a Country'}
- cc = @organization.locations && @organization.locations[b.index].country ? @organization.locations[b.index].country : 'US'
= field b, :territory, :subregion_select, cc, html: {class: @organization.locations[b.index].country ? 'can' : 'cant', data: {:country => cc}}
= field b, :city, :text_field
= field b, :street, :text_field
= field b, :postal_code, :text_field
-#= field f, :logo, :text_field
-#= field f, :avatar, :text_field
-#= field f, :requires_approval, :check_box
-#= field f, :secret_question, :text_field
-#= field f, :secret_answer, :text_field
-#= field f, :location_id, :number_field
-#= field f, :user_organization_replationship_id, :number_field
= b.subregion_select :territory, cc, html: {class: @organization.locations[b.index].country ? 'can' : 'cant', data: {:country => cc}}
= b.text_field :city
= b.text_field :street
= b.text_field :postal_code
.columns
= field f, :info, :text_area
= actions :save
= f.text_area :info
= f.actions :save

6
app/views/organizations/identity.html.haml

@ -8,6 +8,6 @@
%h2=_'organization.members.help.title', :t
%p=_'organization.members.help', :p
.columns.medium-8
= field f, :cover, :image_field, @organization.cover_url
= field f, :year_founded, :number_field
= actions :save
= f.image_field :cover, @organization.cover_url
= f.number_field :year_founded
= f.actions :save

5
app/views/organizations/members.html.haml

@ -10,5 +10,6 @@
.columns.medium-8
.clearfix
= f.fields_for :user_organization_relationships, :include_id => true do |u|
= field u, :id, :user_select_field, @organization.users[u.index], attrs: [@organization.user_organization_relationships[u.index]]
= actions :save
= u.user_select_field :id, @organization.users[u.index], {:relationship => @organization.user_organization_relationships[u.index].relationship || true}
-#attrs: [@organization.user_organization_relationships[u.index]]
= f.actions :save

23
app/views/registration_form_fields/_form.html.haml

@ -1,15 +1,14 @@
= form_for @registration_form_field do |f|
- if @registration_form_field.errors.any?
#error_explanation
%h2= "#{pluralize(@registration_form_field.errors.count, "error")} prohibited this registration_form_field from being saved:"
%ul
- @registration_form_field.errors.full_messages.each do |msg|
%li= msg
- if @conference
= field :conference_id, :hidden_field_tag, value: @conference.id
= field f, :field_type, :select, RegistrationFormField::Types.keys
= f.hidden_field :conference_id, value: @conference.id
= f.select :field_type, RegistrationFormField::Types.keys
- RegistrationFormField::Fields.each do |key, value|
- classes = RegistrationFormField::TypesForField(key.to_sym).collect{|v| 'field-type-' + v.to_s}
- classes << 'registration-form-field-field'
= eval('field f, :' + key.to_s + ', :' + value[:control] + (value[:options] ? ', ' + (value[:options].map.with_index{|v, i| 'value[:options][' + i.to_s + ']'}.join(', ') || 'nil') : '') + ", classes: classes")
= actions :save
- options = {:html => { :classes => RegistrationFormField::TypesForField(key.to_sym).collect{|v| 'field-type-' + v.to_s} } }
- options[:html][:classes] << 'registration-form-field-field'
-# eval('field f, :' + key.to_s + ', :' + value[:control] + (value[:options] ? ', ' + (value[:options].map.with_index{|v, i| 'value[:options][' + i.to_s + ']'}.join(', ') || 'nil') : '') + ", classes: classes")
- if value[:options]
- fields = options_for_select(value[:options].first.map { |v| [_("form_field.#{v}"), v]})
= f.send(value[:control], key.to_s, fields, options)
- else
= f.send(value[:control], key.to_s, options)
= f.actions :save

6
app/views/user_sessions/_form.html.haml

@ -1,4 +1,4 @@
= form_tag user_sessions_path, :method => :post do
= field :email, :email_field
= field :password, :password_field_tag
= actions [:Sign_In, :facebook_sign_in]
= email_field_tag :email
= password_field_tag :password
= form_actions [:Sign_In, :facebook_sign_in]

21
app/views/users/_form.html.haml

@ -1,19 +1,12 @@
= form_for @user, :html => (@user.id ? {:multipart => true} : {}) do |f|
%div{:class => (@user.id ? 'columns medium-6' : '')}
- if @user.errors.any?
#error_explanation
%h2= "#{pluralize(@user.errors.count, "error")} prohibited this user from being saved:"
%ul
- @user.errors.full_messages.each do |msg|
%li= msg
= field f, :username, :text_field
= field f, :email, :text_field
= f.text_field :username
= f.email_field :email
- if !@user.id
= field f, :password, :password_field
= field f, :password_confirmation, :password_field
= actions :register
= f.password_field, :password
= f.password_field, :password_confirmation
= f.actions :register
- if @user.id
.columns.medium-6
= field f, :avatar, :image_field, @user.avatar_url
= actions :save
= f.image_field :avatar, @user.avatar_url
= f.actions :save

22
app/views/workshops/_form.html.haml

@ -1,23 +1,13 @@
= form_for @workshop, url: conference_workshops_path(@conference, @workshop) do |f|
.columns
- 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, :title, :text_field
= field f, :slug, :text_field
= f.text_field :title
= f.text_field :slug
.columns.medium-4
%h2=_'workshop.form.help.title', :t
=_'workshop.form.help', :p
.columns.medium-8
= field f, :info, :text_area
= field f, :workshop_stream_id, :number_field
= field f, :workshop_presentation_style, :number_field
=# field f, :min_facilitators, :number_field
=# field f, :location_id, :number_field
=# field f, :start_time, :datetime_select
=# field f, :end_time, :datetime_select
= f.text_area :info
= f.number_field :workshop_stream_id
= f.number_field :workshop_presentation_style
.columns
= actions :save
= f.actions :save

5
config/application.rb

@ -1,6 +1,8 @@
require File.expand_path('../boot', __FILE__)
require 'rails/all'
#require "#{Rails.root}/app/helpers/bike_bike_form_helper"
#require '/app/helpers/bike_bike_form_helper.rb'
#require 'dotenv'; Dotenv.load ".env.local", ".env.#{Rails.env}"
# Require the gems listed in Gemfile, including any gems
@ -26,5 +28,8 @@ module BikeBike
config.i18n.enforce_available_locales = false
#config.middleware.swap 'Rack::MethodOverride', 'Rack::MethodOverrideWithParams'
#config.i18n.exception_handler = I18n::MissingTranslationExceptionHandler.new
#require '/app/helpers/bike_bike_form_helper'
#ActionView::Base.default_form_builder
#config.action_view.default_form_builder = 'BikeBikeFormHelper::BikeBikeFormBuilder'
end
end

10
config/initializers/i18n.rb

@ -15,27 +15,27 @@ module I18n
case method.to_s
when 'c', 'char', 'character', 'characters'
if size
return Forgery::LoremIpsum.characters size, options
return (Forgery::LoremIpsum.characters size, options).capitalize
end
return Forgery::LoremIpsum.character, options
when 'w', 'word', 'words'
if size
return Forgery::LoremIpsum.words size, options
return (Forgery::LoremIpsum.words size, options).capitalize
end
#return'LOREM'
return Forgery::LoremIpsum.word options
return (Forgery::LoremIpsum.word options).capitalize
when 's', 'sentence', 'sentences'
if size
return Forgery::LoremIpsum.sentences size, options
end
return Forgery::LoremIpsum.sentence options
return (Forgery::LoremIpsum.sentence options).capitalize
when 'p', 'paragraph', 'paragraphs'
if size
return Forgery::LoremIpsum.paragraphs size, options.merge({:sentences => 10})
end
return Forgery::LoremIpsum.sentences 10, options
when 't', 'title'
return Forgery::LoremIpsum.sentences 1, options
return (Forgery::LoremIpsum.sentences 1, options).capitalize
end
return nil
end

Loading…
Cancel
Save