Sortable groups and elements between groups


I need to implement something like this:
but i can't understand, how to do it.

I don't need adding new group actually, but I need sorting items into
the group, moving its between groups and sorting whole groups.

Does anybody have the complete solutions on ror?

Thank you.