Sha256: 25ae954cd9d4cb9dbdbd388c2fed1e7c6023d8a415be8e71812ef55b6c78c09f

Contents?: true

Size: 978 Bytes

Versions: 23

Compression:

Stored size: 978 Bytes

Contents

module Avo
  module Fields
    class HasAndBelongsToManyField < BaseField
      def initialize(id, **args, &block)
        args[:updatable] = false

        super(id, **args, &block)

        hide_on :all
        show_on :show
      end

      def view_component_name
        "HasManyField"
      end

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

      def frame_url
        "#{Avo.configuration.root_path}/resources/#{@model.model_name.route_key}/#{@model.id}/#{id}?turbo_frame=#{turbo_frame}"
      end

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

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
avo-1.7.2 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.7.1 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.7.0 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.6.4.pre.1 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.6.3.pre.3 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.6.3.pre.2 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.6.3.pre.1 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.6.2.pre.1 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.6.1 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.6.0 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.5.5 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.5.4 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.5.3 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.5.2 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.5.1 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.5.0 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.4.5.pre.1 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.4.4.pre.1 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.4.4 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.4.3 lib/avo/fields/has_and_belongs_to_many_field.rb