Sha256: 57d3a5c7f64dbed462393af85d2c2182b48bae4384fe5a0a0949ff4f5ba7e2e0

Contents?: true

Size: 1.53 KB

Versions: 10

Compression:

Stored size: 1.53 KB

Contents

# -*- encoding : utf-8 -*-
InlineForms::SPECIAL_COLUMN_TYPES[:dropdown]=:belongs_to

# dropdown
def dropdown_show(object, attribute)
  attr = object.send attribute
  presentation = "_presentation"
  presentation = "_dropdown_presentation" if attr.respond_to? "_dropdown_presentation"
  attribute_value = object.send(attribute).send(presentation) rescue  "<i class='fi-plus'></i>".html_safe
  link_to_inline_edit object, attribute, attribute_value
end

def dropdown_edit(object, attribute)
  object.send('build_' + attribute.to_s) unless object.send(attribute) # we really need this!
  attr = object.send attribute
  presentation = "_presentation"
  presentation = "_dropdown_presentation" if attr.respond_to? "_dropdown_presentation"
  klass = attribute.to_s.singularize.camelcase.constantize
  if cancan_enabled?
    values = klass.accessible_by(current_ability)
  else
    values = klass.all
  end
  values.sort_by! {|v|v.send presentation}
  # the leading underscore is to avoid name conflicts, like 'email' and 'email_type' will result in 'email' and 'email[email_type_id]' in the form!
  collection_select( ('_' + object.class.to_s.underscore).to_sym, attribute.to_s.foreign_key.to_sym, values, 'id', presentation, :selected => (object.send(attribute).id rescue nil) )
end

def dropdown_update(object, attribute)
  foreign_key = object.class.reflect_on_association(attribute.to_sym).options[:foreign_key] || attribute.to_s.foreign_key.to_sym
  object[foreign_key] = params[('_' + object.class.to_s.underscore).to_sym][attribute.to_s.foreign_key.to_sym]
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
inline_forms-3.0.46 lib/app/helpers/form_elements/dropdown.rb
inline_forms-3.0.45 lib/app/helpers/form_elements/dropdown.rb
inline_forms-3.0.44 lib/app/helpers/form_elements/dropdown.rb
inline_forms-3.0.43 lib/app/helpers/form_elements/dropdown.rb
inline_forms-3.0.42 lib/app/helpers/form_elements/dropdown.rb
inline_forms-3.0.41 lib/app/helpers/form_elements/dropdown.rb
inline_forms-3.0.40 lib/app/helpers/form_elements/dropdown.rb
inline_forms-3.0.39 lib/app/helpers/form_elements/dropdown.rb
inline_forms-3.0.38 lib/app/helpers/form_elements/dropdown.rb
inline_forms-3.0.37 lib/app/helpers/form_elements/dropdown.rb