diff options
| author | Zog | 2018-01-22 09:54:20 +0100 | 
|---|---|---|
| committer | Zog | 2018-01-25 17:18:01 +0100 | 
| commit | ff5d96b530a41669c394b7b0dc138e29da48e97d (patch) | |
| tree | cc731e14383ef8f47302478faebac493dadacdf8 /app/helpers/table_builder_helper.rb | |
| parent | 872f9476971d3bde6e6f470153af09ed87af1b28 (diff) | |
| download | chouette-core-ff5d96b530a41669c394b7b0dc138e29da48e97d.tar.bz2 | |
Refs #5586 @2h; Fix specs
Diffstat (limited to 'app/helpers/table_builder_helper.rb')
| -rw-r--r-- | app/helpers/table_builder_helper.rb | 27 | 
1 files changed, 15 insertions, 12 deletions
diff --git a/app/helpers/table_builder_helper.rb b/app/helpers/table_builder_helper.rb index e29695b55..5c9da3d36 100644 --- a/app/helpers/table_builder_helper.rb +++ b/app/helpers/table_builder_helper.rb @@ -86,12 +86,15 @@ module TableBuilderHelper      overhead: [],      # Possibility to override the result of collection.model -    model: nil +    model: nil, + +    #overrides the params[:action] value +    action: nil    )      content_tag :table, -      thead(collection, columns, sortable, selectable, links.any?, overhead, model || collection.model) + -        tbody(collection, columns, selectable, links, overhead), +      thead(collection, columns, sortable, selectable, links.any?, overhead, model || collection.model, action || params[:action]) + +        tbody(collection, columns, selectable, links, overhead, action || params[:action]),        class: cls    end @@ -109,7 +112,7 @@ module TableBuilderHelper    private -  def thead(collection, columns, sortable, selectable, has_links, overhead, model ) +  def thead(collection, columns, sortable, selectable, has_links, overhead, model, action)      content_tag :thead do        # Inserts overhead content if any specified        over_head = '' @@ -189,7 +192,7 @@ module TableBuilderHelper          # Inserts a blank column for the gear menu          last_item = collection.last -        action_links = last_item && last_item.respond_to?(:action_links) && (last_item&.action_links&.is_a?(AF83::Decorator::ActionLinks) ? last_item.action_links(params[:action]) : last_item.action_links) +        action_links = last_item && last_item.respond_to?(:action_links) && (last_item&.action_links&.is_a?(AF83::Decorator::ActionLinks) ? last_item.action_links(action) : last_item.action_links)          if has_links || action_links.try(:any?)            hcont << content_tag(:th, '')          end @@ -201,7 +204,7 @@ module TableBuilderHelper      end    end -  def tr item, columns, selectable, links, overhead, model_name +  def tr item, columns, selectable, links, overhead, model_name, action      klass = "#{model_name}-#{item.id}"      content_tag :tr, class: klass do        bcont = [] @@ -269,12 +272,12 @@ module TableBuilderHelper          end        end -      action_links = item && item.respond_to?(:action_links) && (item.action_links.is_a?(AF83::Decorator::ActionLinks) ? item.action_links(params[:action]) : item.action_links) +      action_links = item && item.respond_to?(:action_links) && (item.action_links.is_a?(AF83::Decorator::ActionLinks) ? item.action_links(action) : item.action_links)        if links.any? || action_links.try(:any?)          bcont << content_tag(            :td, -          build_links(item, links), +          build_links(item, links, action),            class: 'actions'          )        end @@ -283,12 +286,12 @@ module TableBuilderHelper      end    end -  def tbody(collection, columns, selectable, links, overhead) +  def tbody(collection, columns, selectable, links, overhead, action)      model_name = TableBuilderHelper.item_row_class_name collection      content_tag :tbody do        collection.map do |item| -        tr item, columns, selectable, links, overhead, model_name +        tr item, columns, selectable, links, overhead, model_name, action        end.join.html_safe      end    end @@ -301,7 +304,7 @@ module TableBuilderHelper      end    end -  def build_links(item, links) +  def build_links(item, links, action)      trigger = content_tag(        :div,        class: 'btn dropdown-toggle', @@ -313,7 +316,7 @@ module TableBuilderHelper      action_links = item.action_links      if action_links.is_a?(AF83::Decorator::ActionLinks)        menu = content_tag :div, class: 'dropdown-menu' do -        item.action_links(params[:action]).grouped_by(:primary, :secondary, :footer).map do |group, _links| +        item.action_links(action).grouped_by(:primary, :secondary, :footer).map do |group, _links|            if _links.any?              content_tag :ul, class: group do                _links.map{|link| gear_menu_link(link)}.join.html_safe  | 
