diff options
| author | Teddy Wing | 2017-06-15 12:09:58 +0200 |
|---|---|---|
| committer | Teddy Wing | 2017-06-15 12:09:58 +0200 |
| commit | 9a2be7854d2149f812f90dd9f42f680199e573d4 (patch) | |
| tree | c068320e1b3d46bf61a5ec7cbcd79b48e69da35f | |
| parent | 670b3b9a4be43bd6aea1d198cfe39f158ec1187f (diff) | |
| download | chouette-core-9a2be7854d2149f812f90dd9f42f680199e573d4.tar.bz2 | |
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
| -rw-r--r-- | app/decorators/company_decorator.rb | 29 |
1 files changed, 29 insertions, 0 deletions
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 |
