Sha256: 1919edfa412b32af9cc31c033ffe7b102e410432d8f06d08a8f605eb2be0135a

Contents?: true

Size: 1.04 KB

Versions: 20

Compression:

Stored size: 1.04 KB

Contents

module Avo
  module Fields
    class HasBaseField < BaseField
      attr_accessor :display
      attr_accessor :scope

      def initialize(id, **args, &block)
        super(id, **args, &block)

        @display = args[:display].present? ? args[:display] : :show
        @scope = args[:scope].present? ? args[:scope] : nil
      end

      def resource
        Avo::App.get_resource_by_model_name @model.class
      end

      def turbo_frame
        "#{self.class.name.demodulize.to_s.underscore}_#{display}_#{id}"
      end

      def frame_url
        "#{@resource.record_path}/#{id}?turbo_frame=#{turbo_frame}"
      end

      def target_resource
        if @model._reflections[id.to_s].klass.present?
          Avo::App.get_resource_by_model_name @model._reflections[id.to_s].klass.to_s
        elsif @model._reflections[id.to_s].options[:class_name].present?
          Avo::App.get_resource_by_model_name @model._reflections[id.to_s].options[:class_name]
        else
          Avo::App.get_resource_by_name id.to_s
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
avo-1.24.2 lib/avo/fields/has_base_field.rb
avo-1.24.1 lib/avo/fields/has_base_field.rb
avo-1.24.0 lib/avo/fields/has_base_field.rb
avo-1.23.0 lib/avo/fields/has_base_field.rb
avo-1.22.4 lib/avo/fields/has_base_field.rb
avo-1.22.3 lib/avo/fields/has_base_field.rb
avo-1.22.2 lib/avo/fields/has_base_field.rb
avo-1.22.1 lib/avo/fields/has_base_field.rb
avo-1.22.1.pre.2 lib/avo/fields/has_base_field.rb
avo-1.22.1.pre.1 lib/avo/fields/has_base_field.rb
avo-1.22.0 lib/avo/fields/has_base_field.rb
avo-1.22.0.pre.1 lib/avo/fields/has_base_field.rb
avo-1.21.1.pre.1 lib/avo/fields/has_base_field.rb
avo-1.21.0 lib/avo/fields/has_base_field.rb
avo-1.20.2.pre.2 lib/avo/fields/has_base_field.rb
avo-1.20.2.pre.1 lib/avo/fields/has_base_field.rb
avo-1.21.0.pre.1 lib/avo/fields/has_base_field.rb
avo-1.20.1 lib/avo/fields/has_base_field.rb
avo-1.19.1.pre.11 lib/avo/fields/has_base_field.rb
avo-1.19.1.pre.10 lib/avo/fields/has_base_field.rb