From f81cdd42b2cec14252b602bf2de2dc6bd06428b2 Mon Sep 17 00:00:00 2001 From: Thong Bui Date: Tue, 18 May 2021 18:15:25 +0700 Subject: [PATCH] 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. --- lib/form/dndupload.js | 20 ++++++++++++++++---- mod/quiz/module.js | 6 ++++++ mod/quiz/renderer.php | 7 +++++-- question/preview.php | 12 ++++++++---- question/qengine.js | 3 +++ 5 files changed, 38 insertions(+), 10 deletions(-) diff --git a/lib/form/dndupload.js b/lib/form/dndupload.js index 6d7063d4704..bc8cf5dd15a 100644 --- a/lib/form/dndupload.js +++ b/lib/form/dndupload.js @@ -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); }, diff --git a/mod/quiz/module.js b/mod/quiz/module.js index a62d34a2e95..aae70408361 100644 --- a/mod/quiz/module.js +++ b/mod/quiz/module.js @@ -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(); }; diff --git a/mod/quiz/renderer.php b/mod/quiz/renderer.php index 65622b1c72c..2dadeb2fad7 100644 --- a/mod/quiz/renderer.php +++ b/mod/quiz/renderer.php @@ -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; } diff --git a/question/preview.php b/question/preview.php index 0d2e0192e00..52b455a6c93 100644 --- a/question/preview.php +++ b/question/preview.php @@ -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(); diff --git a/question/qengine.js b/question/qengine.js index e14f918cd74..f8e0cafe930 100644 --- a/question/qengine.js +++ b/question/qengine.js @@ -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;