Sha256: 8f6571a91d10171af4bea20305699b715c9f0b4b72125cb70a361a29a9c90f63

Contents?: true

Size: 933 Bytes

Versions: 7

Compression:

Stored size: 933 Bytes

Contents

module Form
  class Row < ActiveRecord::Base
    include Form
    include Admin::Form::Row

    self.table_name_prefix = 'form_'

    belongs_to :structure
    has_many :fields, through: :structure
    has_one :viewable, through: :structure, class_name: 'Viewable::Form'

    validates :structure, presence: true

    delegate :with_email?, :send_to, :subject, :body, :email_column_key, :header, to: :structure
    delegate :form_name, to: :viewable

    def js_form_selector
      "#new_form_#{model_name.element}"
    end

    def send_from
      send(email_column_key) if email_column_key
    end

    def labelled_values
      columns = fields.count.times.map{ |i| "column_#{i}" }
      values = header.attributes.slice(*columns)
      values.reduce({}) do |values, (column_key, label)|
        values[label] = send(column_key)
        values
      end
    end

    def locale_enum
      I18n.available_locales
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rails_admin_cms-0.1.1 app/models/form/row.rb
rails_admin_cms-0.0.9 app/models/form/row.rb
rails_admin_cms-0.0.7 app/models/form/row.rb
rails_admin_cms-0.0.6 app/models/form/row.rb
rails_admin_cms-0.0.5 app/models/form/row.rb
rails_admin_cms-0.0.4 app/models/form/row.rb
rails_admin_cms-0.0.3 app/models/form/row.rb