Allow custom options in links to actions
Some links were using options like `remote: true`.
This commit is contained in:
@@ -1,11 +1,7 @@
|
||||
<% if actions.include?(:edit) %>
|
||||
<%= link_to edit_text, edit_path, class: "button hollow" %>
|
||||
<%= link_to edit_text, edit_path, edit_options %>
|
||||
<% end %>
|
||||
|
||||
<% if actions.include?(:destroy) %>
|
||||
<%= link_to destroy_text,
|
||||
destroy_path,
|
||||
method: :delete,
|
||||
class: "button hollow alert",
|
||||
data: { confirm: destroy_confirmation } %>
|
||||
<%= link_to destroy_text, destroy_path, destroy_options %>
|
||||
<% end %>
|
||||
|
||||
@@ -20,6 +20,10 @@ class Admin::TableActionsComponent < ApplicationComponent
|
||||
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
|
||||
@@ -28,6 +32,14 @@ class Admin::TableActionsComponent < ApplicationComponent
|
||||
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
|
||||
|
||||
@@ -11,13 +11,14 @@
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<%= link_to t("admin.booth_assignments.manage.actions.unassign"),
|
||||
admin_poll_booth_assignment_path(@poll, booth_assignment),
|
||||
method: :delete,
|
||||
remote: true,
|
||||
title: t("admin.booth_assignments.manage.actions.unassign"),
|
||||
class: "button hollow alert expanded",
|
||||
data: (booth_assignment.shifts? ? { confirm: "#{t("admin.poll_booth_assignments.alert.shifts")}" } : nil) if !@poll.expired? %>
|
||||
<% unless @poll.expired? %>
|
||||
<%= render Admin::TableActionsComponent.new(booth_assignment,
|
||||
actions: [:destroy],
|
||||
destroy_text: t("admin.booth_assignments.manage.actions.unassign"),
|
||||
destroy_confirmation: (booth_assignment.shifts? ? "#{t("admin.poll_booth_assignments.alert.shifts")}" : ""),
|
||||
destroy_options: { remote: true }
|
||||
) %>
|
||||
<% end %>
|
||||
</td>
|
||||
<% else %>
|
||||
<td>
|
||||
|
||||
@@ -48,4 +48,10 @@ describe Admin::TableActionsComponent, type: :component do
|
||||
|
||||
expect(page).to have_css "a[data-confirm='Are you mad? Be careful!']"
|
||||
end
|
||||
|
||||
it "allows custom options" do
|
||||
render_inline Admin::TableActionsComponent.new(record, edit_options: { id: "edit_me" })
|
||||
|
||||
expect(page).to have_css "a#edit_me"
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user