Sha256: 56dd4f516e3513762bdcadba306efbfbefb3b5c381fae26f3aacbe7016ee09fe

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

module ActionLink
  # An action link that indicates deleting a new record.
  class Destroy < Base
    ICON = 'times-circle'

    erb_template <<~ERB.gsub("\n", '')
      <% if permission? %>
      <%= link_to(url, **options) do %>
      <%= content %>
      <% if icon? %><%= ' ' %><%= icon_tag ::ActionLink::Destroy::ICON %><% end %>
      <% end %>
      <% else %>
      <%= content %>
      <% end %>
    ERB

    option :url
    option :confirmation, as: :manual_confirmation, default: -> {}
    option :confirmation_subject, default: -> {}
    option :associative, default: -> { false }

    def i18n_title_key
      return 'action_link_component.titles.unassign' if associative

      super
    end

    def confirmation
      return manual_confirmation if manual_confirmation

      I18n.t(i18n_confirmation_key,
             subject: strip_tags(confirmation_subject || default_confirmation_subject))
    end

    def http_method
      :delete
    end

    private

    def i18n_confirmation_key
      if associative
        'action_link_component.confirmations.unassign'
      else
        'action_link_component.confirmations.destroy'
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
action_link-0.1.1 app/components/action_link/destroy.rb