MDL-33546: course: Fix current week hightlighting after dragging the section
authorRuslan Kabalin <r.kabalin@lancaster.ac.uk>
Fri, 1 Feb 2013 11:41:08 +0000 (11:41 +0000)
committerMarina Glancy <marina@moodle.com>
Tue, 18 Jun 2013 03:01:18 +0000 (13:01 +1000)
course/format/weeks/format.js
course/format/weeks/lib.php

index 1c36994..eb5e106 100644 (file)
@@ -75,6 +75,7 @@ M.course.format.process_sections = function(Y, sectionlist, response, sectionfro
         for (var i = sectionfrom; i <= sectionto; i++) {
             // Update section title.
             sectionlist.item(i).one('.'+CSS.SECTIONNAME).setContent(response.sectiontitles[i]);
+
             // Update move icon.
             ele = sectionlist.item(i).one(SELECTORS.SECTIONLEFTSIDE);
             str = ele.getAttribute('alt');
@@ -82,6 +83,14 @@ M.course.format.process_sections = function(Y, sectionlist, response, sectionfro
             newstr = str.substr(0, stridx +1) + i;
             ele.setAttribute('alt', newstr);
             ele.setAttribute('title', newstr); // For FireFox as 'alt' is not refreshed.
+
+            // Remove the current class as section has been moved.
+            sectionlist.item(i).removeClass('current');
+        }
+        // If there is a current section, apply corresponding class in order to highlight it.
+        if (response.current !== -1) {
+            // Add current class to the required section.
+            sectionlist.item(response.current).addClass('current');
         }
     }
 }
index d31128b..ded5ef0 100644 (file)
@@ -162,15 +162,19 @@ class format_weeks extends format_base {
     function ajax_section_move() {
         global $PAGE;
         $titles = array();
+        $current = -1;
         $course = $this->get_course();
         $modinfo = get_fast_modinfo($course);
         $renderer = $this->get_renderer($PAGE);
         if ($renderer && ($sections = $modinfo->get_section_info_all())) {
             foreach ($sections as $number => $section) {
                 $titles[$number] = $renderer->section_title($section, $course);
+                if ($this->is_section_current($section)) {
+                    $current = $number;
+                }
             }
         }
-        return array('sectiontitles' => $titles, 'action' => 'move');
+        return array('sectiontitles' => $titles, 'current' => $current, 'action' => 'move');
     }
 
     /**