Files
grecia/app/components/admin/table_actions_component.rb
Javi Martín e3753b1ad9 Allow custom options in links to actions
Some links were using options like `remote: true`.
2020-10-19 18:56:02 +02:00

47 lines
1.0 KiB
Ruby

class Admin::TableActionsComponent < ApplicationComponent
attr_reader :record, :options
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] || admin_polymorphic_path(record, action: :edit)
end
def edit_options
{ class: "button hollow" }.merge(options[:edit_options] || {})
end
def destroy_text
options[:destroy_text] || t("admin.actions.delete")
end
def destroy_path
options[:destroy_path] || admin_polymorphic_path(record)
end
def destroy_options
{
method: :delete,
class: "button hollow alert",
data: { confirm: destroy_confirmation }
}.merge(options[:destroy_options] || {})
end
def destroy_confirmation
options[:destroy_confirmation] || t("admin.actions.confirm")
end
end