Sha256: acf44ffddcfbc599c5251c6222ed97123bed21d05c68eaa61f29f35fcdfa8ed6

Contents?: true

Size: 1.49 KB

Versions: 110

Compression:

Stored size: 1.49 KB

Contents

# -*- encoding : utf-8 -*-
InlineForms::SPECIAL_COLUMN_TYPES[:check_list]=:no_migration

# checklist
def check_list_show(object, attribute)
  out = '<ul class="checklist">'
  out << link_to_inline_edit(object, attribute) if object.send(attribute).empty?
  object.send(attribute).sort.each do | item |
    out << '<li>'
    out << link_to_inline_edit(object, attribute, item._presentation )
    out << '</li>'
  end
  out <<  '</ul>'
  out.html_safe
end

def check_list_edit(object, attribute)
  object.send(attribute).build  if object.send(attribute).empty?
  if cancan_enabled?
    values = object.send(attribute).first.class.name.constantize.accessible_by(current_ability).order(attribute.to_s.singularize.camelcase.constantize.order_by_clause)
  else
    values = object.send(attribute).first.class.name.constantize.order(attribute.to_s.singularize.camelcase.constantize.order_by_clause)
  end
  out = '<div class="edit_form_checklist">'
  out << '<ul>'
  values.each do | item |
    out << '<li>'
    out << check_box_tag( attribute.to_s + '[' + item.id.to_s + ']', 1, object.send(attribute.to_s.singularize + "_ids").include?(item.id) )
    out << '<div class="edit_form_checklist_text">'
    out << h(item._presentation)
    out << '</div>'
    out << '<div style="clear: both;"></div>'
    out << '</li>'
  end
  out << '</ul>'
  out << '</div>'
  out.html_safe
end

def check_list_update(object, attribute)
  params[attribute] ||= {}
  object.send(attribute.to_s.singularize + '_ids=', params[attribute].keys)
end

Version data entries

110 entries across 110 versions & 1 rubygems

Version Path
inline_forms-1.6.50 lib/app/helpers/form_elements/check_list.rb
inline_forms-1.6.49 lib/app/helpers/form_elements/check_list.rb
inline_forms-1.6.48 lib/app/helpers/form_elements/check_list.rb
inline_forms-1.6.47 lib/app/helpers/form_elements/check_list.rb
inline_forms-1.6.46 lib/app/helpers/form_elements/check_list.rb
inline_forms-1.6.45 lib/app/helpers/form_elements/check_list.rb
inline_forms-1.6.44 lib/app/helpers/form_elements/check_list.rb
inline_forms-1.6.43 lib/app/helpers/form_elements/check_list.rb
inline_forms-1.6.42 lib/app/helpers/form_elements/check_list.rb
inline_forms-1.6.41 lib/app/helpers/form_elements/check_list.rb
inline_forms-1.6.40 lib/app/helpers/form_elements/check_list.rb
inline_forms-1.6.39 lib/app/helpers/form_elements/check_list.rb
inline_forms-1.6.38 lib/app/helpers/form_elements/check_list.rb
inline_forms-1.6.37 lib/app/helpers/form_elements/check_list.rb
inline_forms-1.6.36 lib/app/helpers/form_elements/check_list.rb
inline_forms-1.6.35 lib/app/helpers/form_elements/check_list.rb
inline_forms-2.23 lib/app/helpers/form_elements/check_list.rb
inline_forms-2.22 lib/app/helpers/form_elements/check_list.rb
inline_forms-2.21 lib/app/helpers/form_elements/check_list.rb
inline_forms-2.2 lib/app/helpers/form_elements/check_list.rb