]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-19756 Refactored JS code from SCORM and choice modules into the core function...
authornicolasconnault <nicolasconnault>
Tue, 28 Jul 2009 11:24:57 +0000 (11:24 +0000)
committernicolasconnault <nicolasconnault>
Tue, 28 Jul 2009 11:24:57 +0000 (11:24 +0000)
lib/javascript-static.js
mod/choice/choice.js [deleted file]
mod/choice/lib.php
mod/scorm/report.php
mod/scorm/scorm.js [deleted file]

index 5e45a675f694eebe8b8b9d0e18b6517c9c78dadf..0f4de7a7202c8322a20c8381e79ee0944d5e4a55 100644 (file)
@@ -205,17 +205,37 @@ function lockoptionsallsetup(formid) {
     return lockoptionsall(formid);
 }
 
-function submit_form_by_id(e, args) { 
+/**
+ * Helper function mainly for drop-down menus' onchange events,
+ * submits the form designated by args.id. If args.selectid is also
+ * given, it only submits the form if the selected <option> is not 
+ * the first one (usually the "Choose..." option)
+ * Example usage of the moodle_select_menu component with this function:
+ * <pre>
+ * $selectmenu = new moodle_select_menu();
+ * $selectmenu->options = array('delete' => get_string('delete'));
+ * $selectmenu->name = 'action';
+ * $selectmenu->button->label = get_string('withselected', 'quiz');
+ * $selectmenu->id = 'menuaction';
+ * $selectmenu->add_action('change', 'submit_form_by_id', array('id' => 'attemptsform', 'selectid' => 'menuaction'));
+ * echo $OUTPUT->select_menu($selectmenu);
+ * </pre>
+ */
+function submit_form_by_id(e, args) {
     var theform = document.getElementById(args.id);
-    if(!theform) {
+    if (!theform) {
         return false;
     }
-    if(theform.tagName.toLowerCase() != 'form') {
+    if (theform.tagName.toLowerCase() != 'form') {
         return false;
     }
-    if(!theform.onsubmit || theform.onsubmit()) {
-        return theform.submit();
+    if (args.selectid) {
+        var select = document.getElementById(args.selectid);
+        if (select.selectedIndex == 0) {
+            return false;
+        }
     }
+    return theform.submit();
 }
 
 /**
diff --git a/mod/choice/choice.js b/mod/choice/choice.js
deleted file mode 100644 (file)
index 19897bd..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-function submit_attempts_form(e, args) {
-    if (e.target.selectedIndex > 0) {
-        submit_form_by_id(null, {id: 'attemptsform'});
-    }
-}
index b832cffd2ac28bcc1aabe97179de05ecfa8e9eff..5f1db1d42a35068aa765292eae0373f628700095 100644 (file)
@@ -544,13 +544,12 @@ function choice_show_results($choice, $course, $cm, $allresponses, $forcepublish
                 echo '<a href="javascript:select_all_in(\'DIV\',null,\'tablecontainer\');">'.get_string('selectall', 'quiz').'</a> / ';
                 echo '<a href="javascript:deselect_all_in(\'DIV\',null,\'tablecontainer\');">'.get_string('selectnone', 'quiz').'</a> ';
                 echo '&nbsp;&nbsp;';
-                $PAGE->requires->js('mod/choice/choice.js');
                 $selectmenu = new moodle_select_menu();
                 $selectmenu->options = array('delete' => get_string('delete'));
                 $selectmenu->name = 'action';
                 $selectmenu->button->label = get_string('withselected', 'quiz');
                 $selectmenu->id = 'menuaction';
-                $selectmenu->add_action('change', 'submit_attempts_form');
+                $selectmenu->add_action('change', 'submit_form_by_id', array('id' => 'attemptsform', 'selectid' => 'menuaction'));
                 echo $OUTPUT->select_menu($selectmenu);
                 echo '<noscript id="noscriptmenuaction" style="display: inline;">';
                 echo '<div>';
index cb474a2053776e027ede3f3247c6157e5c2a30b1..a03a715035800e720bcda57f10a2d8e7d4e41d8f 100755 (executable)
                     echo '<a href="javascript:select_all_in(\'DIV\',null,\'scormtablecontainer\');">'.get_string('selectall', 'quiz').'</a> / ';
                     echo '<a href="javascript:deselect_all_in(\'DIV\',null,\'scormtablecontainer\');">'.get_string('selectnone', 'quiz').'</a> ';
                     echo '&nbsp;&nbsp;';
-                    $PAGE->requires->js('mod/scorm/scorm.js');
                     $selectmenu = new moodle_select_menu();
                     $selectmenu->options = array('delete' => get_string('delete'));
                     $selectmenu->name = 'action';
                     $selectmenu->button->label = get_string('withselected', 'quiz');
                     $selectmenu->id = 'menuaction';
-                    $selectmenu->add_action('change', 'submit_attempts_form');
+                    $selectmenu->add_action('change', 'submit_form_by_id', array('id' => 'attemptsform', 'selectid' => 'menuaction'));
                     echo $OUTPUT->select_menu($selectmenu);
                     echo '<noscript id="noscriptmenuaction" style="display: inline;">';
                     echo '<div>';
diff --git a/mod/scorm/scorm.js b/mod/scorm/scorm.js
deleted file mode 100644 (file)
index 19897bd..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-function submit_attempts_form(e, args) {
-    if (e.target.selectedIndex > 0) {
-        submit_form_by_id(null, {id: 'attemptsform'});
-    }
-}