Sha256: 3c63a8eac557d9b3b0b58c99118a5fc22e37c5df4f47021f656c6321d3ba9a41

Contents?: true

Size: 1.49 KB

Versions: 50

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 = ''
  out = link_to_inline_edit(object, attribute, "<i class='fi-plus'></i>".html_safe) if object.send(attribute).empty?
  object.send(attribute).sort.each do | item |
    out << "<div class='row #{cycle('odd', 'even')}'>"
    out << link_to_inline_edit(object, attribute, item._presentation )
    out << '</div>'
  end
  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 = ''
  values.each do | item |
    out << "<div class='row #{cycle('odd', 'even')}'>"
    out << check_box_tag( attribute.to_s + '[' + item.id.to_s + ']', 1, object.send(attribute.to_s.singularize + "_ids").include?(item.id) )
    out << "<label for=#{attribute.to_s + '[' + item.id.to_s + ']'}>#{h(item._presentation)}</label>"
    out << '</div>'
  end
  out.html_safe
end

def check_list_update(object, attribute)
  params[attribute] ||= {}
  object.send(attribute.to_s.singularize + '_ids=', params[attribute].keys)
  object.touch # TODO we should have a flag to turn this on or of.
end

Version data entries

50 entries across 50 versions & 1 rubygems

Version Path
inline_forms-5.0.16 lib/app/helpers/form_elements/check_list.rb
inline_forms-5.0.15 lib/app/helpers/form_elements/check_list.rb
inline_forms-5.0.6 lib/app/helpers/form_elements/check_list.rb
inline_forms-5.0.4 lib/app/helpers/form_elements/check_list.rb
inline_forms-5.0.0 lib/app/helpers/form_elements/check_list.rb
inline_forms-3.2.11 lib/app/helpers/form_elements/check_list.rb
inline_forms-3.2.10 lib/app/helpers/form_elements/check_list.rb
inline_forms-3.2.9 lib/app/helpers/form_elements/check_list.rb
inline_forms-3.2.8 lib/app/helpers/form_elements/check_list.rb
inline_forms-3.2.7 lib/app/helpers/form_elements/check_list.rb
inline_forms-3.2.6 lib/app/helpers/form_elements/check_list.rb
inline_forms-3.2.5 lib/app/helpers/form_elements/check_list.rb
inline_forms-3.2.4 lib/app/helpers/form_elements/check_list.rb
inline_forms-3.2.3 lib/app/helpers/form_elements/check_list.rb
inline_forms-3.2.2 lib/app/helpers/form_elements/check_list.rb
inline_forms-3.2.1 lib/app/helpers/form_elements/check_list.rb
inline_forms-3.2.0 lib/app/helpers/form_elements/check_list.rb
inline_forms-3.1.9 lib/app/helpers/form_elements/check_list.rb
inline_forms-3.1.8 lib/app/helpers/form_elements/check_list.rb
inline_forms-3.1.7 lib/app/helpers/form_elements/check_list.rb