Permalink
Browse files

MDL-31216 Create dragdrop course module

  • Loading branch information...
1 parent ae2afdd commit 15e2552f00cdfc46d6cc467c3afdf4d7c9d9358b Ruslan Kabalin committed with andrewnicols Jan 18, 2012
Showing with 418 additions and 4 deletions.
  1. +2 −2 course/format/topics/format.php
  2. +2 −2 course/format/weeks/format.php
  3. +36 −0 course/lib.php
  4. +378 −0 course/yui/dragdrop/dragdrop.js
@@ -202,12 +202,12 @@
'<img src="'.$OUTPUT->pix_url('i/show') . '" class="icon hide" alt="'.$strtopicshow.'" /></a><br />';
}
if ($section > 1) { // Add a arrow to move section up
- echo '<a href="view.php?id='.$course->id.'&amp;random='.rand(1,10000).'&amp;section='.$section.'&amp;move=-1&amp;sesskey='.sesskey().'#section-'.($section-1).'" title="'.$strmoveup.'">'.
+ echo '<a href="view.php?id='.$course->id.'&amp;random='.rand(1,10000).'&amp;section='.$section.'&amp;move=-1&amp;sesskey='.sesskey().'#section-'.($section-1).'" title="'.$strmoveup.'" class="moveup">'.
'<img src="'.$OUTPUT->pix_url('t/up') . '" class="icon up" alt="'.$strmoveup.'" /></a><br />';
}
if ($section < $course->numsections) { // Add a arrow to move section down
- echo '<a href="view.php?id='.$course->id.'&amp;random='.rand(1,10000).'&amp;section='.$section.'&amp;move=1&amp;sesskey='.sesskey().'#section-'.($section+1).'" title="'.$strmovedown.'">'.
+ echo '<a href="view.php?id='.$course->id.'&amp;random='.rand(1,10000).'&amp;section='.$section.'&amp;move=1&amp;sesskey='.sesskey().'#section-'.($section+1).'" title="'.$strmovedown.'" class="movedown">'.
'<img src="'.$OUTPUT->pix_url('t/down') . '" class="icon down" alt="'.$strmovedown.'" /></a><br />';
}
}
@@ -201,12 +201,12 @@
'<img src="'.$OUTPUT->pix_url('i/show') . '" class="icon hide" alt="'.$strweekshow.'" /></a><br />';
}
if ($section > 1) { // Add a arrow to move section up
- echo '<a href="view.php?id='.$course->id.'&amp;random='.rand(1,10000).'&amp;section='.$section.'&amp;move=-1&amp;sesskey='.sesskey().'#section-'.($section-1).'" title="'.$strmoveup.'">'.
+ echo '<a href="view.php?id='.$course->id.'&amp;random='.rand(1,10000).'&amp;section='.$section.'&amp;move=-1&amp;sesskey='.sesskey().'#section-'.($section-1).'" title="'.$strmoveup.'" class="moveup">'.
'<img src="'.$OUTPUT->pix_url('t/up') . '" class="icon up" alt="'.$strmoveup.'" /></a><br />';
}
if ($section < $course->numsections) { // Add a arrow to move section down
- echo '<a href="view.php?id='.$course->id.'&amp;random='.rand(1,10000).'&amp;section='.$section.'&amp;move=1&amp;sesskey='.sesskey().'#section-'.($section+1).'" title="'.$strmovedown.'">'.
+ echo '<a href="view.php?id='.$course->id.'&amp;random='.rand(1,10000).'&amp;section='.$section.'&amp;move=1&amp;sesskey='.sesskey().'#section-'.($section+1).'" title="'.$strmovedown.'" class="movedown">'.
'<img src="'.$OUTPUT->pix_url('t/down') . '" class="icon down" alt="'.$strmovedown.'" /></a><br />';
}
}
View
@@ -3065,6 +3065,23 @@ function move_section_to($course, $section, $destination) {
$DB->set_field('course_sections', 'section', $position, array('id' => $id));
}
+ // Adjust destination to reflect the actual section
+ $moveup = false;
+ if ($section > $destination) {
+ $destination++;
+ $moveup = true;
+ }
+
+ // If we move the highlighted section itself, then just highlight the destination.
+ // Adjust the higlighted section location if we move something over it either direction.
+ if ($section == $course->marker) {
+ course_set_marker($course, $destination);
+ } elseif ($moveup && $section > $course->marker && $course->marker >= $destination) {
+ course_set_marker($course, $course->marker+1);
+ } elseif (!$moveup && $section < $course->marker && $course->marker <= $destination) {
+ course_set_marker($course, $course->marker-1);
+ }
+
// if the focus is on the section that is being moved, then move the focus along
if (course_get_display($course->id) == $section) {
course_set_display($course->id, $destination);
@@ -4470,6 +4487,23 @@ function include_course_ajax($course, $modules = array(), $config = null) {
))
);
+ // Include course dragdrop
+ $PAGE->requires->yui_module('moodle-course-dragdrop',
+ 'M.core_course.init_resource_dragdrop',
+ array(array(
+ 'courseid' => $course->id,
+ 'ajaxurl' => $config->resourceurl,
+ 'config' => $config,
+ )), null, true);
+
+ $PAGE->requires->yui_module('moodle-course-dragdrop',
+ 'M.core_course.init_section_dragdrop',
+ array(array(
+ 'courseid' => $course->id,
+ 'ajaxurl' => $config->sectionurl,
+ 'config' => $config,
+ )), null, true);
+
// Require various strings for the command toolbox
$PAGE->requires->strings_for_js(array(
'moveleft',
@@ -4483,6 +4517,8 @@ function include_course_ajax($course, $modules = array(), $config = null) {
'clicktochangeinbrackets',
'markthistopic',
'markedthistopic',
+ 'move',
+ 'movesection',
), 'moodle');
// Include format-specific strings
Oops, something went wrong.

0 comments on commit 15e2552

Please sign in to comment.