Sha256: 30faed6f638d9fabd04579775fa1c59ca7bf9802951a795322129b70c07e950c

Contents?: true

Size: 1.43 KB

Versions: 49

Compression:

Stored size: 1.43 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)
end

Version data entries

49 entries across 49 versions & 1 rubygems

Version Path
inline_forms-3.0.35 lib/app/helpers/form_elements/check_list.rb
inline_forms-3.0.34 lib/app/helpers/form_elements/check_list.rb
inline_forms-3.0.32 lib/app/helpers/form_elements/check_list.rb
inline_forms-3.0.31 lib/app/helpers/form_elements/check_list.rb
inline_forms-3.0.30 lib/app/helpers/form_elements/check_list.rb
inline_forms-3.0.29 lib/app/helpers/form_elements/check_list.rb
inline_forms-3.0.28 lib/app/helpers/form_elements/check_list.rb
inline_forms-3.0.27 lib/app/helpers/form_elements/check_list.rb
inline_forms-3.0.26 lib/app/helpers/form_elements/check_list.rb
inline_forms-3.0.25 lib/app/helpers/form_elements/check_list.rb
inline_forms-3.0.24 lib/app/helpers/form_elements/check_list.rb
inline_forms-3.0.23 lib/app/helpers/form_elements/check_list.rb
inline_forms-3.0.22 lib/app/helpers/form_elements/check_list.rb
inline_forms-3.0.21 lib/app/helpers/form_elements/check_list.rb
inline_forms-3.0.20 lib/app/helpers/form_elements/check_list.rb
inline_forms-3.0.19 lib/app/helpers/form_elements/check_list.rb
inline_forms-3.0.18 lib/app/helpers/form_elements/check_list.rb
inline_forms-3.0.17 lib/app/helpers/form_elements/check_list.rb
inline_forms-3.0.16 lib/app/helpers/form_elements/check_list.rb
inline_forms-3.0.15 lib/app/helpers/form_elements/check_list.rb