diff options
| author | Teddy Wing | 2018-01-24 13:49:29 +0100 | 
|---|---|---|
| committer | Teddy Wing | 2018-01-24 13:49:29 +0100 | 
| commit | 0f6263648d23d140483ee82ce5dd8a92add3c56c (patch) | |
| tree | 5b467d8dec6ae307e47a60a27e91b816abee3011 | |
| parent | 907ec958608842066e4b0f5b7ff188da94736940 (diff) | |
| download | chouette-core-0f6263648d23d140483ee82ce5dd8a92add3c56c.tar.bz2 | |
RoutingConstraintZoneDecorator: Convert action links to new interface
Refs #5586
4 files changed, 38 insertions, 36 deletions
| diff --git a/app/controllers/routing_constraint_zones_controller.rb b/app/controllers/routing_constraint_zones_controller.rb index a72b288b8..47df211d0 100644 --- a/app/controllers/routing_constraint_zones_controller.rb +++ b/app/controllers/routing_constraint_zones_controller.rb @@ -13,9 +13,8 @@ class RoutingConstraintZonesController < ChouetteController    def index      index! do |format| -      @routing_constraint_zones = ModelDecorator.decorate( +      @routing_constraint_zones = RoutingConstraintZoneDecorator.decorate(          @routing_constraint_zones, -        with: RoutingConstraintZoneDecorator,          context: {            referential: referential,            line: parent diff --git a/app/decorators/routing_constraint_zone_decorator.rb b/app/decorators/routing_constraint_zone_decorator.rb index 0b438a554..657065310 100644 --- a/app/decorators/routing_constraint_zone_decorator.rb +++ b/app/decorators/routing_constraint_zone_decorator.rb @@ -1,42 +1,57 @@ -class RoutingConstraintZoneDecorator < Draper::Decorator +class RoutingConstraintZoneDecorator < AF83::Decorator    decorates Chouette::RoutingConstraintZone -  delegate_all - -  # Requires: +  # Action links require:    #   context: {    #     referential: ,    #     line:    #   } -  def action_links -    links = [] -    if h.policy(object).update? -      links << Link.new( -        content: h.t('actions.edit'), -        href: h.edit_referential_line_routing_constraint_zone_path( +  create_action_link( +    if: ->() { +      h.policy(Chouette::RoutingConstraintZone).create? && +        context[:referential].organisation == h.current_organisation +    } +  ) do |l| +    l.href do +      h.new_referential_line_routing_constraint_zone_path( +       context[:referential], +       context[:line] +     ) +    end +    l.class 'btn btn-primary' +  end + +  with_instance_decorator do |instance_decorator| +    instance_decorator.show_action_link do |l| +      l.href do +        h.referential_line_routing_constraint_zone_path(            context[:referential],            context[:line],            object          ) -      ) +      end      end -    if h.policy(object).destroy? -      links << Link.new( -        content: h.destroy_link_content, -        href: h.referential_line_routing_constraint_zone_path( +    instance_decorator.edit_action_link do |l| +      l.href do +        h.edit_referential_line_routing_constraint_zone_path(            context[:referential],            context[:line],            object -        ), -        method: :delete, -        data: { -          confirm: h.t('routing_constraint_zones.actions.destroy_confirm') -        } -      ) +        ) +      end      end -    links +    instance_decorator.destroy_action_link do |l| +      l.href do +        h.referential_line_routing_constraint_zone_path( +          context[:referential], +          context[:line], +          object +        ) +      end +      l.data confirm: h.t('routing_constraint_zones.actions.destroy_confirm') +    end    end  end diff --git a/app/views/routing_constraint_zones/index.html.slim b/app/views/routing_constraint_zones/index.html.slim index 7c54fca68..2f67b467e 100644 --- a/app/views/routing_constraint_zones/index.html.slim +++ b/app/views/routing_constraint_zones/index.html.slim @@ -1,7 +1,4 @@  - breadcrumb :routing_constraint_zones, @referential, @line -- content_for :page_header_actions do -  - if (policy(Chouette::RoutingConstraintZone).create? && @referential.organisation == current_organisation) -    = link_to(t('actions.new'), new_referential_line_routing_constraint_zone_path(@referential, @line), class: 'btn btn-primary')  .page_content    .container-fluid diff --git a/app/views/routing_constraint_zones/show.html.slim b/app/views/routing_constraint_zones/show.html.slim index 3d1988545..8c8e9b17a 100644 --- a/app/views/routing_constraint_zones/show.html.slim +++ b/app/views/routing_constraint_zones/show.html.slim @@ -1,14 +1,5 @@  - breadcrumb :routing_constraint_zone, @referential, @line, @routing_constraint_zone  - page_header_content_for @routing_constraint_zone -- content_for :page_header_content do -  .row -    .col-lg-12.text-right.mb-sm -      - @routing_constraint_zone.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 | 
