Skip to content

Commit df3fe05

Browse files
committed
Add shared resource toolbar for CRUD actions
1 parent d285fda commit df3fe05

File tree

12 files changed

+98
-70
lines changed

12 files changed

+98
-70
lines changed

app/views/better_together/calls_for_interest/show.html.erb

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,12 @@
2222
<% end %>
2323
</div>
2424
<div class="col-auto">
25-
<% if policy(@resource).edit? %>
26-
<%= link_to edit_call_for_interest_path(@resource), class: 'btn btn-outline-primary btn-sm me-2', 'aria-label' => 'Edit Partner' do %>
27-
<i class="fas fa-edit"></i> <%= t('globals.edit') %>
28-
<% end %>
29-
<% end %>
30-
<% if policy(@resource).destroy? %>
31-
<%= link_to call_for_interest_path(@resource), data: { turbo_method: :delete, turbo_confirm: t('globals.confirm_delete') }, class: 'btn btn-outline-danger btn-sm', 'aria-label' => 'Delete Record' do %>
32-
<i class="fas fa-trash-alt"></i> <%= t('globals.delete') %>
33-
<% end %>
34-
<% end %>
25+
<%= render 'shared/resource_toolbar',
26+
edit_path: policy(@resource).edit? ? edit_call_for_interest_path(@resource) : nil,
27+
edit_aria_label: 'Edit Partner',
28+
destroy_path: policy(@resource).destroy? ? call_for_interest_path(@resource) : nil,
29+
destroy_confirm: t('globals.confirm_delete'),
30+
destroy_aria_label: 'Delete Record' %>
3531
</div>
3632
</div>
3733
</div>

app/views/better_together/categories/show.html.erb

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,11 @@
1212
<% if policy(resource_class).index? %>
1313
<%= link_to t('better_together.categories.back_to_categories'), categories_path, class: 'btn btn-sm btn-outline-secondary' %>
1414
<% end %>
15-
<% if policy(@resource).edit? %>
16-
<%= link_to edit_category_path(@resource), class: 'btn btn-outline-primary btn-sm me-2', 'aria-label' => 'Edit Partner' do %>
17-
<i class="fas fa-edit"></i> <%= t('globals.edit') %>
18-
<% end %>
19-
<% end %>
20-
<% if policy(@resource).destroy? %>
21-
<%= link_to category_path(@resource), data: { turbo_method: :delete, turbo_confirm: t('globals.confirm_delete') }, class: 'btn btn-outline-danger btn-sm', 'aria-label' => 'Delete Record' do %>
22-
<i class="fas fa-trash-alt"></i> <%= t('globals.delete') %>
23-
<% end %>
24-
<% end %>
15+
<%= render 'shared/resource_toolbar',
16+
edit_path: policy(@resource).edit? ? edit_category_path(@resource) : nil,
17+
edit_aria_label: 'Edit Partner',
18+
destroy_path: policy(@resource).destroy? ? category_path(@resource) : nil,
19+
destroy_confirm: t('globals.confirm_delete'),
20+
destroy_aria_label: 'Delete Record' %>
2521
</div>
2622
</div>

app/views/better_together/communities/show.html.erb

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,12 @@
2727
<%= privacy_badge(@resource) %>
2828
</div>
2929
<div class="col-auto">
30-
<% if policy(@resource).edit? %>
31-
<%= link_to edit_community_path(@resource), class: 'btn btn-outline-primary btn-sm me-2', 'aria-label' => 'Edit Partner' do %>
32-
<i class="fas fa-edit"></i> <%= t('globals.edit') %>
33-
<% end %>
34-
<% end %>
35-
<% if policy(@resource).destroy? %>
36-
<%= link_to community_path(@resource), data: { turbo_method: :delete, turbo_confirm: t('partners.confirm_delete') }, class: 'btn btn-outline-danger btn-sm', 'aria-label' => 'Delete Partner' do %>
37-
<i class="fas fa-trash-alt"></i> <%= t('globals.delete') %>
38-
<% end %>
39-
<% end %>
30+
<%= render 'shared/resource_toolbar',
31+
edit_path: policy(@resource).edit? ? edit_community_path(@resource) : nil,
32+
edit_aria_label: 'Edit Partner',
33+
destroy_path: policy(@resource).destroy? ? community_path(@resource) : nil,
34+
destroy_confirm: t('partners.confirm_delete'),
35+
destroy_aria_label: 'Delete Partner' %>
4036
</div>
4137
</div>
4238
</div>

app/views/better_together/events/show.html.erb

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,12 @@
2929
<% end %>
3030
</div>
3131
<div class="col-auto">
32-
<% if policy(@resource).edit? %>
33-
<%= link_to edit_event_path(@resource), class: 'btn btn-outline-primary btn-sm me-2', 'aria-label' => 'Edit Partner' do %>
34-
<i class="fas fa-edit"></i> <%= t('globals.edit') %>
35-
<% end %>
36-
<% end %>
37-
<% if policy(@resource).destroy? %>
38-
<%= link_to event_path(@resource), data: { turbo_method: :delete, turbo_confirm: t('globals.confirm_delete') }, class: 'btn btn-outline-danger btn-sm', 'aria-label' => 'Delete Record' do %>
39-
<i class="fas fa-trash-alt"></i> <%= t('globals.delete') %>
40-
<% end %>
41-
<% end %>
32+
<%= render 'shared/resource_toolbar',
33+
edit_path: policy(@resource).edit? ? edit_event_path(@resource) : nil,
34+
edit_aria_label: 'Edit Partner',
35+
destroy_path: policy(@resource).destroy? ? event_path(@resource) : nil,
36+
destroy_confirm: t('globals.confirm_delete'),
37+
destroy_aria_label: 'Delete Record' %>
4238
</div>
4339
</div>
4440
</div>

app/views/better_together/people/show.html.erb

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,12 @@
2626
<%= privacy_badge(@person) %>
2727
</div>
2828
<div class="col-auto">
29-
<% if policy(@person).edit? %>
30-
<%= link_to edit_person_path(@person), class: 'btn btn-outline-primary btn-sm me-2', 'aria-label' => 'Edit Profile' do %>
31-
<i class="fas fa-edit"></i> <%= t('globals.edit') %>
32-
<% end %>
33-
<% end %>
34-
<% if policy(@person).destroy? %>
35-
<%= link_to person_path(@person), method: :delete, data: { turbo_method: :delete, confirm: t('people.confirm_delete') }, class: 'btn btn-outline-danger btn-sm', 'aria-label' => 'Delete Profile' do %>
36-
<i class="fas fa-trash-alt"></i> <%= t('globals.delete') %>
37-
<% end %>
38-
<% end %>
29+
<%= render 'shared/resource_toolbar',
30+
edit_path: policy(@person).edit? ? edit_person_path(@person) : nil,
31+
edit_aria_label: 'Edit Profile',
32+
destroy_path: policy(@person).destroy? ? person_path(@person) : nil,
33+
destroy_confirm: t('people.confirm_delete'),
34+
destroy_aria_label: 'Delete Profile' %>
3935
</div>
4036
</div>
4137
</div>

app/views/better_together/platforms/show.html.erb

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,12 @@
2424
<p class="profile-description"><%= @platform.description.presence || t('globals.no_description') %></p>
2525
</div>
2626
<div class="col-auto">
27-
<% if policy(@platform).edit? %>
28-
<%= link_to edit_platform_path(@platform), class: 'btn btn-outline-primary btn-sm me-2', 'aria-label' => 'Edit Platform' do %>
29-
<i class="fas fa-edit"></i> <%= t('globals.edit') %>
30-
<% end %>
31-
<% end %>
32-
<% if policy(@platform).destroy? %>
33-
<%= link_to platform_path(@platform), method: :delete, data: { turbo_method: :delete, confirm: t('platforms.confirm_delete') }, class: 'btn btn-outline-danger btn-sm', 'aria-label' => 'Delete Platform' do %>
34-
<i class="fas fa-trash-alt"></i> <%= t('globals.delete') %>
35-
<% end %>
36-
<% end %>
27+
<%= render 'shared/resource_toolbar',
28+
edit_path: policy(@platform).edit? ? edit_platform_path(@platform) : nil,
29+
edit_aria_label: 'Edit Platform',
30+
destroy_path: policy(@platform).destroy? ? platform_path(@platform) : nil,
31+
destroy_confirm: t('platforms.confirm_delete'),
32+
destroy_aria_label: 'Delete Platform' %>
3733
</div>
3834
</div>
3935
</div>

app/views/better_together/posts/show.html.erb

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,11 @@
1313
<% if policy(resource_class).index? %>
1414
<%= link_to t('better_together.posts.back_to_posts', default: 'Back to Posts'), posts_path, class: 'btn btn-sm btn-outline-secondary' %>
1515
<% end %>
16-
<% if policy(@post).edit? %>
17-
<%= link_to edit_post_path(@post), class: 'btn btn-outline-primary btn-sm me-2', 'aria-label' => 'Edit Post' do %>
18-
<i class="fas fa-edit"></i> <%= t('globals.edit') %>
19-
<% end %>
20-
<% end %>
21-
<% if policy(@post).destroy? %>
22-
<%= link_to post_path(@post), data: { turbo_method: :delete, turbo_confirm: t('globals.confirm_delete') }, class: 'btn btn-outline-danger btn-sm', 'aria-label' => 'Delete Record' do %>
23-
<i class="fas fa-trash-alt"></i> <%= t('globals.delete') %>
24-
<% end %>
25-
<% end %>
16+
<%= render 'shared/resource_toolbar',
17+
edit_path: policy(@post).edit? ? edit_post_path(@post) : nil,
18+
edit_aria_label: 'Edit Post',
19+
destroy_path: policy(@post).destroy? ? post_path(@post) : nil,
20+
destroy_confirm: t('globals.confirm_delete'),
21+
destroy_aria_label: 'Delete Record' %>
2622
</div>
2723
</div>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<%# Renders a toolbar with optional action buttons for a resource.
2+
Locals:
3+
edit_path: path for edit action (optional)
4+
edit_aria_label: aria-label for edit button (defaults to t('globals.edit'))
5+
preview_path: path for preview action (optional)
6+
preview_aria_label: aria-label for preview button (defaults to t('globals.preview'))
7+
destroy_path: path for destroy action (optional)
8+
destroy_confirm: confirmation message (defaults to t('globals.confirm_delete'))
9+
destroy_aria_label: aria-label for destroy button (defaults to t('globals.delete'))
10+
%>
11+
<div class="resource-toolbar">
12+
<% if local_assigns[:edit_path] %>
13+
<%= link_to edit_path, class: 'btn btn-outline-primary btn-sm me-2', 'aria-label' => (local_assigns[:edit_aria_label] || t('globals.edit')) do %>
14+
<i class="fas fa-edit"></i> <%= t('globals.edit') %>
15+
<% end %>
16+
<% end %>
17+
<% if local_assigns[:preview_path] %>
18+
<%= link_to preview_path, class: 'btn btn-outline-secondary btn-sm me-2', 'aria-label' => (local_assigns[:preview_aria_label] || t('globals.preview')) do %>
19+
<i class="fas fa-eye"></i> <%= t('globals.preview') %>
20+
<% end %>
21+
<% end %>
22+
<% if local_assigns[:destroy_path] %>
23+
<%= link_to destroy_path, data: { turbo_method: :delete, turbo_confirm: (local_assigns[:destroy_confirm] || t('globals.confirm_delete')) }, class: 'btn btn-outline-danger btn-sm', 'aria-label' => (local_assigns[:destroy_aria_label] || t('globals.delete')) do %>
24+
<i class="fas fa-trash-alt"></i> <%= t('globals.delete') %>
25+
<% end %>
26+
<% end %>
27+
</div>

config/locales/en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,6 +1273,7 @@ en:
12731273
destroy: Destroy
12741274
draft: Draft
12751275
edit: Edit
1276+
preview: Preview
12761277
'false': 'No'
12771278
forms:
12781279
save: Save

config/locales/es.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,7 @@ es:
12591259
destroy: Destruir
12601260
draft: Borrador
12611261
edit: Editar
1262+
preview: Vista previa
12621263
'false': 'No'
12631264
forms:
12641265
save: Guardar

0 commit comments

Comments
 (0)