I do this two ways for my custom made CMS. Ordering pages is done via left_id right_id and depth. I use jQuery-ui Sortable to do the ordering (AJAX part). I have a table and data-page-id="the ID" so it knows how to order it. Using https://github.com/gazsp/baum for database structure.
// Sortable
$('tbody#is_sortable').sortable({
containment: '#page-table',
handle: '.re-order',
tolerance: 'pointer',
placeholder: 'ui-state-highlight',
opacity: 0.55,
update: function (e, ui) {
//$('#content .update_message').show();
// send reorder request
var id = $(ui.item).data('page-id');
var left_sibling_id = $(ui.item).prev().data('page-id');
// if left_sibling_id is undefined, must be next to home page
if (!left_sibling_id) {
left_sibling_id = 'parent';
}
if (left_sibling_id) {
$.post('/admin/pages/ajax/re-order', {
id: id,
left_sibling_id: left_sibling_id
},
function (data) {
//$('#content .update_message').fadeOut(400, 0);
}
);
}
}
});
Sorting on Baum
if ($request->left_sibling_id == 'parent') {
$parent = ($page->isRoot() ? Page::root() : Page::find($page->parent_id));
//return $parent;
if (! $page->makeFirstChildOf($parent)) {
return [
'error' => true,
'message' => 'Could not move that page.',
];
}
} else {
$left_page = Page::find($request->left_sibling_id);
if (! $page->makeNextSiblingOf($left_page)) {
return [
'error' => true,
'message' => 'Could not move that page.',
];
}
}
I then use jQuery Sortable again just to do a small image ordering for attached images (as well as selecting them from available => selected).
$('#image_sort_source, #image_sort_dest')
.sortable({
connectWith: '.droppable',
over: function (event, ui) {
$(ui.placeholder).parent().css({'border': '2px solid #aaa'})
},
out: function (event, ui) {
$(ui.placeholder).parent().css({'border': ''})
},
stop: function (event, ui) {
$(ui.item).parent().css({'border': ''})
},
})
.disableSelection();
var callback = function (event, ui) {
var ids = [];
$('#image_sort_dest').find('li').each(function () {
ids.push($(this).data('id'));
})
$('#image_sort_order').val(ids.join());
}
$('#image_sort_dest')
.on("sortreceive", function (event, ui) {
callback(event, ui);
})
.on("sortstop", function (event, ui) {
callback(event, ui);
});
I'm sure you can use something from that.