# encoding: utf-8
module Formily
module Helpers
module ViewHelper
# # Create html table from submitted data
# # @param obj [ActiveRecord::Base]
# def formily_form_data_table(obj)
# if obj.is_many_formily?
# if obj.formily_forms.present?
# ids = obj.formily_forms.pluck(:form_id)
# forms = Formily::Form.where(id: ids)
# render({partial: formily_partial_path('data/many_tables'), :locals => {:@forms => forms, :@res => obj}})
# end
# else
# if obj.formily_form.present?
# form = obj.formily_form.form
# render({partial: formily_partial_path('data/table'), :locals => {:@form => form, :@res => obj}})
# end
# end
# end
#
# def formily_form_list(obj)
# if obj.is_many_formily?
# if obj.formily_forms.present?
# ids = obj.formily_forms.pluck(:form_id)
# forms = Formily::Form.where(id: ids)
# render({partial: formily_partial_path('data/forms_table'), :locals => {:@forms => forms, :@res => obj}})
# end
# else
# if obj.formily_form.present?
# end
# end
# end
#
# # Connect formily form to object
# # @param obj [ActiveRecord::Base]
# # @param formily_form_id [Integer]
# def connect_to_formily_url(obj, formily_form_id)
# formily_forms_connect_form_path({form_id: formily_form_id, model_name: obj.class.to_s, model_id: obj.id})
# end
#
def show_formily_form_link_tag(form_id, obj, submit_id = 0, user_id = 0, btn_text = 'Connect', html_attrs = {})
url_options = {
id: form_id,
model_id: obj.id,
model_name: obj.class.name,
submit_id: submit_id,
user_id: user_id
}
html_attrs['data-formily-iframe-url'] = formily_iframe_form_path(url_options)
attr_str = html_attrs.map{|k, v| "#{k}=\"#{v}\""}.join(' ')
('' + btn_text + '').html_safe
end
def connect_form_btn_tag(obj, user_id, btn_text = 'Connect', html_attrs = {})
html_attrs['data-formily-iframe-url'] = formily_form_iframe_url(obj, user_id, '/new')
attr_str = html_attrs.map{|k, v| "#{k}=\"#{v}\""}.join(' ')
('').html_safe
end
# Render