Sha256: 26b9de1ba896b517f79890f99c88b0ed4606f1977fa1b3f5c5dc438df386ce33

Contents?: true

Size: 1.26 KB

Versions: 16

Compression:

Stored size: 1.26 KB

Contents

module CmAdmin
  module Models
    class Section

      attr_accessor :section_name, :section_fields, :display_if, :current_action, :cm_model, :nested_table_fields

      def initialize(section_name, current_action, cm_model, display_if, &block)
        @section_fields = []
        @nested_table_fields = {}
        @section_name = section_name
        @current_action = current_action
        @cm_model = cm_model
        @display_if = display_if || lambda { |arg| return true }
        instance_eval(&block)
      end

      def field(field_name, options={})
        @section_fields << CmAdmin::Models::Field.new(field_name, options)
      end

      def form_field(field_name, options={}, arg=nil)
        if @current_action.is_nested_field
          @nested_table_fields[@current_action.nested_table_name] ||= []
          @nested_table_fields[@current_action.nested_table_name] << CmAdmin::Models::FormField.new(field_name, options[:input_type], options)
        else
          @section_fields << CmAdmin::Models::FormField.new(field_name, options[:input_type], options)
        end
      end

      def nested_form_field(field_name, &block)
        @current_action.is_nested_field = true
        @current_action.nested_table_name = field_name
        yield
      end

    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
cm-admin-1.1.9 lib/cm_admin/models/section.rb
cm-admin-1.1.8 lib/cm_admin/models/section.rb
cm-admin-1.1.7 lib/cm_admin/models/section.rb
cm-admin-1.1.6 lib/cm_admin/models/section.rb
cm-admin-1.1.5 lib/cm_admin/models/section.rb
cm-admin-1.1.4 lib/cm_admin/models/section.rb
cm-admin-1.1.3 lib/cm_admin/models/section.rb
cm-admin-1.1.2 lib/cm_admin/models/section.rb
cm-admin-1.1.1 lib/cm_admin/models/section.rb
cm-admin-1.1.0 lib/cm_admin/models/section.rb
cm-admin-1.0.9 lib/cm_admin/models/section.rb
cm-admin-1.0.8 lib/cm_admin/models/section.rb
cm-admin-1.0.7 lib/cm_admin/models/section.rb
cm-admin-1.0.6 lib/cm_admin/models/section.rb
cm-admin-1.0.5 lib/cm_admin/models/section.rb
cm-admin-1.0.3 lib/cm_admin/models/section.rb