Sha256: a3178291d3347305cadf4f549a4124403f9f7b73a7ace763bf9fcd427c411c5a

Contents?: true

Size: 1.58 KB

Versions: 34

Compression:

Stored size: 1.58 KB

Contents

module ActiveExt
module ExtHelpers
module FormBuilder
  class << self

    def build_form_fields(core, model_id, action)
      fields = []

      if action != 'new'
        #add hidden id
        fields << ActiveExt::ExtHelpers::FieldBuilder.build_field(core.columns[:id], get_value(core, model_id, :id), false, true)
        #add id column if showing it
        if core.options[:show_id]
          fields << ActiveExt::ExtHelpers::FieldBuilder.build_field(core.columns[:id], get_value(core, model_id, :id), true)
        end
      end

      display_only = action == 'show'

      #build ext columns
      core.columns.each do |column|
        next if column.name.to_s =~ /(^id|created_at|updated_at)$/  || core.columns.exclude_column?(column.name)
        next if column.sql_type.blank? || column.sql_type == NilClass
        fields << ActiveExt::ExtHelpers::FieldBuilder.build_field(column, get_value(core, model_id, column.name), display_only)
      end

      #add timestamp columns if showing them
      if core.options[:show_timestamps] && action != 'new'
        fields << ActiveExt::ExtHelpers::FieldBuilder.build_field(core.columns[:created_at], get_value(core, model_id, :created_at), true)
        fields << ActiveExt::ExtHelpers::FieldBuilder.build_field(core.columns[:updated_at], get_value(core, model_id, :updated_at), true)
      end

      fields.to_json
    end

    def get_value(core, model_id, name)
      value = nil

      unless model_id.nil?
        value = core.model.find(model_id).send(name)
      end

      value
    end

  end
end
end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
erp_app-4.0.0 lib/active_ext/ext_helpers/form_builder.rb
erp_app-3.1.16 lib/active_ext/ext_helpers/form_builder.rb
erp_app-3.1.15 lib/active_ext/ext_helpers/form_builder.rb
erp_app-3.1.14 lib/active_ext/ext_helpers/form_builder.rb
erp_app-3.1.13 lib/active_ext/ext_helpers/form_builder.rb
erp_app-3.1.12 lib/active_ext/ext_helpers/form_builder.rb
erp_app-3.1.11 lib/active_ext/ext_helpers/form_builder.rb
erp_app-3.1.10 lib/active_ext/ext_helpers/form_builder.rb
erp_app-3.1.9 lib/active_ext/ext_helpers/form_builder.rb
erp_app-3.1.8 lib/active_ext/ext_helpers/form_builder.rb
erp_app-3.1.7 lib/active_ext/ext_helpers/form_builder.rb
erp_app-3.1.6 lib/active_ext/ext_helpers/form_builder.rb
erp_app-3.1.5 lib/active_ext/ext_helpers/form_builder.rb
erp_app-3.1.4 lib/active_ext/ext_helpers/form_builder.rb
erp_app-3.1.3 lib/active_ext/ext_helpers/form_builder.rb
erp_app-3.1.2 lib/active_ext/ext_helpers/form_builder.rb
erp_app-3.0.16 lib/active_ext/ext_helpers/form_builder.rb
erp_app-3.0.15 lib/active_ext/ext_helpers/form_builder.rb
erp_app-3.1.1 lib/active_ext/ext_helpers/form_builder.rb
erp_app-3.1.0 lib/active_ext/ext_helpers/form_builder.rb