Sha256: ffa051a77f2bb05199829bf1338fb6e017780e119c11a3fbd89be9cc476a5813

Contents?: true

Size: 1.27 KB

Versions: 144

Compression:

Stored size: 1.27 KB

Contents

module Avo
  module Fields
    class FilesField < BaseField
      attr_accessor :is_audio
      attr_accessor :is_image
      attr_accessor :direct_upload
      attr_accessor :accept
      attr_reader :display_filename
      attr_reader :view_type
      attr_reader :hide_view_type_switcher

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

        @is_audio = args[:is_audio].present? ? args[:is_audio] : false
        @is_image = args[:is_image].present? ? args[:is_image] : @is_avatar
        @direct_upload = args[:direct_upload].present? ? args[:direct_upload] : false
        @accept = args[:accept].present? ? args[:accept] : nil
        @display_filename = args[:display_filename].nil? ? true : args[:display_filename]
        @view_type = args[:view_type] || :grid
        @hide_view_type_switcher = args[:hide_view_type_switcher]
      end

      def view_component_name
        "FilesField"
      end

      def to_permitted_param
        {"#{id}": []}
      end

      def fill_field(model, key, value, params)
        return model unless model.methods.include? key.to_sym

        value.each do |file|
          # Skip empty values
          next unless file.present?

          model.send(key).attach file
        end

        model
      end
    end
  end
end

Version data entries

144 entries across 144 versions & 1 rubygems

Version Path
avo-2.53.0 lib/avo/fields/files_field.rb
avo-2.52.0 lib/avo/fields/files_field.rb
avo-3.10.7 lib/avo/fields/files_field.rb
avo-3.10.6 lib/avo/fields/files_field.rb
avo-3.10.5 lib/avo/fields/files_field.rb
avo-3.10.4 lib/avo/fields/files_field.rb
avo-3.10.3 lib/avo/fields/files_field.rb
avo-3.10.2 lib/avo/fields/files_field.rb
avo-3.10.1 lib/avo/fields/files_field.rb
avo-3.10.0 lib/avo/fields/files_field.rb
avo-3.9.2 lib/avo/fields/files_field.rb
avo-3.9.1 lib/avo/fields/files_field.rb
avo-3.8.2 lib/avo/fields/files_field.rb
avo-3.9.0 lib/avo/fields/files_field.rb
avo-3.8.1 lib/avo/fields/files_field.rb
avo-3.8.0 lib/avo/fields/files_field.rb
avo-3.6.4 lib/avo/fields/files_field.rb
avo-3.6.3 lib/avo/fields/files_field.rb
avo-3.6.2 lib/avo/fields/files_field.rb
avo-2.49.0 lib/avo/fields/files_field.rb