MDL-34741 use 2in3 in mod_survey

This commit is contained in:
Petr Škoda 2012-08-06 23:10:08 +02:00
parent 69ccc32d4f
commit 2de3515fcc
2 changed files with 29 additions and 24 deletions

View File

@ -1,26 +1,27 @@
function checkform(e) {
var error = false;
if (document.getElementById('surveyform')) {
var surveyform = document.getElementById('surveyform');
for (var i=0; i < surveycheck.questions.length; i++) {
var tempquestion = surveycheck.questions[i];
if (surveyform[tempquestion['question']][tempquestion['default']].checked) {
error = true;
}
}
}
if (error) {
alert(M.str.survey.questionsnotanswered);
YAHOO.util.Event.preventDefault(e);
return false;
} else {
return true;
}
}
function survey_attach_onsubmit() {
M.mod_survey = {};
M.mod_survey.init = function(Y) {
if (document.getElementById('surveyform')) {
var surveyform = document.getElementById('surveyform');
YAHOO.util.Event.addListener('surveyform', "submit", checkform);
Y.YUI2.util.Event.addListener('surveyform', "submit", function(e) {
var error = false;
if (document.getElementById('surveyform')) {
var surveyform = document.getElementById('surveyform');
for (var i=0; i < surveycheck.questions.length; i++) {
var tempquestion = surveycheck.questions[i];
if (surveyform[tempquestion['question']][tempquestion['default']].checked) {
error = true;
}
}
}
if (error) {
alert(M.str.survey.questionsnotanswered);
Y.YUI2.util.Event.preventDefault(e);
return false;
} else {
return true;
}
});
}
}
};

View File

@ -198,10 +198,14 @@ $completion->set_module_viewed($cm);
$checkarray['questions'][] = Array('question'=>$question, 'default'=>$default);
}
}
$PAGE->requires->js('/mod/survey/survey.js');
$PAGE->requires->data_for_js('surveycheck', $checkarray);
$module = array(
'name' => 'mod_survey',
'fullpath' => '/mod/survey/survey.js',
'requires' => array('yui2-event'),
);
$PAGE->requires->string_for_js('questionsnotanswered', 'survey');
$PAGE->requires->js_function_call('survey_attach_onsubmit');
$PAGE->requires->js_init_call('M.mod_survey.init', $checkarray, true, $module);
echo '<br />';
echo '<input type="submit" value="'.get_string("clicktocontinue", "survey").'" />';