mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-19756 Refactored JS code from SCORM and choice modules into the core function submit_form_by_id()
This commit is contained in:
parent
a19f419db2
commit
dc58020794
5 changed files with 27 additions and 19 deletions
|
@ -205,6 +205,22 @@ function lockoptionsallsetup(formid) {
|
||||||
return lockoptionsall(formid);
|
return lockoptionsall(formid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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) {
|
function submit_form_by_id(e, args) {
|
||||||
var theform = document.getElementById(args.id);
|
var theform = document.getElementById(args.id);
|
||||||
if (!theform) {
|
if (!theform) {
|
||||||
|
@ -213,10 +229,14 @@ function submit_form_by_id(e, args) {
|
||||||
if (theform.tagName.toLowerCase() != 'form') {
|
if (theform.tagName.toLowerCase() != 'form') {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(!theform.onsubmit || theform.onsubmit()) {
|
if (args.selectid) {
|
||||||
return theform.submit();
|
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
|
* Either check, or uncheck, all checkboxes inside the element with id is
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
function submit_attempts_form(e, args) {
|
|
||||||
if (e.target.selectedIndex > 0) {
|
|
||||||
submit_form_by_id(null, {id: 'attemptsform'});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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: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 '<a href="javascript:deselect_all_in(\'DIV\',null,\'tablecontainer\');">'.get_string('selectnone', 'quiz').'</a> ';
|
||||||
echo ' ';
|
echo ' ';
|
||||||
$PAGE->requires->js('mod/choice/choice.js');
|
|
||||||
$selectmenu = new moodle_select_menu();
|
$selectmenu = new moodle_select_menu();
|
||||||
$selectmenu->options = array('delete' => get_string('delete'));
|
$selectmenu->options = array('delete' => get_string('delete'));
|
||||||
$selectmenu->name = 'action';
|
$selectmenu->name = 'action';
|
||||||
$selectmenu->button->label = get_string('withselected', 'quiz');
|
$selectmenu->button->label = get_string('withselected', 'quiz');
|
||||||
$selectmenu->id = 'menuaction';
|
$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 $OUTPUT->select_menu($selectmenu);
|
||||||
echo '<noscript id="noscriptmenuaction" style="display: inline;">';
|
echo '<noscript id="noscriptmenuaction" style="display: inline;">';
|
||||||
echo '<div>';
|
echo '<div>';
|
||||||
|
|
|
@ -198,13 +198,12 @@
|
||||||
echo '<a href="javascript:select_all_in(\'DIV\',null,\'scormtablecontainer\');">'.get_string('selectall', 'quiz').'</a> / ';
|
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 '<a href="javascript:deselect_all_in(\'DIV\',null,\'scormtablecontainer\');">'.get_string('selectnone', 'quiz').'</a> ';
|
||||||
echo ' ';
|
echo ' ';
|
||||||
$PAGE->requires->js('mod/scorm/scorm.js');
|
|
||||||
$selectmenu = new moodle_select_menu();
|
$selectmenu = new moodle_select_menu();
|
||||||
$selectmenu->options = array('delete' => get_string('delete'));
|
$selectmenu->options = array('delete' => get_string('delete'));
|
||||||
$selectmenu->name = 'action';
|
$selectmenu->name = 'action';
|
||||||
$selectmenu->button->label = get_string('withselected', 'quiz');
|
$selectmenu->button->label = get_string('withselected', 'quiz');
|
||||||
$selectmenu->id = 'menuaction';
|
$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 $OUTPUT->select_menu($selectmenu);
|
||||||
echo '<noscript id="noscriptmenuaction" style="display: inline;">';
|
echo '<noscript id="noscriptmenuaction" style="display: inline;">';
|
||||||
echo '<div>';
|
echo '<div>';
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
function submit_attempts_form(e, args) {
|
|
||||||
if (e.target.selectedIndex > 0) {
|
|
||||||
submit_form_by_id(null, {id: 'attemptsform'});
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue