Sha256: 6422e441e781b524495e15c6e438963129f0442ccf9380ad7aee3ce942126fe3

Contents?: true

Size: 956 Bytes

Versions: 19

Compression:

Stored size: 956 Bytes

Contents

module Alchemy
  module Admin
    class AttachmentSelect < ViewComponent::Base
      delegate :alchemy, to: :helpers

      def initialize(attachment = nil, url: nil, placeholder: Alchemy.t("Please choose"), query_params: nil)
        @attachment = attachment
        @url = url
        @placeholder = placeholder
        @query_params = query_params
      end

      def call
        content_tag("alchemy-attachment-select", content, attributes)
      end

      private

      def attributes
        options = {
          "allow-clear": true,
          placeholder: @placeholder,
          url: @url || alchemy.api_attachments_path
        }

        if @query_params
          options[:"query-params"] = @query_params.to_json
        end

        if @attachment
          selection = ActiveModelSerializers::SerializableResource.new(@attachment)
          options[:selection] = selection.to_json
        end

        options
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
alchemy_cms-7.4.2 app/components/alchemy/admin/attachment_select.rb
alchemy_cms-7.3.6 app/components/alchemy/admin/attachment_select.rb
alchemy_cms-7.2.9 app/components/alchemy/admin/attachment_select.rb
alchemy_cms-7.4.1 app/components/alchemy/admin/attachment_select.rb
alchemy_cms-7.4.0 app/components/alchemy/admin/attachment_select.rb
alchemy_cms-7.3.5 app/components/alchemy/admin/attachment_select.rb
alchemy_cms-7.2.8 app/components/alchemy/admin/attachment_select.rb
alchemy_cms-7.3.4 app/components/alchemy/admin/attachment_select.rb
alchemy_cms-7.3.3 app/components/alchemy/admin/attachment_select.rb
alchemy_cms-7.3.2 app/components/alchemy/admin/attachment_select.rb
alchemy_cms-7.2.7 app/components/alchemy/admin/attachment_select.rb
alchemy_cms-7.3.1 app/components/alchemy/admin/attachment_select.rb
alchemy_cms-7.3.0 app/components/alchemy/admin/attachment_select.rb
alchemy_cms-7.2.6 app/components/alchemy/admin/attachment_select.rb
alchemy_cms-7.2.5 app/components/alchemy/admin/attachment_select.rb
alchemy_cms-7.2.4 app/components/alchemy/admin/attachment_select.rb
alchemy_cms-7.2.3 app/components/alchemy/admin/attachment_select.rb
alchemy_cms-7.2.2 app/components/alchemy/admin/attachment_select.rb
alchemy_cms-7.2.1 app/components/alchemy/admin/attachment_select.rb