').html_safe
else
classes << 'new'
form_html += ('' + image_tag('http://placehold.it/120x120&text=%252B').html_safe + '').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 = ('
").html_safe
end
def actions(actions = [])
if !actions.is_a?(Array)
actions = [actions]
end
html = '
'
actions.each { |action|
if action == :facebook_sign_in
html += '' + (_ action.to_s) + ''
else
html += ''
end
}
html += '
'
html.html_safe
end
def sortable(objects, id = 'id', url: nil, &block)
result = '
'
objects.each_index do |i|
@this = objects[i]
result += '
'
result += hidden_field_tag (id + "[#{i}]"), objects[i][id]
result += hidden_field_tag ('position' + "[#{i}]"), i, :class => 'sortable-position'
if block_given?
result += capture(objects[i], &block)
end
result += '
'
end
result += ''
result.html_safe
end
def tabs object, tabs
type = object.class.name.downcase
tab_list = ''
tabs.each do |tab|
link = nil
if self.respond_to?(type + '_' + tab.to_s + '_path')
link = self.send(type + '_' + tab.to_s + '_path', object)
elsif self.respond_to?(tab.to_s + '_' + type + '_path')
link = self.send(tab.to_s + '_' + type + '_path', object)
end
c = ['tab', 'tab-' + (link ? tab.to_s : 'show')]
if params[:action] == tab.to_s
c << 'current'
end
link_html = ''
if tab.is_a?(Hash)
func = tab.keys[0]
val = tab[func]
args = val ? (val.is_a?(Array) ? (val.collect { |v| object[v] } ) : [object[val]] ) : nil
link_html = link_to func.to_s.gsub(/_path$/, ''), args ? self.send(func, args) : self.send(func), :class => c
else
#x
link_html = link_to tab, link || object, :class => c
end
tab_list += link_html
end
('').html_safe
end
def tabs!
object = nil
tabs = nil
case params[:controller]
when 'organizations'
object = @organization
tabs = OrganizationsHelper::TABS
when 'conferences'
object = @conference
tabs = ConferencesHelper::TABS
when 'workshops'
object = [@conference, @workshop]
tabs = WorkshopsHelper::TABS
end
if object && tabs
return tabs object, tabs
end
end
def sub_tabs object, tabs
type = object.class.name.downcase
tab_list = ''
tabs.each do |tab|
link = nil
if self.respond_to?(type + '_' + tab.to_s + '_path')
link = self.send(type + '_' + tab.to_s + '_path', object)
elsif self.respond_to?(tab.to_s + '_' + type + '_path')
link = self.send(tab.to_s + '_' + type + '_path', object)
end
c = ['sub-tab', 'sub-tab-' + (link ? tab.to_s : 'show')]
if current_page?(link)
c << 'current'
end
tab_list += link_to tab, link || object, :class => c
end
('').html_safe
end
def sub_tabs!
object = nil
tabs = nil
case params[:controller]
when 'organizations'
object = @organization
tabs = OrganizationsHelper::SUB_TABS
when 'conferences'
object = @conference
tabs = ConferencesHelper::SUB_TABS
end
if object && tabs
return sub_tabs object, tabs
end
end
def p(object, attribute)
('
').html_safe
end
def form_field(f, response = nil)
id = 'field_' + f.id.to_s
html = p(f, 'title')
options = JSON.parse(f.options)
if f.field_type == 'multiple'
if f.help
html += ('
' + p(f, 'help') + '
').html_safe
end
opts = Hash.new
options['options'].split(/\s*\n\s*/).each do |value|
kv = value.split(/\s*\|\s*/, 2)
opts[kv[0]] = kv[1]
end
val = response ? ActiveSupport::JSON.decode(response.data) : Hash.new
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)
end
else
html += field(id.to_sym, options['selection_type'] + '_tag', opts, value: val, required: f.required)
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)
end
html.html_safe
end
def t(*a)
_(*a)
end
def lookup_ip_location
if request.remote_ip == '127.0.0.1'
Geocoder.search(session['remote_ip'] || (session['remote_ip'] = open("http://checkip.dyndns.org").first.gsub(/^.*\s([\d\.]+).*$/s, '\1').gsub(/[^\.\d]/, ''))).first
else
request.location
end
end
end