Note the CSS could probably be improved to avoid duplication with other button style definitions. However, that's fine because we're going to change the style of the links soon. For the same reason, I haven't bothered to style every single link the way it was until now.
48 lines
1.0 KiB
Ruby
48 lines
1.0 KiB
Ruby
class Admin::TableActionsComponent < ApplicationComponent
|
|
include TableActionLink
|
|
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: "edit-link" }.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: "destroy-link",
|
|
data: { confirm: destroy_confirmation }
|
|
}.merge(options[:destroy_options] || {})
|
|
end
|
|
|
|
def destroy_confirmation
|
|
options[:destroy_confirmation] || t("admin.actions.confirm")
|
|
end
|
|
end
|