var toggles=YAHOO.util.Dom.getElementsByClassName('togglecompletion', 'form');
for(var i=0;i<toggles.length;i++) {
- completion_init_toggle(toggles[i]);
+ if(toggles[i].className.indexOf('preventjs')==-1) {
+ completion_init_toggle(toggles[i]);
+ }
}
}
$completiondata->completionstate==COMPLETION_COMPLETE
? COMPLETION_INCOMPLETE
: COMPLETION_COMPLETE;
- // In manual mode the icon is a toggle form.
+ // In manual mode the icon is a toggle form...
+
+ // If this completion state is used by the
+ // conditional activities system, we need to turn
+ // off the JS.
+ if (!empty($CFG->enableavailability) &&
+ condition_info::completion_value_used_as_condition(
+ $course, $mod)) {
+ $extraclass = ' preventjs';
+ } else {
+ $extraclass = '';
+ }
echo "
-<form class='togglecompletion' method='post' action='togglecompletion.php'><div>";
+<form class='togglecompletion$extraclass' method='post' action='togglecompletion.php'><div>";
if(!$shownhelp && !$isediting) {
helpbutton('completionicons',get_string('completionicons','completion'),'completion');
$shownhelp=true;
}
}
}
+
+ /**
+ * Used in course/lib.php because we need to disable the completion JS if
+ * a completion value affects a conditional activity.
+ * @param object $course Moodle course object
+ * @param object $cm Moodle course-module
+ * @return bool True if this is used in a condition, false otherwise
+ */
+ public static function completion_value_used_as_condition($course,$cm) {
+ // Have we already worked out a list of required completion values
+ // for this course? If so just use that
+ static $affected = array();
+ if (!array_key_exists($course->id, $affected)) {
+ // We don't have data for this course, build it
+ $modinfo = get_fast_modinfo($course);
+ $affected[$course->id] = array();
+ foreach ($modinfo->cms as $cm) {
+ foreach ($cm->conditionscompletion as $cmid=>$expectedcompletion) {
+ $affected[$course->id][$cmid] = true;
+ }
+ }
+ }
+ return array_key_exists($cm->id,$affected[$course->id]);
+ }
}
?>