diff options
| author | teddywing | 2017-09-01 18:25:05 +0200 | 
|---|---|---|
| committer | GitHub | 2017-09-01 18:25:05 +0200 | 
| commit | ed64dc517bca5f775631d999aa2e60f78d4dae30 (patch) | |
| tree | 0acfa761cbbd39d9ec67a7e9e56eccb86950e1b5 /app/helpers/table_builder_helper.rb | |
| parent | d127ed12158550f84ef1fb9c21d6360c86ac3642 (diff) | |
| parent | 44aeaeadfaf78ca1c43a6e182aaa67648f7e45f7 (diff) | |
| download | chouette-core-ed64dc517bca5f775631d999aa2e60f78d4dae30.tar.bz2 | |
Merge pull request #60 from af83/table-builder--allow-column-links-to-be-customised
Table builder  allow column links to be customised
Diffstat (limited to 'app/helpers/table_builder_helper.rb')
| -rw-r--r-- | app/helpers/table_builder_helper.rb | 39 | 
1 files changed, 23 insertions, 16 deletions
diff --git a/app/helpers/table_builder_helper.rb b/app/helpers/table_builder_helper.rb index f15019458..ec4d487c1 100644 --- a/app/helpers/table_builder_helper.rb +++ b/app/helpers/table_builder_helper.rb @@ -26,7 +26,10 @@ require 'table_builder_helper/url'  #       ),  #       TableBuilderHelper::Column.new(  #         key: :name, -#         attribute: 'name' +#         attribute: 'name', +#         link_to: lambda do |company| +#           referential_company_path(@referential, company) +#         end  #       ),  #       TableBuilderHelper::Column.new(  #         key: :phone, @@ -43,7 +46,18 @@ require 'table_builder_helper/url'  #     ],  #     links: [:show, :edit],  #     cls: 'table has-search', -#     overhead: [ {title: 'one', width: 1, cls: 'toto'}, {title: 'two <span class="test">Info</span>', width: 2, cls: 'default'} ] +#     overhead: [ +#       { +#         title: 'one', +#         width: 1, +#         cls: 'toto' +#       }, +#       { +#         title: 'two <span class="test">Info</span>', +#         width: 2, +#         cls: 'default' +#       } +#     ]  #   )  module TableBuilderHelper    # TODO: rename this after migration from `table_builder` @@ -186,15 +200,12 @@ module TableBuilderHelper            columns.each do |column|              value = column.value(item) -            if column_is_linkable?(column) -              # Build a link to the `item` -              polymorph_url = URL.polymorphic_url_parts( -                item, -                referential -              ) +            if column.linkable? +              path = column.link_to(item) +              link = link_to(value, path)                if overhead.empty? -                bcont << content_tag(:td, link_to(value, polymorph_url), title: 'Voir') +                bcont << content_tag(:td, link, title: 'Voir')                else                  i = columns.index(column) @@ -203,16 +214,16 @@ module TableBuilderHelper                    if (i > 0) && (overhead[i - 1][:width] > 1)                      clsArrayAlt = overhead[i - 1][:cls].split -                    bcont << content_tag(:td, link_to(value, polymorph_url), title: 'Voir', class: td_cls(clsArrayAlt)) +                    bcont << content_tag(:td, link, title: 'Voir', class: td_cls(clsArrayAlt))                    else -                    bcont << content_tag(:td, link_to(value, polymorph_url), title: 'Voir') +                    bcont << content_tag(:td, link, title: 'Voir')                    end                  else                    clsArray = overhead[columns.index(column)][:cls].split -                  bcont << content_tag(:td, link_to(value, polymorph_url), title: 'Voir', class: td_cls(clsArray)) +                  bcont << content_tag(:td, link, title: 'Voir', class: td_cls(clsArray))                  end                end @@ -334,10 +345,6 @@ module TableBuilderHelper      end    end -  def column_is_linkable?(column) -    column.attribute == 'name' || column.attribute == 'comment' -  end -    def gear_menu_link(link)      content_tag(        :li,  | 
