From 9a2be7854d2149f812f90dd9f42f680199e573d4 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 15 Jun 2017 12:09:58 +0200 Subject: CompanyDecorator: Add `#action_links` Copy the links from "companies/show.html.slim" into this method so they can be reused here and in the gear menu in the table on the Companies#index page. Refs #3479 --- app/decorators/company_decorator.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/app/decorators/company_decorator.rb b/app/decorators/company_decorator.rb index 3a0cc16ce..7d14f8c8b 100644 --- a/app/decorators/company_decorator.rb +++ b/app/decorators/company_decorator.rb @@ -9,4 +9,33 @@ class CompanyDecorator < Draper::Decorator object.lines.count end + def action_links + links = [] + + if h.policy(Chouette::Company).create? + links << Link.new( + name: h.t('companies.actions.new'), + href: h.new_line_referential_company_path(@line_referential) + ) + end + + if h.policy(object).update? + links << Link.new( + name: h.t('companies.actions.edit'), + href: h.edit_line_referential_company_path(@line_referential, object) + ) + end + + if h.policy(object).destroy? + links << Link.new( + name: t('companies.actions.destroy'), + href: h.line_referential_company_path(@line_referential, object), + method: :delete, + data: { confirm: t('companies.actions.destroy_confirm') } + ) + end + + links + end + end -- cgit v1.2.3