Files
grecia/app/components/admin/table_actions_component.rb
Javi Martín c66a5a30ef Allow using table actions in different namespaces
This way we can reuse it in sections like SDGManagement and URLs will be
automatically generated as expected.
2021-01-14 17:35:38 +01:00

49 lines
1.1 KiB
Ruby

class Admin::TableActionsComponent < ApplicationComponent
include TableActionLink
attr_reader :record, :options
delegate :namespace, to: :helpers
def initialize(record = nil, **options)
@record = record
@options = options
end
private
def actions
options[:actions] || [:edit, :destroy]
end
def edit_text
options[:edit_text] || t("admin.actions.edit")
end
def edit_path
options[:edit_path] || namespaced_polymorphic_path(namespace, record, action: :edit)
end
def edit_options
{ class: "edit-link" }.merge(options[:edit_options] || {})
end
def destroy_text
options[:destroy_text] || t("admin.actions.delete")
end
def destroy_path
options[:destroy_path] || namespaced_polymorphic_path(namespace, record)
end
def destroy_options
{
method: :delete,
class: "destroy-link",
data: { confirm: destroy_confirmation }
}.merge(options[:destroy_options] || {})
end
def destroy_confirmation
options[:destroy_confirmation] || t("admin.actions.confirm")
end
end