diff options
| -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 | ||||
| -rw-r--r-- | config/locales/purchase_windows.en.yml | 1 | ||||
| -rw-r--r-- | config/locales/purchase_windows.fr.yml | 1 | ||||
| -rw-r--r-- | lib/af83/decorator.rb | 4 | 
7 files changed, 34 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 diff --git a/config/locales/purchase_windows.en.yml b/config/locales/purchase_windows.en.yml index c0f402bf4..9ce05a1b9 100644 --- a/config/locales/purchase_windows.en.yml +++ b/config/locales/purchase_windows.en.yml @@ -24,6 +24,7 @@ en:        12: December      actions:        new: Add a new purchase window +      show: "Show"        edit: Edit this purchase window        destroy: Remove this purchase window        destroy_confirm: Are you sure you want destroy this purchase window? diff --git a/config/locales/purchase_windows.fr.yml b/config/locales/purchase_windows.fr.yml index 589546c32..bcc174d93 100644 --- a/config/locales/purchase_windows.fr.yml +++ b/config/locales/purchase_windows.fr.yml @@ -24,6 +24,7 @@ fr:        12: Décembre      actions:        new: Créer +      show: "Consulter"        edit: Editer        destroy: Supprimer        destroy_confirm: Etes vous sûr de supprimer cet calendrier commercial ? diff --git a/lib/af83/decorator.rb b/lib/af83/decorator.rb index e83e03e0f..1b9574053 100644 --- a/lib/af83/decorator.rb +++ b/lib/af83/decorator.rb @@ -28,6 +28,10 @@ class AF83::Decorator < ModelDecorator      end    end +  def self.define_instance_method method_name, &block +    instance_decorator.send(:define_method, method_name, &block) +  end +    class ActionLinks      attr_reader :options | 
