Sha256: 9037df3a797b3a35ff125b299a9b3d45434eb8eaf46520a8ea432bf4727d6e92

Contents?: true

Size: 1.04 KB

Versions: 24

Compression:

Stored size: 1.04 KB

Contents

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

      def initialize(page = nil, url: nil, allow_clear: false, placeholder: Alchemy.t(:search_page), query_params: nil)
        @page = page
        @url = url
        @allow_clear = allow_clear
        @placeholder = placeholder
        @query_params = query_params
      end

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

      private

      def attributes
        options = {
          placeholder: @placeholder,
          url: @url || alchemy.api_pages_path
        }

        options = options.merge({"allow-clear": @allow_clear}) if @allow_clear
        options = options.merge({"query-params": @query_params.to_json}) if @query_params

        if @page
          selection = {
            id: @page.id,
            name: @page.name,
            url_path: @page.url_path
          }
          options = options.merge({selection: selection.to_json})
        end

        options
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
alchemy_cms-7.2.7 app/components/alchemy/admin/page_select.rb
alchemy_cms-7.3.0 app/components/alchemy/admin/page_select.rb
alchemy_cms-7.2.6 app/components/alchemy/admin/page_select.rb
alchemy_cms-7.2.5 app/components/alchemy/admin/page_select.rb
alchemy_cms-7.1.12 app/components/alchemy/admin/page_select.rb
alchemy_cms-7.2.4 app/components/alchemy/admin/page_select.rb
alchemy_cms-7.1.11 app/components/alchemy/admin/page_select.rb
alchemy_cms-7.2.3 app/components/alchemy/admin/page_select.rb
alchemy_cms-7.1.10 app/components/alchemy/admin/page_select.rb
alchemy_cms-7.2.2 app/components/alchemy/admin/page_select.rb
alchemy_cms-7.1.9 app/components/alchemy/admin/page_select.rb
alchemy_cms-7.2.1 app/components/alchemy/admin/page_select.rb
alchemy_cms-7.1.8 app/components/alchemy/admin/page_select.rb
alchemy_cms-7.1.7 app/components/alchemy/admin/page_select.rb
alchemy_cms-7.1.6 app/components/alchemy/admin/page_select.rb
alchemy_cms-7.1.5 app/components/alchemy/admin/page_select.rb
alchemy_cms-7.1.4 app/components/alchemy/admin/page_select.rb
alchemy_cms-7.1.3 app/components/alchemy/admin/page_select.rb
alchemy_cms-7.1.2 app/components/alchemy/admin/page_select.rb
alchemy_cms-7.1.1 app/components/alchemy/admin/page_select.rb