Sha256: 9ed9b0726d1328e07ec8df1be69f759098adfa87bc45fd43f4521251790b6afa

Contents?: true

Size: 992 Bytes

Versions: 3

Compression:

Stored size: 992 Bytes

Contents

module Para
  module TreeHelper
    def needs_placeholder?(node)
      node.children.empty? && node.depth < max_depth_for(node.class)
    end

    def max_depth_for(model)
      model.max_depth || Para.config.default_tree_max_depth
    end

    def actions(resource)
      content_tag(:div, class: 'pull-right btn-group') do
        edit_button(resource) + delete_button(resource)
      end
    end

    def edit_button(resource)
      link_to(
        component.relation_path(
          resource, action: :edit, return_to: view.request.fullpath
        ),
        class: 'btn btn-primary'
      ) do
        content_tag(:i, '', class: 'fa fa-pencil')
      end
    end

    def delete_button(resource)
      link_to(
        component.relation_path(resource),
        method: :delete,
        data: {
          confirm: I18n.t('para.list.delete_confirmation')
        },
        class: 'btn btn-danger'
      ) do
        content_tag(:i, '', class: 'fa fa-trash')
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
para-0.5.1 app/helpers/para/tree_helper.rb
para-0.5.0 app/helpers/para/tree_helper.rb
para-0.4.0 app/helpers/para/tree_helper.rb