Commit ac09e18b by Don Mitchell

Now traps out of bounds as implying no change. Seems very slow.

parent 1782c54e
...@@ -253,44 +253,53 @@ function expandSection(event) { ...@@ -253,44 +253,53 @@ function expandSection(event) {
$(event.currentTarget).find('.expand-collapse-icon').removeClass('expand').addClass('collapse'); $(event.currentTarget).find('.expand-collapse-icon').removeClass('expand').addClass('collapse');
} }
function checkDropValidity(event, ui) {
var posInDestination = ui.position.top - $(event.target).position().top;
if (posInDestination <= -ui.item.height() || posInDestination >= $(event.target).height()) {
// May need to call on ui.sender
$(event.target).sortable("cancel");
return false;
}
return true;
}
// 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(event, ui) { function onUnitReordered(event, ui) {
var subsection_id = $(this).data('subsection-id'); // This is called 2x when moving from one subsection to another: once for the sender and once
// for the receiver. The sender's call has ui.sender == null
var _els = $(this).children('li:.leaf'); var subsection_id = $(event.target).data('subsection-id');
var _els = $(event.target).children('li:.leaf');
var children = _els.map(function(idx, el) { return $(el).data('id'); }).get(); var children = _els.map(function(idx, el) { return $(el).data('id'); }).get();
// if it believes the element belongs in this section, check that it was dropped w/in the bounds
// call into server to commit the new order if (_.contains(children, ui.item.data('id'))) {
$.ajax({ if (checkDropValidity(event, ui)) {
url: "/save_item", // call into server to commit the new order
type: "POST", $.ajax({
dataType: "json", url: "/save_item",
contentType: "application/json", type: "POST",
data:JSON.stringify({ 'id' : subsection_id, 'children' : children}) dataType: "json",
}); contentType: "application/json",
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'); else {
var children = _els.map(function(idx, el) { return $(el).data('id'); }).get(); // recording the removal (as element is not in the collection)
// call into server to commit the new order
$.ajax({ $.ajax({
url: "/save_item", url: "/save_item",
type: "POST", type: "POST",
dataType: "json", dataType: "json",
contentType: "application/json", contentType: "application/json",
data:JSON.stringify({ 'id' : ui.sender.data('subsection-id'), 'children' : children}) data:JSON.stringify({ 'id' : subsection_id, 'children' : children})
}); });
} }
} }
function onSubsectionReordered(event, ui) { function onSubsectionReordered(event, ui) {
var section_id = $(this).data('section-id'); var section_id = $(event.target).data('section-id');
var _els = $(this).children('li:.branch'); var _els = $(event.target).children('li:.branch');
var children = _els.map(function(idx, el) { return $(el).data('id'); }).get(); var children = _els.map(function(idx, el) { return $(el).data('id'); }).get();
// call into server to commit the new order // call into server to commit the new order
...@@ -320,9 +329,9 @@ function onSubsectionReordered(event, ui) { ...@@ -320,9 +329,9 @@ function onSubsectionReordered(event, ui) {
} }
function onSectionReordered() { function onSectionReordered() {
var course_id = $(this).data('course-id'); var course_id = $(event.target).data('course-id');
var _els = $(this).children('section:.branch'); var _els = $(event.target).children('section:.branch');
var children = _els.map(function(idx, el) { return $(el).data('id'); }).get(); var children = _els.map(function(idx, el) { return $(el).data('id'); }).get();
// call into server to commit the new order // call into server to commit the new order
......
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