Module: RailsAdminNestedSet::Helper
- Defined in:
- lib/rails_admin_nested_set/helper.rb
Instance Method Summary collapse
- #action_links(model) ⇒ Object
- #g_link(node, fv, on, badge) ⇒ Object
- #max_depth ⇒ Object
- #rails_admin_nested_set(tree, opts = {}) ⇒ Object
- #rails_admin_nested_set_builder(nodes, tree) ⇒ Object
Instance Method Details
#action_links(model) ⇒ Object
68 69 70 71 72 |
# File 'lib/rails_admin_nested_set/helper.rb', line 68 def action_links(model) content_tag :ul, class: 'inline actions' do :member, @abstract_model, model, true end end |
#g_link(node, fv, on, badge) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/rails_admin_nested_set/helper.rb', line 12 def g_link(node, fv, on, badge) link_to( fv.html_safe, toggle_path(model_name: @abstract_model, id: node.id, method: 'enabled', on: on.to_s), method: :post, class: 'badge ' + badge, ) end |
#max_depth ⇒ Object
64 65 66 |
# File 'lib/rails_admin_nested_set/helper.rb', line 64 def max_depth @nested_set_conf.[:max_depth] || '0' end |
#rails_admin_nested_set(tree, opts = {}) ⇒ Object
3 4 5 6 7 8 9 10 |
# File 'lib/rails_admin_nested_set/helper.rb', line 3 def rails_admin_nested_set(tree, opts= {}) tree = tree.to_a.sort_by { |m| m.lft } roots = tree.select{|elem| elem.parent_id.nil?} id = "ns_#{rand(100_000_000..999_999_999)}" content = content_tag(:ol, rails_admin_nested_set_builder(roots, tree), id: id, class: 'dd-list') js = "rails_admin_nested_set({id: '#{id}', max_depth: #{max_depth}, update_url: '#{nested_set_path(model_name: @abstract_model)}'});" content + content_tag(:script, js.html_safe, type: 'text/javascript') end |
#rails_admin_nested_set_builder(nodes, tree) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rails_admin_nested_set/helper.rb', line 21 def rails_admin_nested_set_builder(nodes, tree) nodes.map do |node| li_classes = 'dd-item dd3-item' content_tag :li, class: li_classes, :'data-id' => node.id do output = content_tag :div, 'drag', class: 'dd-handle dd3-handle' output+= content_tag :div, class: 'dd3-content' do content = ''.html_safe if node.respond_to?(:enabled) && respond_to?(:toggle_path) content += case node.enabled when nil g_link(node, '✘', 0, 'badge-important') + g_link(node, '✓', 1, 'badge-success') when false g_link(node, '✘', 1, 'badge-important') when true g_link(node, '✓', 0, 'badge-success') else %{<span class="badge">-</span>} end.html_safe end content += link_to @model_config.with(object: node).object_label, edit_path(@abstract_model, node.id) [:cover, :image].each do |mth| if node.respond_to?(mth) content += image_tag(node.send(mth), style: "max-height: 90px") end end content += content_tag(:div, action_links(node), class: 'pull-right links') content end children = tree.select{|elem| elem.parent_id == node.id} output = content_tag(:div, output) if children.any? output += content_tag(:ol, rails_admin_nested_set_builder(children, tree), class: 'dd-list') end output end end.join.html_safe end |