MDL-20204 converted select + JS on participation page
authorPetr Skoda <skodak@moodle.org>
Thu, 11 Feb 2010 09:12:17 +0000 (09:12 +0000)
committerPetr Skoda <skodak@moodle.org>
Thu, 11 Feb 2010 09:12:17 +0000 (09:12 +0000)
user/index.php
user/module.js [new file with mode: 0644]
user/user.js [deleted file]

index 6db0518..d1bc700 100644 (file)
 
     if ($bulkoperations) {
         $PAGE->requires->js('/user/user.js');
-        echo '<form action="action_redir.php" method="post" id="participantsform" onsubmit="return checksubmit(this);">';
+        echo '<form action="action_redir.php" method="post" id="participantsform">';
         echo '<div>';
         echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
         echo '<input type="hidden" name="returnto" value="'.s(me()).'" />';
                 }
 
                 if ($bulkoperations) {
-                    $data[] = '<input type="checkbox" name="user'.$user->id.'" />';
+                    $data[] = '<input type="checkbox" class="usercheckbox" name="user'.$user->id.'" />';
                 }
                 $table->add_data($data);
 
 
     if ($bulkoperations) {
         echo '<br /><div class="buttons">';
-        echo '<input type="button" onclick="checkall()" value="'.get_string('selectall').'" /> ';
-        echo '<input type="button" onclick="checknone()" value="'.get_string('deselectall').'" /> ';
+        echo '<input type="button" id="checkall" value="'.get_string('selectall').'" /> ';
+        echo '<input type="button" id="checknone" value="'.get_string('deselectall').'" /> ';
         $displaylist = array();
         $displaylist['messageselect.php'] = get_string('messageselectadd');
         if (!empty($CFG->enablenotes) && has_capability('moodle/notes:manage', $context) && $context->id != $frontpagectx->id) {
         }
 
         echo $OUTPUT->help_icon("participantswithselectedusers", get_string("withselectedusers"));
-        $select = new html_select();
-        $select->options = $displaylist;
-        $select->name = "formaction";
-        $select->label = get_string("withselectedusers");
-        $select->add_action('change', 'conditionalsubmit', array('formid' => 'participantsform'));
-        echo $OUTPUT->select($select);
+        echo html_writer::tag('label', array('for'=>'formactionid'), get_string("withselectedusers"));
+        echo html_writer::select($displaylist, 'formaction', '', array(''=>'choosedots'), array('id'=>'formactionid'));
+
         echo '<input type="hidden" name="id" value="'.$course->id.'" />';
-        echo '<div id="noscriptparticipantsform" class="hiddenifjs">';
-        echo '<input type="submit" value="'.get_string('ok').'" /></div>';
-        echo '</div>';
-        echo '</div>';
+        echo '<noscript style="display:inline">';
+        echo '<input type="submit" value="'.get_string('ok').'" />';
+        echo '</noscript>';
+        echo '</div></div>';
         echo '</form>';
 
+        $module = array('name'=>'core_user', 'fullpath'=>'/user/module.js');
+        $PAGE->requires->js_init_call('M.core_user.init_participation', null, false, $module);
     }
 
     if (has_capability('moodle/site:viewparticipants', $context) && $totalcount > ($perpage*3)) {
diff --git a/user/module.js b/user/module.js
new file mode 100644 (file)
index 0000000..ef956d4
--- /dev/null
@@ -0,0 +1,34 @@
+
+M.core_user = {};
+
+M.core_user.init_participation = function(Y) {
+       Y.on('change', function() {
+               var action = Y.one('#formactionid');
+               if (action.get('value') == '') {
+                       return;
+               }
+        var ok = false;
+        Y.all('input.usercheckbox').each(function() {
+            if (this.get('checked')) {
+                ok = true;
+            }
+        });
+        if (!ok) {
+            // no checkbox selected
+            return;
+        }
+        Y.one('#participantsform').submit();
+       }, '#formactionid');
+
+    Y.on('click', function(e) {
+        Y.all('input.usercheckbox').each(function() {
+            this.set('checked', 'checked');
+        });
+    }, '#checkall');
+
+    Y.on('click', function(e) {
+        Y.all('input.usercheckbox').each(function() {
+            this.set('checked', '');
+        });
+    }, '#checknone');
+};
diff --git a/user/user.js b/user/user.js
deleted file mode 100644 (file)
index f3e7abf..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-function checksubmit(form) {
-    var destination = form.formaction.options[form.formaction.selectedIndex].value;
-    if (destination == "" || !checkchecked(form)) {
-        form.formaction.selectedIndex = 0;
-        return false;
-    } else {
-        return true;
-    }
-}
-
-function checkchecked(form) {
-    var inputs = document.getElementsByTagName('INPUT');
-    var checked = false;
-    inputs = filterByParent(inputs, function() {return form;});
-    for(var i = 0; i < inputs.length; ++i) {
-        if (inputs[i].type == 'checkbox' && inputs[i].checked) {
-            checked = true;
-        }
-    }
-    return checked;
-}
-
-function conditionalsubmit(event, args) {
-    var form = document.getElementById(args.formid);
-    if (checksubmit(form)) {
-        form.submit();
-    }
-}