Commit 30c87be2 by Don Mitchell

Subsection drag between sections should work now.

parent ac09e18b
...@@ -55,16 +55,6 @@ $(document).ready(function() { ...@@ -55,16 +55,6 @@ $(document).ready(function() {
$("#start_date, #start_time, #due_date, #due_time").bind('change', autosaveInput); $("#start_date, #start_time, #due_date, #due_time").bind('change', autosaveInput);
$('.sync-date, .remove-date').bind('click', autosaveInput); $('.sync-date, .remove-date').bind('click', autosaveInput);
var cachedHesitation = new CMS.HesitateEvent( expandSection, $('.branch .collapsed'), 'mouseLeave');
// making the unit list sortable
$('.sortable-unit-list').sortable({
axis: 'y',
handle: '.drag-handle',
update: onUnitReordered,
connectWith: '.sortable-unit-list',
revert: true
});
// expand/collapse methods for optional date setters // expand/collapse methods for optional date setters
$('.set-date').bind('click', showDateSetter); $('.set-date').bind('click', showDateSetter);
$('.remove-date').bind('click', removeDateSetter); $('.remove-date').bind('click', removeDateSetter);
...@@ -90,6 +80,16 @@ $(document).ready(function() { ...@@ -90,6 +80,16 @@ $(document).ready(function() {
$('.import .file-input').click(); $('.import .file-input').click();
}); });
var cachedHesitation = new CMS.HesitateEvent( expandSection, $('.branch .collapsed'), 'mouseLeave');
// making the unit list sortable
$('.sortable-unit-list').sortable({
axis: 'y',
handle: '.drag-handle',
update: onUnitReordered,
connectWith: '.sortable-unit-list',
revert: true
});
// Subsection reordering // Subsection reordering
$('.subsection-list > ol').sortable({ $('.subsection-list > ol').sortable({
axis: 'y', axis: 'y',
...@@ -254,9 +254,8 @@ function expandSection(event) { ...@@ -254,9 +254,8 @@ function expandSection(event) {
} }
function checkDropValidity(event, ui) { function checkDropValidity(event, ui) {
var posInDestination = ui.position.top - $(event.target).position().top; var posInDestination = ui.item.position().top - $(event.target).position().top;
if (posInDestination <= -ui.item.height() || posInDestination >= $(event.target).height()) { if (posInDestination <= -ui.item.height() || posInDestination >= $(event.target).height()) {
// May need to call on ui.sender
$(event.target).sortable("cancel"); $(event.target).sortable("cancel");
return false; return false;
} }
...@@ -297,11 +296,13 @@ function onUnitReordered(event, ui) { ...@@ -297,11 +296,13 @@ function onUnitReordered(event, ui) {
} }
function onSubsectionReordered(event, ui) { function onSubsectionReordered(event, ui) {
// see onUnitReordered for pattern and comments
var section_id = $(event.target).data('section-id'); var section_id = $(event.target).data('section-id');
var _els = $(event.target).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();
// if it believes the element belongs in this section, check that it was dropped w/in the bounds
if (_.contains(children, ui.item.data('id'))) {
if (checkDropValidity(event, ui)) {
// call into server to commit the new order // call into server to commit the new order
$.ajax({ $.ajax({
url: "/save_item", url: "/save_item",
...@@ -310,21 +311,17 @@ function onSubsectionReordered(event, ui) { ...@@ -310,21 +311,17 @@ function onSubsectionReordered(event, ui) {
contentType: "application/json", contentType: "application/json",
data:JSON.stringify({ 'id' : section_id, 'children' : children}) data:JSON.stringify({ 'id' : section_id, 'children' : children})
}); });
}
// remove from old container }
if (ui.sender && section_id !== ui.sender.data('section-id')) { else {
var _els = ui.sender.children('li:.branch');
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
$.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('section-id'), 'children' : children}) data:JSON.stringify({ 'id' : section_id, 'children' : children})
}); });
} }
} }
......
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