Sha256: cb222cbdfe1f6f95b47602f6d26411889b33bc09074c908dfd1d1cc67673c98e

Contents?: true

Size: 1.36 KB

Versions: 30

Compression:

Stored size: 1.36 KB

Contents

module Avo
  module Fields
    class TrixField < BaseField
      attr_reader :always_show
      attr_reader :attachment_key
      attr_reader :hide_attachment_filename
      attr_reader :hide_attachment_filesize
      attr_reader :hide_attachment_url

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

        hide_on :index

        @always_show = args[:always_show] || false
        @attachment_key = args[:attachment_key]
        @attachments_disabled = args[:attachments_disabled]
        @hide_attachment_filename = args[:hide_attachment_filename] || false
        @hide_attachment_filesize = args[:hide_attachment_filesize] || false
        @hide_attachment_url = args[:hide_attachment_url] || false
      end

      # Identify if field is bonded to a rich text model attribute
      def is_action_text?
        return false if !defined?(ActionText::RichText) || record.nil? || !record.respond_to?(id)

        record.send(id).is_a?(ActionText::RichText)
      end

      def attachments_disabled
        # Return the value of attachments_disabled if explicitly provided
        return @attachments_disabled unless @attachments_disabled.nil?

        # By default enable attachments on action text
        return false if is_action_text?

        # Disable attachments if attachment_key is not present
        @attachment_key.blank?
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
avo-3.18.1.tw4 lib/avo/fields/trix_field.rb
avo-3.18.1 lib/avo/fields/trix_field.rb
avo-3.18.0.tw4 lib/avo/fields/trix_field.rb
avo-3.18.0 lib/avo/fields/trix_field.rb
avo-3.17.9.beta2 lib/avo/fields/trix_field.rb
avo-3.17.9.beta1 lib/avo/fields/trix_field.rb
avo-3.17.9.tw4 lib/avo/fields/trix_field.rb
avo-3.17.9 lib/avo/fields/trix_field.rb
avo-3.17.8.tw4 lib/avo/fields/trix_field.rb
avo-3.17.8 lib/avo/fields/trix_field.rb
avo-3.17.7 lib/avo/fields/trix_field.rb
avo-3.17.6.tw4 lib/avo/fields/trix_field.rb
avo-3.17.6 lib/avo/fields/trix_field.rb
avo-3.17.5 lib/avo/fields/trix_field.rb
avo-3.17.4 lib/avo/fields/trix_field.rb
avo-3.17.3 lib/avo/fields/trix_field.rb
avo-3.17.5.tw4 lib/avo/fields/trix_field.rb
avo-3.17.4.tw4 lib/avo/fields/trix_field.rb
avo-3.17.3.tw4 lib/avo/fields/trix_field.rb
avo-3.17.2.tw4 lib/avo/fields/trix_field.rb