diff --git a/course/lib.php b/course/lib.php index c3e520f..cc1a787 100644 --- a/course/lib.php +++ b/course/lib.php @@ -2247,12 +2247,20 @@ function move_section($course, $section, $move) { return false; } - if (!set_field("course_sections", "section", $sectiondest, "id", $sectionrecord->id)) { - return false; + + $count = abs($sectiondest - $section); + $direction = ($sectiondest - $section) / $count; + + for ($i = 0, $ref = $section + $direction; $i < $count; ++$i, $ref += $direction) { + if (!set_field("course_sections", "section", $ref - $direction, 'course', $course->id, 'section', $ref)) { + return false; + } } - if (!set_field("course_sections", "section", $section, "id", $sectiondestrecord->id)) { + + if (!set_field("course_sections", "section", $sectiondest, "id", $sectionrecord->id)) { return false; } + // if the focus is on the section that is being moved, then move the focus along if (isset($USER->display[$course->id]) and ($USER->display[$course->id] == $section)) { course_set_display($course->id, $sectiondest); diff --git a/lib/ajax/section_classes.js b/lib/ajax/section_classes.js index 9c0add9..6fc6e58 100755 --- a/lib/ajax/section_classes.js +++ b/lib/ajax/section_classes.js @@ -219,36 +219,49 @@ section_class.prototype.move_to_section = function(target) { var loopmodifier = 'i + 1'; } + // Save a reference to `this`, because it is not included in the + // closure of the success function like the rest of the + // environment is. + var this_ref = this; + + success = function(o) + { + //move on front end + for (var i=loopStart; eval(loopCondition); eval(loopInc)) { + + if ((main.sections[i] == this_ref) && !found) { + //enounter with original node + if (this_ref.debug) { + YAHOO.log("Found Original "+main.sections[i].getEl().id); + } + if (main.sections[i] == this_ref) { + found = true; + } + } else if (main.sections[i] == target) { + //encounter with target node + if (this_ref.debug) { + YAHOO.log("Found target "+main.sections[i].getEl().id); + } + main.sections[i].swap_dates(main.sections[eval(loopmodifier)]); + main.sections[i].swap_with_section(main.sections[eval(loopmodifier)]); + found = false; + break; + } else if (found) { + //encounter with nodes inbetween + main.sections[i].swap_dates(main.sections[eval(loopmodifier)]); + main.sections[i].swap_with_section(main.sections[eval(loopmodifier)]); + } + } + } + + failure = function(o) + { + } + //move on backend - main.connect('POST','class=section&field=move',null,'id='+this.sectionId+'&value=' + main.connect('POST','class=section&field=move', { success: success, failure: failure },'id='+this.sectionId+'&value=' +(target.sectionId - this.sectionId)); - //move on front end - for (var i=loopStart; eval(loopCondition); eval(loopInc)) { - - if ((main.sections[i] == this) && !found) { - //enounter with original node - if (this.debug) { - YAHOO.log("Found Original "+main.sections[i].getEl().id); - } - if (main.sections[i] == this) { - found = true; - } - } else if (main.sections[i] == target) { - //encounter with target node - if (this.debug) { - YAHOO.log("Found target "+main.sections[i].getEl().id); - } - main.sections[i].swap_dates(main.sections[eval(loopmodifier)]); - main.sections[i].swap_with_section(main.sections[eval(loopmodifier)]); - found = false; - break; - } else if (found) { - //encounter with nodes inbetween - main.sections[i].swap_dates(main.sections[eval(loopmodifier)]); - main.sections[i].swap_with_section(main.sections[eval(loopmodifier)]); - } - } }