diff options
| author | Teddy Wing | 2017-06-15 17:44:55 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2017-06-15 17:44:55 +0200 | 
| commit | 1d489cef3b9aeb474071b89be6d256e554182863 (patch) | |
| tree | 806f5b015fbeaa51481c7f0d687703d8b7521a2e | |
| parent | 8e678905af6be3358069a9d51f7af88d3449f014 (diff) | |
| download | chouette-core-1d489cef3b9aeb474071b89be6d256e554182863.tar.bz2 | |
ReferentialDecorator: Handle non-`Link` buttons
Referentials#show has a button "Purger" that isn't a link. Instead, it's
a `<button>` element that opens a modal.
Previously, we only knew how to put `Link`s in the `#action_links`, and
only these could then be rendered in the header bar as buttons.
This change allows us to accept non-Link objects. Since the button is
rather simple, I decided to create a simple `HTMLElement` class to
represent it and output it in the resulting HTML. The class uses the
`#content_tag` `ActionView` helper to render the final HTML.
Update "referentials/show.html.slim" to output the button correctly in
addition to the normal links.
Update `TableBuilderHelper#build_links` to not add anything that's not a
`Link` to the gear menu. This allows us to display the "Purger" button
on the Referentials#show page but not in the table on Workbenches#show.
Refs #3479
| -rw-r--r-- | app/decorators/referential_decorator.rb | 11 | ||||
| -rw-r--r-- | app/helpers/table_builder_helper.rb | 2 | ||||
| -rw-r--r-- | app/views/referentials/show.html.slim | 13 | ||||
| -rw-r--r-- | lib/html_element.rb | 15 | 
4 files changed, 33 insertions, 8 deletions
| diff --git a/app/decorators/referential_decorator.rb b/app/decorators/referential_decorator.rb index 58c2eac73..9107de0b3 100644 --- a/app/decorators/referential_decorator.rb +++ b/app/decorators/referential_decorator.rb @@ -17,8 +17,15 @@ class ReferentialDecorator < Draper::Decorator      end      if h.policy(object).edit? -      # TODO: Handle buttons in the header and don't show them in the gear menu -      # button.btn.btn-primary type='button' data-toggle='modal' data-target='#purgeModal' Purger +      links << HTMLElement.new( +        :button, +        'Purger', +        type: 'button', +        data: { +          toggle: 'modal', +          target: '#purgeModal' +        } +      )        if object.archived?          links << Link.new( diff --git a/app/helpers/table_builder_helper.rb b/app/helpers/table_builder_helper.rb index 111237a7b..97370b7e0 100644 --- a/app/helpers/table_builder_helper.rb +++ b/app/helpers/table_builder_helper.rb @@ -112,7 +112,7 @@ module TableBuilderHelper      menu = content_tag :ul, class: 'dropdown-menu' do        (          CustomLinks.new(item, pundit_user, links).links + -        item.action_links +        item.action_links.select { |link| link.is_a?(Link) }        ).map do |link|          gear_menu_link(link)        end.join.html_safe diff --git a/app/views/referentials/show.html.slim b/app/views/referentials/show.html.slim index f3dcf6a69..2e67f4968 100644 --- a/app/views/referentials/show.html.slim +++ b/app/views/referentials/show.html.slim @@ -27,11 +27,14 @@        /    span = t('actions.destroy')        /= leslinks.map { |l| link_to l.href, l.label }        - @referential.action_links.each do |link| -        = link_to link.href, -            method: link.method, -            data: link.data, -            class: 'btn btn-primary' do -              = link.content +        - if link.is_a?(HTMLElement) +          = link.to_html(class: 'btn btn-primary') +        - else +          = link_to link.href, +              method: link.method, +              data: link.data, +              class: 'btn btn-primary' do +                = link.content  / PageContent  .page_content diff --git a/lib/html_element.rb b/lib/html_element.rb new file mode 100644 index 000000000..469fd7565 --- /dev/null +++ b/lib/html_element.rb @@ -0,0 +1,15 @@ +class HTMLElement +  def initialize(tag_name, content = nil, options = nil) +    @tag_name = tag_name +    @content = content +    @options = options +  end + +  def to_html(options = {}) +    ApplicationController.helpers.content_tag( +      @tag_name, +      @content, +      @options.merge(options) +    ) +  end +end | 
