# frozen_string_literal: true # # Methods useful for building out tables # module CoreTableHelper # # Format the table header # @param name - Name of the header, either the text or a localized value # @param classes - Additional classes to apply to the header # @param priority - Priority to show the column when the screen gets small, the lower value is higher priority # @param visible - This column should be visible # def table_header_actions_tag(name: :actions, classes: %w[actions], priority: 2, visible: true) return unless visible table_header_tag(name, classes: classes, priority: priority, visible: visible) end # # Format the table header # @param name - Name of the header, either the text or a localized value # @param classes - Additional classes to apply to the header # @param priority - Priority to show the column when the screen gets small, the lower value is higher priority # @param visible - This column should be visible # def table_header_tag(name, classes: [], priority: 1, visible: true) return unless visible options = { data: { priority: priority } } options[:class] = classes if classes.present? content_tag(:th, options) { table_header_text(name) } end # # First look to see if a localized string was passed in, # then try to look in table.headers.... # lastly return the titleized string # @param name - Name of the header, either the text or a localized value # def table_header_text(name) if I18n.exists?(name) t(name) elsif I18n.exists?("table.headers.#{name}") t("table.headers.#{name}") elsif I18n.exists?("core_table.headers.#{name}") t("core_table.headers.#{name}") else name.to_s.titleize end rescue StandardError name end def dynamic_custom_modal(anchor, label, title, view_endpoint, _options = {}) datum = { view_url: view_endpoint } content_tag(:span) do concat(content_tag(:a, href: "##{anchor}", class: 'modal-trigger') do concat(materialize_icon(label)) end) concat(content_tag(:div, id: anchor, class: 'modal modal-fixed-footer', data: datum) do concat(content_tag(:div, class: 'modal-content') do concat(content_tag(:h2, class: 'center') do concat(content_tag(:span, title)) end) concat(content_tag(:div, class: 'center-align') do concat(content_tag(:div, class: 'progress red lighten-4') do tag(:div, class: 'indeterminate red') end) end) end) concat(content_tag(:div, class: 'modal-footer') do concat(content_tag(:a, href: '#', class: 'modal-action modal-close btn btn-flat') do concat('Close') end) end) end) end end end