Sha256: 389f787323593154f3467dfdc513816376671a8f809200699c29ba9f42c6cb5c

Contents?: true

Size: 1023 Bytes

Versions: 36

Compression:

Stored size: 1023 Bytes

Contents

module Avo
  module Fields
    class HasAndBelongsToManyField < BaseField
      def initialize(name, **args, &block)
        @defaults = {
          updatable: false,
          partial_name: "has-many-field"
        }

        super(name, **args, &block)

        hide_on :all
        show_on :show

        @resource = args[:resource]
      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

36 entries across 36 versions & 1 rubygems

Version Path
avo-1.4.0.pre.1 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.3.5 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.3.5.pre.1 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.3.4 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.3.3 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.3.2 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.3.1 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.3.0 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.2.11.pre.4 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.2.11.pre.3 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.2.11.pre.2 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.2.11.pre.1 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.2.10 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.2.9 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.2.8 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.2.7 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.2.6 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.2.6.pre.1 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.2.5 lib/avo/fields/has_and_belongs_to_many_field.rb
avo-1.2.4 lib/avo/fields/has_and_belongs_to_many_field.rb