MDL-71644 Quiz: The issues outstanding from MDL-70947.

Issue 1: While essay question's uploading progress, we need to disable submit
buttons to prevent submit form event.

Issue 2: Enable buttons after pressing cancel button on the popup
confirming overwrite file existed.
This commit is contained in:
Thong Bui 2021-05-18 18:15:25 +07:00
parent 0b69b37f04
commit f81cdd42b2
5 changed files with 38 additions and 10 deletions

View File

@ -756,6 +756,7 @@ M.form_dndupload.init = function(Y, options) {
e.preventDefault();
process_dlg.hide();
if (self.callbackcancel) {
this.triggerUploadCompleted();
self.callbackcancel();
}
}, this);
@ -794,13 +795,26 @@ M.form_dndupload.init = function(Y, options) {
// Destroy the dialog once it has been hidden.
process_dlg.after('visibleChange', function(e) {
if (!process_dlg.get('visible')) {
if (self.callbackcancel) {
this.triggerUploadCompleted();
self.callbackcancel();
}
process_dlg.destroy(true);
}
});
}, this);
process_dlg.show();
},
/**
* Trigger upload completed event.
*/
triggerUploadCompleted: function() {
require(['core_form/events'], function(FormEvent) {
FormEvent.triggerUploadCompleted(this.filemanagerhelper.filemanager.get('id'));
}.bind(this));
},
/**
* Checks if there is already a file with the given name in the current folder
* or in the list of already uploading files
@ -857,9 +871,7 @@ M.form_dndupload.init = function(Y, options) {
*/
uploadfinished: function(lastresult) {
// Trigger form upload complete events.
require(['core_form/events'], function(FormEvent) {
FormEvent.triggerUploadCompleted(this.filemanagerhelper.filemanager.get('id'));
}.bind(this));
this.triggerUploadCompleted();
this.callback(lastresult);
},

View File

@ -175,6 +175,12 @@ M.mod_quiz.nav.init = function(Y) {
// Automatically submit the form. We do it this strange way because just
// calling form.submit() does not run the form's submit event handlers.
var submit = form.one('input[name="next"]');
// Navigation when button enable.
if (submit.get('disabled')) {
return;
}
submit.set('name', '');
submit.getDOMNode().click();
};

View File

@ -536,7 +536,9 @@ class mod_quiz_renderer extends plugin_renderer_base {
$output .= html_writer::start_tag('div', array('class' => 'submitbtns'));
if ($page > 0 && $navmethod == 'free') {
$output .= html_writer::empty_tag('input', array('type' => 'submit', 'name' => 'previous',
'value' => get_string('navigateprevious', 'quiz'), 'class' => 'mod_quiz-prev-nav btn btn-secondary'));
'value' => get_string('navigateprevious', 'quiz'), 'class' => 'mod_quiz-prev-nav btn btn-secondary',
'id' => 'mod_quiz-prev-nav'));
$this->page->requires->js_call_amd('core_form/submit', 'init', ['mod_quiz-prev-nav']);
}
if ($lastpage) {
$nextlabel = get_string('endtest', 'quiz');
@ -544,8 +546,9 @@ class mod_quiz_renderer extends plugin_renderer_base {
$nextlabel = get_string('navigatenext', 'quiz');
}
$output .= html_writer::empty_tag('input', array('type' => 'submit', 'name' => 'next',
'value' => $nextlabel, 'class' => 'mod_quiz-next-nav btn btn-primary'));
'value' => $nextlabel, 'class' => 'mod_quiz-next-nav btn btn-primary', 'id' => 'mod_quiz-next-nav'));
$output .= html_writer::end_tag('div');
$this->page->requires->js_call_amd('core_form/submit', 'init', ['mod_quiz-next-nav']);
return $output;
}

View File

@ -256,12 +256,14 @@ echo $quba->render_question($slot, $options, $displaynumber);
echo html_writer::start_tag('div', array('id' => 'previewcontrols', 'class' => 'controls'));
echo html_writer::empty_tag('input', $restartdisabled + array('type' => 'submit',
'name' => 'restart', 'value' => get_string('restart', 'question'), 'class' => 'btn btn-secondary'));
echo html_writer::empty_tag('input', $finishdisabled + array('type' => 'submit',
'name' => 'save', 'value' => get_string('save', 'question'), 'class' => 'btn btn-secondary'));
echo html_writer::empty_tag('input', $finishdisabled + array('type' => 'submit',
'name' => 'save', 'value' => get_string('save', 'question'), 'class' => 'btn btn-secondary',
'id' => 'id_save_question_preview'));
echo html_writer::empty_tag('input', $filldisabled + array('type' => 'submit',
'name' => 'fill', 'value' => get_string('fillincorrect', 'question'), 'class' => 'btn btn-secondary'));
echo html_writer::empty_tag('input', $finishdisabled + array('type' => 'submit',
'name' => 'finish', 'value' => get_string('submitandfinish', 'question'), 'class' => 'btn btn-secondary'));
echo html_writer::empty_tag('input', $finishdisabled + array('type' => 'submit',
'name' => 'finish', 'value' => get_string('submitandfinish', 'question'), 'class' => 'btn btn-secondary',
'id' => 'id_finish_question_preview'));
echo html_writer::end_tag('div');
echo html_writer::end_tag('form');
@ -291,5 +293,7 @@ $PAGE->requires->strings_for_js(array(
'closepreview',
), 'question');
$PAGE->requires->yui_module('moodle-question-preview', 'M.question.preview.init');
$PAGE->requires->js_call_amd('core_form/submit', 'init', ['id_save_question_preview']);
$PAGE->requires->js_call_amd('core_form/submit', 'init', ['id_finish_question_preview']);
echo $OUTPUT->footer();

View File

@ -126,6 +126,9 @@ M.core_question_engine.questionformalreadysubmitted = false;
* @param button the id of the button in the HTML.
*/
M.core_question_engine.init_submit_button = function(Y, button) {
require(['core_form/submit'], function(submit) {
submit.init(button);
});
var totalQuestionsInPage = document.querySelectorAll('div.que').length;
var buttonel = document.getElementById(button);
var outeruniqueid = buttonel.closest('.que').id;