Commit 3a2c5752 by Don Mitchell

Basic dnd for units

parent c9c9f7e5
...@@ -59,7 +59,9 @@ $(document).ready(function() { ...@@ -59,7 +59,9 @@ $(document).ready(function() {
$('.sortable-unit-list').sortable({ $('.sortable-unit-list').sortable({
axis: 'y', axis: 'y',
handle: '.drag-handle', handle: '.drag-handle',
update: onUnitReordered update: onUnitReordered,
connectWith: '.sortable-unit-list',
revert: true
}); });
// expand/collapse methods for optional date setters // expand/collapse methods for optional date setters
...@@ -242,7 +244,7 @@ function removePolicyMetadata(e) { ...@@ -242,7 +244,7 @@ function removePolicyMetadata(e) {
// This method only changes the ordering of the child objects in a subsection // This method only changes the ordering of the child objects in a subsection
function onUnitReordered() { function onUnitReordered(event, ui) {
var subsection_id = $(this).data('subsection-id'); var subsection_id = $(this).data('subsection-id');
var _els = $(this).children('li:.leaf'); var _els = $(this).children('li:.leaf');
...@@ -256,6 +258,23 @@ function onUnitReordered() { ...@@ -256,6 +258,23 @@ function onUnitReordered() {
contentType: "application/json", contentType: "application/json",
data:JSON.stringify({ 'id' : subsection_id, 'children' : children}) data:JSON.stringify({ 'id' : subsection_id, 'children' : children})
}); });
// remove from old container
if (ui.sender && subsection_id !== ui.sender.data('subsection-id')) {
var _els = ui.sender.children('li:.leaf');
var children = _els.map(function(idx, el) { return $(el).data('id'); }).get();
// call into server to commit the new order
$.ajax({
url: "/save_item",
type: "POST",
dataType: "json",
contentType: "application/json",
data:JSON.stringify({ 'id' : ui.sender.data('subsection-id'), 'children' : children})
});
}
} }
function onSubsectionReordered() { function onSubsectionReordered() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment