This gem adds a tree and a list view to your ActiveAdmin resource index, both sortable via drag'n'drop.
# Gemfilegem"activeadmin-sortable-tree",:github=>"nebirhos/activeadmin-sortable-tree",:branch=>"master"WARNING! Not compatible with neo/activeadmin-sortable[https://github.com/neo/activeadmin-sortable]
Admin:
# app/admin/page.rbActiveAdmin.registerPagedosortabletree: trueindex:as=>:sortabledolabel:title# item contentactionsendendModel: activeadmin-sortable-tree is agnostic to the tree implementation. All you have to do is expose a sorting attribute and a few tree methods (:parent, :children and :roots). Let's say you use Ancestry:
classPage < ActiveRecord::Baseattr_accessible:title,:body,:positionhas_ancestry:orphan_strategy=>:rootifyendYou can configure these methods if you need:
ActiveAdmin.registerPagedosortabletree: true,sorting_attribute: :position,parent_method: :parent,children_method: :children,roots_method: :roots,roots_collection: proc{current_user.pages.roots}# ...endThe option roots_collection provides full control on how to find the root
nodes of your sortable tree and is evaluated within the context of the
controller. Please note that roots_collection will override what is specified
in roots_method.
Admin:
# app/admin/page.rbActiveAdmin.registerPagedosortableindex:as=>:sortabledolabel:title# item contentactionsendendModel: Sortable list assumes you have a :position field in your resource. Of course it's configurable:
ActiveAdmin.registerPagedosortabletree: false,# defaultsorting_attribute: :my_position_field
...
endCurrently supports only IndexAsBlock, more to come!
Admin:
# app/admin/page.rbActiveAdmin.registerPagedosortableindex:as=>:blockdo |page|
# item contentendendModel: Same as list view (see above)
ActiveAdmin.registerPagedosortabletree: true,max_levels: 0,# infinite indent levelsprotect_root: false,# allow root items to be draggedsorting_attribute: :position,parent_method: :parent,children_method: :children,roots_method: :roots,roots_collection: nil,# proc to specifiy retrieval of rootscollapsible: false,# show +/- buttons to collapse childrenstart_collapsed: false,# when collapsible, start with all roots collapsedendIn IndexAsSortable you can add custom actions (with or without the defaults):
index:as=>:sortabledoactionsdefaults: falsedo |page|
link_to"Custom action",my_custon_path(page)endendIt exposes three Ajax Events: ajaxDone, ajaxFail and ajaxAlways, which correspond to jQuery ajax callbacks: done, fail and always.
To subscribe Ajax callback:
ActiveAdminSortableEvent.add('ajaxDone',function(){// do what you want})Copyright © 2013 Francesco Disperati, Cantiere Creativo. See the file MIT-LICENSE for details. See the full list list of contributors.