diff options
Diffstat (limited to 'app/helpers/table_builder_helper.rb')
| -rw-r--r-- | app/helpers/table_builder_helper.rb | 147 |
1 files changed, 80 insertions, 67 deletions
diff --git a/app/helpers/table_builder_helper.rb b/app/helpers/table_builder_helper.rb index 64bec6bae..de78e903d 100644 --- a/app/helpers/table_builder_helper.rb +++ b/app/helpers/table_builder_helper.rb @@ -95,6 +95,18 @@ module TableBuilderHelper class: cls end + def self.item_row_class_name collection + if collection.respond_to?(:model) + model_name = collection.model.name + elsif collection.respond_to?(:first) + model_name = collection.first.class.name + else + model_name = "item" + end + + model_name.split("::").last.parameterize + end + private def thead(collection, columns, sortable, selectable, has_links, overhead, model ) @@ -187,92 +199,92 @@ module TableBuilderHelper end end - def tbody(collection, columns, selectable, links, overhead) - if collection.respond_to?(:model) - model_name = collection.model.name.split("::").last - else - model_name = "item" - end - - content_tag :tbody do - collection.map do |item| - klass = "#{model_name.parameterize}-#{item.id}" - content_tag :tr, class: klass do - bcont = [] - - if selectable - bcont << content_tag( - :td, - checkbox(id_name: item.try(:id), value: item.try(:id)) - ) - end - - columns.each do |column| - value = column.value(item) - - if column.linkable? - path = column.link_to(item) - link = link_to(value, path) + def tr item, columns, selectable, links, overhead, model_name + klass = "#{model_name}-#{item.id}" + content_tag :tr, class: klass do + bcont = [] + if selectable + disabled = selectable.respond_to?(:call) && !selectable.call(item) + bcont << content_tag( + :td, + checkbox(id_name: item.try(:id), value: item.try(:id), disabled: disabled) + ) + end - if overhead.empty? - bcont << content_tag(:td, link, title: 'Voir') + columns.each do |column| + value = column.value(item) - else - i = columns.index(column) + if column.linkable? + path = column.link_to(item) + link = link_to(value, path) - if overhead[i].blank? - if (i > 0) && (overhead[i - 1][:width] > 1) - clsArrayAlt = overhead[i - 1][:cls].split + if overhead.empty? + bcont << content_tag(:td, link, title: 'Voir') - bcont << content_tag(:td, link, title: 'Voir', class: td_cls(clsArrayAlt)) + else + i = columns.index(column) - else - bcont << content_tag(:td, link, title: 'Voir') - end + if overhead[i].blank? + if (i > 0) && (overhead[i - 1][:width] > 1) + clsArrayAlt = overhead[i - 1][:cls].split - else - clsArray = overhead[columns.index(column)][:cls].split + bcont << content_tag(:td, link, title: 'Voir', class: td_cls(clsArrayAlt)) - bcont << content_tag(:td, link, title: 'Voir', class: td_cls(clsArray)) - end + else + bcont << content_tag(:td, link, title: 'Voir') end else - if overhead.empty? - bcont << content_tag(:td, value) + clsArray = overhead[columns.index(column)][:cls].split - else - i = columns.index(column) + bcont << content_tag(:td, link, title: 'Voir', class: td_cls(clsArray)) + end + end - if overhead[i].blank? - if (i > 0) && (overhead[i - 1][:width] > 1) - clsArrayAlt = overhead[i - 1][:cls].split + else + if overhead.empty? + bcont << content_tag(:td, value) - bcont << content_tag(:td, value, class: td_cls(clsArrayAlt)) + else + i = columns.index(column) - else - bcont << content_tag(:td, value) - end + if overhead[i].blank? + if (i > 0) && (overhead[i - 1][:width] > 1) + clsArrayAlt = overhead[i - 1][:cls].split - else - clsArray = overhead[i][:cls].split + bcont << content_tag(:td, value, class: td_cls(clsArrayAlt)) - bcont << content_tag(:td, value, class: td_cls(clsArray)) - end + else + bcont << content_tag(:td, value) end + + else + clsArray = overhead[i][:cls].split + + bcont << content_tag(:td, value, class: td_cls(clsArray)) end end + end + end - if links.any? || item.try(:action_links).try(:any?) - bcont << content_tag( - :td, - build_links(item, links), - class: 'actions' - ) - end + if links.any? || item.try(:action_links).try(:any?) + bcont << content_tag( + :td, + build_links(item, links), + class: 'actions' + ) + end - bcont.join.html_safe - end + bcont.join.html_safe + end + end + + def tbody(collection, columns, selectable, links, overhead) + model_name = TableBuilderHelper.item_row_class_name collection + + content_tag :tbody do + collection.map do |item| + tr item, columns, selectable, links, overhead, model_name end.join.html_safe end end @@ -347,13 +359,14 @@ module TableBuilderHelper end end - def checkbox(id_name:, value:) + def checkbox(id_name:, value:, disabled: false) content_tag :div, '', class: 'checkbox' do - check_box_tag(id_name, value).concat( + check_box_tag(id_name, value, nil, disabled: disabled).concat( content_tag(:label, '', for: id_name) ) end end + def gear_menu_link(link) content_tag( :li, |
