MDL-21577 converting select auto submit code
authorPetr Skoda <skodak@moodle.org>
Wed, 10 Feb 2010 16:20:28 +0000 (16:20 +0000)
committerPetr Skoda <skodak@moodle.org>
Wed, 10 Feb 2010 16:20:28 +0000 (16:20 +0000)
course/category.php
course/search.php
lib/javascript-static.js
lib/outputrenderers.php
mod/choice/lib.php
mod/feedback/analysis_course.php
mod/lesson/report.php
mod/scorm/locallib.php
mod/scorm/report.php
question/editlib.php

index 16180a1..404fd23 100644 (file)
             make_categories_list($movetocategories, $notused, 'moodle/category:manage');
             $movetocategories[$category->id] = get_string('moveselectedcoursesto');
             echo '<tr><td colspan="3" align="right">';
-            $select = new html_select();
-            $select->options = $movetocategories;
-            $select->name = 'moveto';
-            $select->selectedvalue = $category->id;
-            $select->add_action('change', 'submit_form_by_id', array('id' => 'movecourses'));
-            echo $OUTPUT->select($select);
+            echo html_writer::select($movetocategories, 'moveto', $category->id, null, array('id'=>'movetoid'));
+            $PAGE->requires->js_init_call('M.util.init_select_autosubmit', array('movecourses', 'movetoid', false));
             echo '<input type="hidden" name="id" value="'.$category->id.'" />';
             echo '</td></tr>';
         }
index 5b20542..e64f806 100644 (file)
             echo "<br />";
             echo "<input type=\"button\" onclick=\"checkall()\" value=\"$strselectall\" />\n";
             echo "<input type=\"button\" onclick=\"checknone()\" value=\"$strdeselectall\" />\n";
-            $select = new html_select();
-            $select->options = $displaylist;
-            $select->name = "moveto";
-            $select->label = get_string("moveselectedcoursesto");
-            $select->add_action('change', 'submit_form_by_id', array('id' => 'movecourses'));
-            echo $OUTPUT->select($select);
+            echo html_writer::select($displaylist, 'moveto', '', array(''=>get_string('moveselectedcoursesto')), array('id'=>'movetoid'));
+            $PAGE->requires->js_init_call('M.util.init_select_autosubmit', array('movecourses', 'movetoid', false));
             echo "</td>\n</tr>\n";
             echo "</table>\n</form>";
 
index f843c69..767a382 100644 (file)
@@ -384,7 +384,7 @@ M.util.init_maximised_embed = function(Y, id) {
 /**
  * Attach handler to single_select
  */
-M.util.init_single_select = function(Y, formid, selectid, nothing) {
+M.util.init_select_autosubmit = function(Y, formid, selectid, nothing) {
        YUI(M.yui.loader).use('node', function(Y) {
                Y.on('change', function() {
                if ((nothing == false && Y.Lang.isBoolean(nothing)) || Y.one('#'+selectid).get('value') != nothing) {
@@ -655,39 +655,6 @@ function lockoptionsallsetup(formid) {
     return lockoptionsall(formid);
 }
 
-/**
- * Helper function mainly for drop-down menus' onchange events,
- * submits the form designated by args.id.
- * Example usage of the html_select component with this function:
- * <pre>
- * $select = new html_select();
- * $select->options = array('delete' => get_string('delete'));
- * $select->name = 'action';
- * $select->button->label = get_string('withselected', 'quiz');
- * $select->id = 'menuaction';
- * $select->add_action('change', 'submit_form_by_id', array('id' => 'attemptsform', 'selectid' => 'menuaction'));
- * echo $OUTPUT->select($select);
- * </pre>
- */
-function submit_form_by_id(e, args) {
-    var theform = document.getElementById(args.id);
-    if (!theform) {
-        return false;
-    }
-    if (theform.tagName.toLowerCase() != 'form') {
-        return false;
-    }
-    //MDL-21513 the below makes the first option unselectable assuming it will be some sort
-    //of "Choose..." option. However if there is no placeholder first option the first item is unselectable :(
-    //if (args.selectid) {
-      //  var select = document.getElementById(args.selectid);
-        //if (select.selectedIndex == 0) {
-          //  return false;
-        //}
-    //}
-    return theform.submit();
-}
-
 /**
  * Either check, or uncheck, all checkboxes inside the element with id is
  * @param id the id of the container
@@ -1459,10 +1426,6 @@ function frame_breakout(e, properties) {
 //       DO NOT USE!!!!!!!
 // Do not put this stuff in separate file because it only adds extra load on servers!
 
-function submitFormById(id) {
-    submit_form_by_id(null, {id: id});
-}
-
 /**
  * Used in a couple of modules to hide navigation areas when using AJAX
  */
index 3a2d13e..8167d8b 100644 (file)
@@ -1146,7 +1146,7 @@ class core_renderer extends renderer_base {
         $output .= html_writer::tag('noscript', array('style'=>'inline'), $go);
 
         $nothing = empty($select->nothing) ? false : key($select->nothing);
-        $output .= $this->page->requires->js_init_call('M.util.init_single_select', array($select->formid, $select->attributes['id'], $nothing));
+        $this->page->requires->js_init_call('M.util.init_select_autosubmit', array($select->formid, $select->attributes['id'], $nothing));
 
         // then div wrapper for xhtml strictness
         $output = html_writer::tag('div', array(), $output);
index 08a0298..d731494 100644 (file)
@@ -546,14 +546,10 @@ 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;';
-                $select = new html_select();
-                $select->options = array('delete' => get_string('delete'));
-                $select->name = 'action';
-                $select->button->label = get_string('withselected', 'quiz');
-                $select->id = 'menuaction';
-                $select->add_action('change', 'submit_form_by_id', array('id' => 'attemptsform', 'selectid' => 'menuaction'));
-                echo $OUTPUT->select($select);
-                echo '<noscript id="noscriptmenuaction" class="hiddenifjs">';
+                echo html_writer::tag('label', array('for'=>'menuaction'), get_string('withselected', 'quiz')); 
+                echo html_writer::select(array('delete' => get_string('delete')), 'action', '', array(''=>get_string('moveselectedcoursesto')), array('id'=>'menuaction'));
+                $PAGE->requires->js_init_call('M.util.init_select_autosubmit', array('attemptsform', 'menuaction', ''));
+                echo '<noscript id="noscriptmenuaction" style="display:inline">';
                 echo '<div>';
                 echo '<input type="submit" value="'.get_string('go').'" /></div></noscript>';
                 echo '</td><td></td></tr>';
index 2a6ba9c..eb102cb 100644 (file)
@@ -157,12 +157,9 @@ if ($courseitemfilter > 0) {
     if ($courses = $DB->get_records_sql_menu($sql, $params)) {
 
          echo ' ' . get_string('filter_by_course', 'feedback') . ': ';
-         $select = new html_select();
-         $select->options = $courses;
-         $select->name = 'coursefilter';
-         $select->selectedvalue = $coursefilter;
-         $select->add_action('change', 'submit_form_by_id', array('id' => 'analysis-form'));
-         echo $OUTPUT->select($select);
+         
+         echo htmL_writer::select($courses, 'coursefilter', $coursefilter, null, array('id'=>'coursefilterid'));
+         $PAGE->requires->js_init_call('M.util.init_select_autosubmit', array('analysis-form', 'coursefilterid', false));
     }
     echo '<hr />';
     $itemnr = 0;
index 4c6ec21..d643a24 100644 (file)
@@ -302,13 +302,10 @@ if ($action == 'reportoverview') {
     echo $OUTPUT->table($table);
     if (has_capability('mod/lesson:edit', $context)) {
         $checklinks  = '<a href="javascript: checkall();">'.get_string('selectall').'</a> / ';
-        $checklinks .='<a href="javascript: checknone();">'.get_string('deselectall').'</a>';
-        $select = new html_select();
-        $select->options = array('delete' => get_string('deleteselected'));
-        $select->name = 'attemptaction';
-        $select->selectedvalue = 0;
-        $select->add_action('change', 'submit_form_by_id', array('id' => 'theform'));
-        echo $OUTPUT->box($checklinks.$OUTPUT->select($select), 'center');
+        $checklinks .= '<a href="javascript: checknone();">'.get_string('deselectall').'</a>';
+        $checklinks .= htmL_writer::select(array('delete' => get_string('deleteselected')), 'attemptaction', 0, array(''=>'choosedots'), array('id'=>'actionid'));
+        $PAGE->requires->js_init_call('M.util.init_select_autosubmit', array('theform', 'actionid', ''));
+        echo $OUTPUT->box($checklinks, 'center');
         echo '</form>';
     }
 
index c7af2d8..4c1820f 100755 (executable)
@@ -728,21 +728,10 @@ function scorm_view_display ($user, $scorm, $action, $cm, $boxwidth='') {
     }
     if ($orgs = $DB->get_records_menu('scorm_scoes', array('scorm'=>$scorm->id, 'organization'=>'', 'launch'=>''), 'id', 'id,title')) {
         if (count($orgs) > 1) {
- ?>
-            <div class='scorm-center'>
-                <?php print_string('organizations','scorm') ?>
-                <form id='changeorg' method='post' action='<?php echo $action ?>'>
-                    <?php
-                    $select = new html_select();
-                    $select->options = $orgs;
-                    $select->name = 'organization';
-                    $select->selectedvalue = $organization;
-                    $select->add_action('change', 'submit_form_by_id', array('id' => 'changeorg'));
-                    echo $OUTPUT->select($select);
-                    ?>
-                </form>
-            </div>
-<?php
+            $select = new single_select(new moodle_url($action), 'organization', $orgs, $organization, null);
+            $select->lable = get_string('organizations','scorm');
+            $select->class = 'scorm-center';
+            echo $OUTPUT->render($select);
         }
     }
     $orgidentifier = '';
index c05aa72..32f96b8 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;';
-                    $select = new html_select();
-                    $select->options = array('delete' => get_string('delete'));
-                    $select->name = 'action';
-                    $select->button->label = get_string('withselected', 'quiz');
-                    $select->id = 'menuaction';
-                    $select->add_action('change', 'submit_form_by_id', array('id' => 'attemptsform', 'selectid' => 'menuaction'));
-                    echo $OUTPUT->select($select);
-                    echo '<noscript id="noscriptmenuaction" class="hiddenifjs">';
+                    echo htnml_writer::tag('label', array('for'=>'menuaction'), get_string('withselected', 'quiz'));
+                    echo htmL_writer::select(array('delete' => get_string('delete')), 'action', '', array(''=>'choosedots'), array('id'=>'menuaction'));
+                    $PAGE->requires->js_init_call('M.util.init_select_autosubmit', array('attemptsform', 'menuaction', ''));
+                    echo '<noscript id="noscriptmenuaction" style="disaply:inline">';
                     echo '<div>';
                     echo '<input type="submit" value="'.get_string('go').'" /></div></noscript>';
                     echo '</form>';
index dae6616..5628955 100644 (file)
@@ -1176,9 +1176,6 @@ class question_bank_view {
 
         $editurl = new moodle_url('/question/edit.php', $pageurl->params());
         $select = new single_select($editurl, 'category', $catmenu, $current, null, 'catmenu');
-        // The js func submit_form_by_id ignores the first element by default when using
-        // the html_select component so we need to unset the selectid param to make it
-        // work in the way we want for this control
         $select->set_label(get_string('selectacategory', 'question'));
         echo $OUTPUT->render($select);
         echo "</div>\n";