Sha256: 95f9ee2d05c424f6d4a42093349080fa411caea7c1da3c02882ce968d74e22c7

Contents?: true

Size: 1.59 KB

Versions: 49

Compression:

Stored size: 1.59 KB

Contents

module Tramway
  module Admin
    module InputsHelper
      def association_params(form_object:, property:, value:, object:)
        full_class_name_association = form_object.class.full_class_name_association(property)
        {
          label: false,
          input_html: {
            name: "#{object}[#{property}]",
            id: "#{object}_#{property}",
            value: (form_object.send(property) || form_object.model.send("#{property}_id") || value)
          },
          selected: (form_object.model.send("#{property}_id") || value),
          collection: full_class_name_association.active.map do |obj|
            decorator_class(full_class_name_association).decorate obj
          end
        }
      end

      def polymorphic_association_params(object:, form_object:, property:, value:)
        full_class_names = form_object.model.class.send("#{property}_type").values.map &:constantize
        collection = full_class_names.map do |class_name|
          class_name.active.map do |obj|
            decorator_class(class_name).decorate obj
          end
        end.flatten
        {
          as: :select,
          label: false,
          input_html: {
            name: "#{object}[#{property}]",
            id: "#{object}_#{property}",
            value: (form_object.send(property) || form_object.model.send("#{property}_id") || value)
          },
          selected: (form_object.model.send("#{property}_id") || value),
          collection: collection,
          label_method: lambda do |obj|
            "#{obj.class.model_name.human} | #{obj.name}"
          end
        }
      end
    end
  end
end

Version data entries

49 entries across 49 versions & 1 rubygems

Version Path
tramway-admin-1.14.0.3 app/helpers/tramway/admin/inputs_helper.rb
tramway-admin-1.14.0.2 app/helpers/tramway/admin/inputs_helper.rb
tramway-admin-1.14.0.1 app/helpers/tramway/admin/inputs_helper.rb
tramway-admin-1.14 app/helpers/tramway/admin/inputs_helper.rb
tramway-admin-1.13.0.4 app/helpers/tramway/admin/inputs_helper.rb
tramway-admin-1.13.0.3 app/helpers/tramway/admin/inputs_helper.rb
tramway-admin-1.13.0.2 app/helpers/tramway/admin/inputs_helper.rb
tramway-admin-1.13.0.1 app/helpers/tramway/admin/inputs_helper.rb
tramway-admin-1.13 app/helpers/tramway/admin/inputs_helper.rb
tramway-admin-1.12.2 app/helpers/tramway/admin/inputs_helper.rb
tramway-admin-1.12.1.1 app/helpers/tramway/admin/inputs_helper.rb
tramway-admin-1.12.1 app/helpers/tramway/admin/inputs_helper.rb
tramway-admin-1.12.0.8 app/helpers/tramway/admin/inputs_helper.rb
tramway-admin-1.12.0.7 app/helpers/tramway/admin/inputs_helper.rb
tramway-admin-1.12.0.6 app/helpers/tramway/admin/inputs_helper.rb
tramway-admin-1.12.0.5 app/helpers/tramway/admin/inputs_helper.rb
tramway-admin-1.12.0.4 app/helpers/tramway/admin/inputs_helper.rb
tramway-admin-1.12.0.3 app/helpers/tramway/admin/inputs_helper.rb
tramway-admin-1.12.0.2 app/helpers/tramway/admin/inputs_helper.rb
tramway-admin-1.12.0.1 app/helpers/tramway/admin/inputs_helper.rb