Sha256: c25fa55e15827a7408647c2a39c642cdc391000b0a8201b176bcc9ce779e0c70

Contents?: true

Size: 984 Bytes

Versions: 46

Compression:

Stored size: 984 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::App.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?
          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

46 entries across 46 versions & 1 rubygems

Version Path
avo-1.13.0 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.12.4 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.12.3 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.12.2 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.12.1 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.12.0 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.11.6 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.11.5 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.11.4 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.11.3 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.11.2 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.11.1 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.10.3 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.11.0 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.10.2 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.10.1 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.10.0 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.9.1 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.9.0 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.8.4 lib/avo/fields/has_and_belongs_to_many_field.rb