Module: EtabliocmsCore::Admin::TableTreeHelper
- Defined in:
- app/helpers/etabliocms_core/admin/table_tree_helper.rb
Instance Method Summary collapse
- #actions_links(item, parent) ⇒ Object
- #destroy_path(item) ⇒ Object
- #edit_path(item) ⇒ Object
- #item_html(item, stack) ⇒ Object
- #move_path(item, method) ⇒ Object
- #render_table_tree(items = []) ⇒ Object
Instance Method Details
#actions_links(item, parent) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/helpers/etabliocms_core/admin/table_tree_helper.rb', line 47 def actions_links(item, parent) links = [ link_to(I18n.t('admin.edit'), edit_path(item), :class => "icon icon-edit", :title => I18n.t('admin.edit')), link_to(I18n.t('admin.destroy'), destroy_path(item), :method => :delete, :confirm => t("#{item.class.to_s.demodulize.underscore}.destroy_confirmation"), :class => 'icon icon-destroy', :title => I18n.t('admin.destroy')) ] unless item.is_first_of_siblings?(parent) links << link_to(I18n.t('hierarchy.up'), move_path(item, "move_higher"), :method => :put, :class => "icon icon-up", :title => I18n.t('hierarchy.up')) links << link_to(I18n.t('hierarchy.top'), move_path(item, "move_to_top"), :method => :put, :class => "icon icon-up-up", :title => I18n.t('hierarchy.top')) end unless item.is_last_of_siblings?(parent) links << link_to(I18n.t('hierarchy.down'), move_path(item, "move_lower"), :method => :put, :class => "icon icon-down", :title => I18n.t('hierarchy.down')) links << link_to(I18n.t('hierarchy.bottom'), move_path(item, "move_to_bottom"), :method => :put, :class => "icon icon-down-down", :title => I18n.t('hierarchy.bottom')) end links.join("").html_safe end |
#destroy_path(item) ⇒ Object
85 86 87 |
# File 'app/helpers/etabliocms_core/admin/table_tree_helper.rb', line 85 def destroy_path(item) send "admin_#{item.class.to_s.demodulize.underscore}_path", item.id end |
#edit_path(item) ⇒ Object
81 82 83 |
# File 'app/helpers/etabliocms_core/admin/table_tree_helper.rb', line 81 def edit_path(item) send "edit_admin_#{item.class.to_s.demodulize.underscore}_path", item.id end |
#item_html(item, stack) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/helpers/etabliocms_core/admin/table_tree_helper.rb', line 32 def item_html(item, stack) title, locale = if defined?(EtabliocmsPages::Page) && item.is_a?(EtabliocmsPages::Page) [item.titles, item.locales] else [item.title, item.locale] end html = [ link_to(title, edit_path(item), :style => "padding-left:#{stack.size*10}px"), content_tag(:span, I18n.l(item.created_at, :format => :short), :class => "centered"), content_tag(:span, locale, :class => 'centered'), actions_links(item, stack.last) ].inject("") { |line, cell_content| line + content_tag(:td, cell_content) } content_tag(:tr, html.html_safe) end |
#move_path(item, method) ⇒ Object
89 90 91 |
# File 'app/helpers/etabliocms_core/admin/table_tree_helper.rb', line 89 def move_path(item, method) send "move_admin_#{item.class.to_s.demodulize.underscore}_path", {:id => item.id, :method => method} end |
#render_table_tree(items = []) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/helpers/etabliocms_core/admin/table_tree_helper.rb', line 5 def render_table_tree(items = []) stack = [] html = "" items.each do |node| if stack.empty? html << item_html(node, stack) stack.push(node) next end if stack.last.lft < node.lft && node.lft < stack.last.rgt if node.leaf? html << item_html(node, stack) else html << item_html(node, stack) stack.push(node) end if node.rgt + 1 == stack.last.rgt stack.pop end else stack.pop redo end end html.html_safe end |