aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2017-06-15 14:37:14 +0200
committerTeddy Wing2017-06-15 14:37:14 +0200
commit3b621ee93c5097c55bd4ce4c7bdecdaa18c6f9ab (patch)
treee4c5fd925687018476e51435511b686b456a03b1
parent5897637c559ba3d37e4f02b97149ff7dab927ef2 (diff)
downloadchouette-core-3b621ee93c5097c55bd4ce4c7bdecdaa18c6f9ab.tar.bz2
TableBuilder: Make destroy link in gear menu render correctly
Previously we weren't correctly outputting the proper HTML to get the :delete link rendering correctly with the icon and text. It should show: [TRASH CAN ICON] Supprimer but instead was showing the href. To get this working, I added a `@content` attribute to `Link`. This allows us to optionally specify non-text content to display in the link. We then have delete-link-specific handling when rendering the gear menu's HTML. In that particular case, the `<li>` needs to have a 'delete-action' class in order for the styling to work properly. Created a new `destroy_link` helper method to allow us to reuse the destroy link content in the header bar. TODO: Collect Link#content and Link#name into the same property. TODO: Rename `#destroy_link` to `#destroy_link_content` Refs #3479
-rw-r--r--app/decorators/referential_decorator.rb3
-rw-r--r--app/helpers/links_helper.rb5
-rw-r--r--app/helpers/table_builder_helper.rb18
-rw-r--r--lib/link.rb5
4 files changed, 21 insertions, 10 deletions
diff --git a/app/decorators/referential_decorator.rb b/app/decorators/referential_decorator.rb
index 5112f9dd4..8b3b54f2a 100644
--- a/app/decorators/referential_decorator.rb
+++ b/app/decorators/referential_decorator.rb
@@ -39,7 +39,8 @@ class ReferentialDecorator < Draper::Decorator
links << Link.new(
href: h.referential_path(object),
method: :delete,
- data: { confirm: h.t('referentials.actions.destroy_confirm') }
+ data: { confirm: h.t('referentials.actions.destroy_confirm') },
+ content: h.destroy_link
)
end
diff --git a/app/helpers/links_helper.rb b/app/helpers/links_helper.rb
new file mode 100644
index 000000000..48cfe9ca4
--- /dev/null
+++ b/app/helpers/links_helper.rb
@@ -0,0 +1,5 @@
+module LinksHelper
+ def destroy_link
+ content_tag(:span, nil, class: 'fa fa-trash') + t('actions.destroy')
+ end
+end
diff --git a/app/helpers/table_builder_helper.rb b/app/helpers/table_builder_helper.rb
index 4537a0795..af05a7354 100644
--- a/app/helpers/table_builder_helper.rb
+++ b/app/helpers/table_builder_helper.rb
@@ -113,13 +113,17 @@ module TableBuilderHelper
CustomLinks.new(item, pundit_user, links).links +
item.action_links
).map do |link|
- # TODO: ensure the Delete link is formatted correctly with the spacer,
- # icon, and label
- content_tag :li, link_to(
- link.name,
- link.href,
- method: link.method,
- data: link.data
+ # TODO: make a new method for this
+ content_tag(
+ :li,
+ link_to(
+ link.href,
+ method: link.method,
+ data: link.data
+ ) do
+ link.content || link.name
+ end,
+ class: link.method == :delete ? 'delete-action' : '',
)
end.join.html_safe
diff --git a/lib/link.rb b/lib/link.rb
index c875b85ac..3ce12ae24 100644
--- a/lib/link.rb
+++ b/lib/link.rb
@@ -1,10 +1,11 @@
class Link
- attr_reader :name, :href, :method, :data
+ attr_reader :name, :href, :method, :data, :content
- def initialize(name: nil, href:, method: nil, data: nil)
+ def initialize(name: nil, href:, method: nil, data: nil, content: nil)
@name = name
@href = href
@method = method
@data = data
+ @content = content
end
end