Sha256: 6cee0b7b74b9fd7e11781107e8dbae94e7a9eaaa72cf5dbd784747cb63577f65

Contents?: true

Size: 1.04 KB

Versions: 63

Compression:

Stored size: 1.04 KB

Contents

require_relative 'utils/associations'

module CmAdmin
  module Models
    class Field
      include Utils::Associations

      attr_accessor :field_name, :label, :header, :field_type, :format, :precision, :height,
        :width, :helper_method, :preview, :custom_link, :prefix, :suffix, :tag_class,
        :display_if, :association_name, :association_type, :col_size

      def initialize(field_name, attributes = {})
        @field_name = field_name
        set_default_values
        attributes.each do |key, value|
          self.send("#{key.to_s}=", value)
        end
        self.height = 50 if self.field_type == :image && self.height.nil?
        self.width = 50 if self.field_type == :image && self.width.nil?
        self.display_if = lambda { |arg| return true } if self.display_if.nil?

        validation_for_association
      end

      def set_default_values
        self.precision = 2
        self.tag_class = {}
        self.col_size = nil
        self.field_type = :string
        self.label = field_name.to_s.titleize
      end
    end
  end
end

Version data entries

63 entries across 63 versions & 1 rubygems

Version Path
cm-admin-4.0.0 lib/cm_admin/models/field.rb
cm-admin-3.0.16 lib/cm_admin/models/field.rb
cm-admin-3.0.15 lib/cm_admin/models/field.rb
cm-admin-3.0.14 lib/cm_admin/models/field.rb
cm-admin-3.0.13 lib/cm_admin/models/field.rb
cm-admin-3.0.12 lib/cm_admin/models/field.rb
cm-admin-3.0.11 lib/cm_admin/models/field.rb
cm-admin-3.0.10 lib/cm_admin/models/field.rb
cm-admin-3.0.9 lib/cm_admin/models/field.rb
cm-admin-3.0.8 lib/cm_admin/models/field.rb
cm-admin-3.0.7 lib/cm_admin/models/field.rb
cm-admin-3.0.6 lib/cm_admin/models/field.rb
cm-admin-3.0.5 lib/cm_admin/models/field.rb
cm-admin-3.0.4 lib/cm_admin/models/field.rb
cm-admin-3.0.3 lib/cm_admin/models/field.rb
cm-admin-3.0.2 lib/cm_admin/models/field.rb
cm-admin-3.0.1 lib/cm_admin/models/field.rb
cm-admin-3.0.0 lib/cm_admin/models/field.rb
cm-admin-2.4.6 lib/cm_admin/models/field.rb
cm-admin-2.4.5 lib/cm_admin/models/field.rb