'
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|
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 += _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)
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
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
def hash_to_html_attributes(hash, prefix = '')
attributes = ''
if hash
hash.each { |k,v|
k = k.to_s
if v
if v.is_a?(Hash)
attributes += hash_to_html_attributes(v, 'data-')
else
attributes += " #{k}=\"" + (v.is_a?(Array) ? v.join(' ') : v) + '"'
end
end
}
end
attributes
end
def icon(id, attributes = nil)
('').html_safe
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