Skip to content

Commit

Permalink
MDL-71961 Quiz: Disable quiz navigation buttons when files are uploading
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenphuctien committed Sep 13, 2021
1 parent 5af6e79 commit da619ac
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
45 changes: 39 additions & 6 deletions mod/quiz/module.js
Expand Up @@ -148,6 +148,32 @@ M.mod_quiz.timer = {
}
};

M.mod_quiz.filesUpload = {
/**
* YUI object.
*/
Y: null,

/**
* Number of files uploading.
*/
numberFilesUploading: 0,

/**
* Disable navigation block when uploading and enable navigation block when all files are uploaded.
*/
disableNavPanel: function() {
var quizNavigationBlock = document.getElementById('mod_quiz_navblock');
if (quizNavigationBlock) {
if (M.mod_quiz.filesUpload.numberFilesUploading) {
quizNavigationBlock.classList.add('nav-disabled');
} else {
quizNavigationBlock.classList.remove('nav-disabled');
}
}
}
};

M.mod_quiz.nav = M.mod_quiz.nav || {};

M.mod_quiz.nav.update_flag_state = function(attemptid, questionid, newstate) {
Expand Down Expand Up @@ -175,12 +201,6 @@ 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();
};
Expand Down Expand Up @@ -216,6 +236,19 @@ M.mod_quiz.nav.init = function(Y) {
}, 'a.endtestlink');
}

// Navigation buttons should be disabled when the files are uploading.
require(['core_form/events'], function(formEvent) {
document.addEventListener(formEvent.types.uploadStarted, function() {
M.mod_quiz.filesUpload.numberFilesUploading++;
M.mod_quiz.filesUpload.disableNavPanel();
});

document.addEventListener(formEvent.types.uploadCompleted, function() {
M.mod_quiz.filesUpload.numberFilesUploading--;
M.mod_quiz.filesUpload.disableNavPanel();
});
});

if (M.core_question_flags) {
M.core_question_flags.add_listener(M.mod_quiz.nav.update_flag_state);
}
Expand Down
6 changes: 6 additions & 0 deletions mod/quiz/styles.css
Expand Up @@ -196,6 +196,12 @@
margin: 0.5em 0;
}

#mod_quiz_navblock.nav-disabled > * {
opacity: .65;
pointer-events: none;
cursor: not-allowed;
}

/** mod quiz mod **/
#page-mod-quiz-mod #id_reviewoptionshdr .fitem {
width: 23%;
Expand Down

0 comments on commit da619ac

Please sign in to comment.