Merge branch 'MDL-57697-master' of git://github.com/danpoltawski/moodle

This commit is contained in:
David Monllao 2017-02-15 11:00:55 +01:00
commit 759a70d32e
4 changed files with 9 additions and 27 deletions

View File

@ -1 +1 @@
define(["jquery","core/str","core/modal_factory","core/notification"],function(a,b,c,d){return{ensureRadiosChosen:function(e,f){var g=b.get_strings([{key:"error",component:"moodle"},{key:"questionsnotanswered",component:"survey"}]).then(function(a){return c.create({type:c.types.CANCEL,title:a[0],body:a[1]})})["catch"](d.exception),h=a("#"+e);h.submit(function(a){var b=!1;return f.forEach(function(a){var c=h.find('input:radio[name="'+a.name+'"]:checked');c.val()==a["default"]&&(b=!0)}),!b||(a.preventDefault(),g.then(function(a){a.show()}),!1)})}}});
define(["jquery","core/str","core/modal_factory","core/notification"],function(a,b,c,d){return{ensureRadiosChosen:function(e){var f=b.get_strings([{key:"error",component:"moodle"},{key:"questionsnotanswered",component:"survey"}]).then(function(a){return c.create({type:c.types.CANCEL,title:a[0],body:a[1]})})["catch"](d.exception),g=a("#"+e);g.submit(function(a){return 0===g.find('input:radio[data-survey-default="true"]:checked').length||(a.preventDefault(),f.then(function(a){a.show()}),!1)})}}});

View File

@ -31,7 +31,7 @@ define(['jquery', 'core/str', 'core/modal_factory', 'core/notification'], functi
* @param {String} formid HTML id of form
* @param {Array} questions
*/
ensureRadiosChosen: function(formid, questions) {
ensureRadiosChosen: function(formid) {
// Prepare modal for display in case of problems.
var modalPromise = Str.get_strings([
{key: 'error', component: 'moodle'},
@ -46,15 +46,8 @@ define(['jquery', 'core/str', 'core/modal_factory', 'core/notification'], functi
var form = $('#' + formid);
form.submit(function(e) {
var error = false;
questions.forEach(function(question) {
var checkedResponse = form.find('input:radio[name="' + question.name + '"]:checked');
if (checkedResponse.val() == question.default) {
error = true;
}
});
if (error) {
// Look for unanswered questions..
if (form.find('input:radio[data-survey-default="true"]:checked').length !== 0) {
e.preventDefault();
// Display the modal error.
modalPromise.then(function(modal) {

View File

@ -497,7 +497,7 @@ function survey_shorten_name ($name, $numwords) {
* @param object $question
*/
function survey_print_multi($question) {
global $USER, $DB, $qnum, $checklist, $DB, $OUTPUT; //TODO: this is sloppy globals abuse
global $USER, $DB, $qnum, $DB, $OUTPUT; //TODO: this is sloppy globals abuse
$stripreferthat = get_string("ipreferthat", "survey");
$strifoundthat = get_string("ifoundthat", "survey");
@ -555,15 +555,13 @@ function survey_print_multi($question) {
echo $q->text ."</th>\n";
$default = get_accesshide($strdefault);
echo "<td class=\"whitecell\"><label for=\"q$P$q->id\"><input type=\"radio\" name=\"q$P$q->id\" id=\"q$P" . $q->id . "_D\" value=\"0\" checked=\"checked\" />$default</label></td>";
echo "<td class=\"whitecell\"><label for=\"q$P$q->id\"><input type=\"radio\" name=\"q$P$q->id\" id=\"q$P" . $q->id . "_D\" value=\"0\" checked=\"checked\" data-survey-default=\"true\" />$default</label></td>";
for ($i=1;$i<=$numoptions;$i++) {
$hiddentext = get_accesshide($options[$i-1]);
$id = "q$P" . $q->id . "_$i";
echo "<td><label for=\"$id\"><input type=\"radio\" name=\"q$P$q->id\" id=\"$id\" value=\"$i\" />$hiddentext</label></td>";
}
$checklist["q$P$q->id"] = 0;
} else {
echo "<th scope=\"row\" class=\"optioncell\">";
echo "<b class=\"qnumtopcell\">$qnum</b> &nbsp; ";
@ -572,7 +570,7 @@ function survey_print_multi($question) {
echo "<span class=\"option\">$q->text</span></th>\n";
$default = get_accesshide($strdefault);
echo '<td class="whitecell"><label for="qP'.$q->id.'"><input type="radio" name="qP'.$q->id.'" id="qP'.$q->id.'" value="0" checked="checked" />'.$default.'</label></td>';
echo '<td class="whitecell"><label for="qP'.$q->id.'"><input type="radio" name="qP'.$q->id.'" id="qP'.$q->id.'" value="0" checked="checked" data-survey-default="true" />'.$default.'</label></td>';
for ($i=1;$i<=$numoptions;$i++) {
@ -589,16 +587,13 @@ function survey_print_multi($question) {
echo "<span class=\"option\">$q->text</span></th>\n";
$default = get_accesshide($strdefault);
echo '<td class="whitecell"><label for="q'. $q->id .'"><input type="radio" name="q'.$q->id. '" id="q'. $q->id .'" value="0" checked="checked" />'.$default.'</label></td>';
echo '<td class="whitecell"><label for="q'. $q->id .'"><input type="radio" name="q'.$q->id. '" id="q'. $q->id .'" value="0" checked="checked" data-survey-default="true" />'.$default.'</label></td>';
for ($i=1;$i<=$numoptions;$i++) {
$hiddentext = get_accesshide($options[$i-1]);
$id = "q" . $q->id . "_$i";
echo "<td><label for=\"$id\"><input type=\"radio\" name=\"q$q->id\" id=\"$id\" value=\"$i\" />$hiddentext</label></td>";
}
$checklist["qP$q->id"] = 0;
$checklist["q$q->id"] = 0;
}
echo "</tr>\n";
}

View File

@ -151,9 +151,7 @@ echo '<div>'. get_string('allquestionrequireanswer', 'survey'). '</div>';
$questions = survey_get_questions($survey);
global $qnum; // TODO: ugly globals hack for survey_print_*().
global $checklist; // TODO: ugly globals hack for survey_print_*().
$qnum = 0;
$checklist = array();
foreach ($questions as $question) {
if ($question->type >= 0) {
@ -175,11 +173,7 @@ if (!is_enrolled($context)) {
exit;
}
$questions = array();
foreach ($checklist as $question => $default) {
$questions[] = array('name' => $question, 'default' => $default);
}
$PAGE->requires->js_call_amd('mod_survey/validation', 'ensureRadiosChosen', array('surveyform', $questions));
$PAGE->requires->js_call_amd('mod_survey/validation', 'ensureRadiosChosen', array('surveyform'));
echo '<br />';
echo '<input type="submit" class="btn btn-primary" value="'.get_string("clicktocontinue", "survey").'" />';