diff options
| author | Teddy Wing | 2018-01-24 17:01:42 +0100 |
|---|---|---|
| committer | Zog | 2018-01-25 17:18:02 +0100 |
| commit | c02c597cfcd8d21c9bf59d41dbd312e9c26289b8 (patch) | |
| tree | ec76fa7f6bc7b43df03e764175d9b04abef2ac5a /app | |
| parent | 5e41dbed021522331532eb0151ac441553be2d13 (diff) | |
| download | chouette-core-c02c597cfcd8d21c9bf59d41dbd312e9c26289b8.tar.bz2 | |
PurchaseWindowDecorator: Convert to new action links interface
Also add a new method `AF83::Decorator.define_instance_method`. Thanks
to Johan for suggesting that and walking me through writing it. This new
method allows us to define methods on the instance decorator. We need
this to preserve the `#bounding_dates` method that was defined in
`PurchaseWindowDecorator`.
Refs #5586
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/purchase_windows_controller.rb | 7 | ||||
| -rw-r--r-- | app/decorators/purchase_window_decorator.rb | 44 | ||||
| -rw-r--r-- | app/views/purchase_windows/index.html.slim | 4 | ||||
| -rw-r--r-- | app/views/purchase_windows/show.html.slim | 9 |
4 files changed, 28 insertions, 36 deletions
diff --git a/app/controllers/purchase_windows_controller.rb b/app/controllers/purchase_windows_controller.rb index 04b5736bb..293a7d8e4 100644 --- a/app/controllers/purchase_windows_controller.rb +++ b/app/controllers/purchase_windows_controller.rb @@ -36,13 +36,12 @@ class PurchaseWindowsController < ChouetteController end def decorate_purchase_windows(purchase_windows) - ModelDecorator.decorate( + PurchaseWindowDecorator.decorate( purchase_windows, - with: PurchaseWindowDecorator, context: { referential: @referential - } - ) + } + ) end def sort_column diff --git a/app/decorators/purchase_window_decorator.rb b/app/decorators/purchase_window_decorator.rb index 646fdea0d..54b241173 100644 --- a/app/decorators/purchase_window_decorator.rb +++ b/app/decorators/purchase_window_decorator.rb @@ -1,31 +1,37 @@ -class PurchaseWindowDecorator < Draper::Decorator +class PurchaseWindowDecorator < AF83::Decorator decorates Chouette::PurchaseWindow - delegate_all - def action_links - policy = h.policy(object) - links = [] + create_action_link do |l| + l.content t('purchase_windows.actions.new') + l.href { h.new_referential_purchase_window_path(context[:referential]) } + end - if policy.update? - links << Link.new( - content: I18n.t('actions.edit'), - href: h.edit_referential_purchase_window_path(context[:referential].id, object) - ) + with_instance_decorator do |instance_decorator| + instance_decorator.show_action_link do |l| + l.content t('purchase_windows.actions.show') + l.href do + h.referential_purchase_window_path( + context[:referential], + object + ) + end end - if policy.destroy? - links << Link.new( - content: I18n.t('actions.destroy'), - href: h.referential_purchase_window_path(context[:referential].id, object), - method: :delete, - data: { confirm: h.t('purchase_windows.actions.destroy_confirm') } - ) + instance_decorator.edit_action_link do |l| + l.href do + h.edit_referential_purchase_window_path(context[:referential].id, object) + end end - links + instance_decorator.destroy_action_link do |l| + l.href do + h.referential_purchase_window_path(context[:referential].id, object) + end + l.data confirm: h.t('purchase_windows.actions.destroy_confirm') + end end - def bounding_dates + define_instance_method :bounding_dates do unless object.date_ranges.empty? object.date_ranges.map(&:min).min..object.date_ranges.map(&:max).max end diff --git a/app/views/purchase_windows/index.html.slim b/app/views/purchase_windows/index.html.slim index 04f9fb0a8..0dba86935 100644 --- a/app/views/purchase_windows/index.html.slim +++ b/app/views/purchase_windows/index.html.slim @@ -1,7 +1,4 @@ - breadcrumb :purchase_windows, @referential -- content_for :page_header_actions do - - if policy(Chouette::PurchaseWindow).create? - = link_to(t('actions.add'), new_referential_purchase_window_path(@referential), class: 'btn btn-default') .page_content .container-fluid @@ -32,7 +29,6 @@ sortable: false \ ) \ ], - links: [:show], cls: 'table has-filter' = new_pagination @purchase_windows, 'pull-right' diff --git a/app/views/purchase_windows/show.html.slim b/app/views/purchase_windows/show.html.slim index 4ddde1706..4e836f424 100644 --- a/app/views/purchase_windows/show.html.slim +++ b/app/views/purchase_windows/show.html.slim @@ -1,14 +1,5 @@ - breadcrumb :purchase_window, @referential, @purchase_window - page_header_content_for @purchase_window -- content_for :page_header_content do - .row.mb-sm - .col-lg-12.text-right - - @purchase_window.action_links.each do |link| - = link_to link.href, - method: link.method, - data: link.data, - class: 'btn btn-primary' do - = link.content .page_content .container-fluid |
