Merge branch 'MDL-71750-310' of https://github.com/NashTechOpenUniversity/moodle into MOODLE_310_STABLE

This commit is contained in:
Andrew Nicols
2021-10-25 13:58:46 +08:00
5 changed files with 50 additions and 14 deletions
+1 -1
View File
@@ -1,2 +1,2 @@
define ("core_form/submit",["exports","core_form/events"],function(a,b){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.init=void 0;var c=0,d=[],e=function(a){d.push(a);if(!c){c=setInterval(function(){var a=document.cookie.split(f()+"=");if(2==a.length){g();clearInterval(c);c=0;d.forEach(function(a){a.disabled=!1})}},500)}},f=function(){return"moodledownload_"+M.cfg.sesskey},g=function(){document.cookie=encodeURIComponent(f())+"=deleted; expires="+new Date(0).toUTCString()};a.init=function init(a){var c=document.getElementById(a);document.addEventListener(b.types.uploadStarted,function(a){window.console.log(a.target);c.disabled=!0});document.addEventListener(b.types.uploadCompleted,function(a){window.console.log(a.target);c.disabled=!1});if("off"===c.form.dataset.doubleSubmitProtection){return}c.form.addEventListener("submit",function(a){var b=function(){if(a.defaultPrevented||c.disabled){return}c.disabled=!0;g();e(c)};window.addEventListener("beforeunload",b);setTimeout(function(){window.removeEventListener("beforeunload",b)},0)},!1)}});
define ("core_form/submit",["exports","core_form/events"],function(a,b){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.init=void 0;var c=0,d=[],f=0,g=[],h=!1,i=function(a){d.push(a);if(!c){c=setInterval(function(){var a=document.cookie.split(j()+"=");if(2==a.length){k();clearInterval(c);c=0;d.forEach(function(a){a.disabled=!1})}},500)}},j=function(){return"moodledownload_"+M.cfg.sesskey},k=function(){document.cookie=encodeURIComponent(j())+"=deleted; expires="+new Date(0).toUTCString()},l=function(){if(f){g.forEach(function(a){a.disabled=!0})}else{g.forEach(function(a){a.disabled=!1})}},m=function(a){var c=document.getElementById(a);if(!c.disabled){g.push(c)}if(!h){document.addEventListener(b.types.uploadStarted,function(a){window.console.log(a.target);f++;l()});document.addEventListener(b.types.uploadCompleted,function(a){window.console.log(a.target);f--;l()});h=!0}if("off"===c.form.dataset.doubleSubmitProtection){return}c.form.addEventListener("submit",function(a){var b=function(){if(a.defaultPrevented||c.disabled){return}c.disabled=!0;k();i(c)};window.addEventListener("beforeunload",b);setTimeout(function(){window.removeEventListener("beforeunload",b)},0)},!1)};a.init=m});
//# sourceMappingURL=submit.min.js.map
File diff suppressed because one or more lines are too long
+43 -10
View File
@@ -31,6 +31,15 @@ let cookieListener = 0;
/** @property {Array} Array of buttons that need re-enabling if we get a download cookie */
const cookieListeningButtons = [];
/** @property {number} Number of files uploading. */
let currentUploadCount = 0;
/** @property {Array} Array of buttons that need re-enabling if we get a upload process. */
const uploadListeningButtons = [];
/** @property {Boolean} Is upload listeners registered? */
let uploadListenersRegistered = false;
/**
* Listens in case a download cookie is provided.
*
@@ -79,6 +88,21 @@ const clearDownloadCookie = () => {
document.cookie = encodeURIComponent(getCookieName()) + '=deleted; expires=' + new Date(0).toUTCString();
};
/**
* Enable submit buttons when all files are uploaded.
*/
const checkUploadCount = () => {
if (currentUploadCount) {
uploadListeningButtons.forEach(button => {
button.disabled = true;
});
} else {
uploadListeningButtons.forEach(button => {
button.disabled = false;
});
}
};
/**
* Initialises submit buttons.
*
@@ -86,18 +110,27 @@ const clearDownloadCookie = () => {
*/
export const init = (elementId) => {
const button = document.getElementById(elementId);
// If buttons are disabled by default, we do not enable them when file upload completed event is fired.
if (!button.disabled) {
uploadListeningButtons.push(button);
}
// Add event listener for file upload start.
document.addEventListener(types.uploadStarted, e => {
window.console.log(e.target); // This will be the element/section where the file is uploaded to.
button.disabled = true;
});
if (!uploadListenersRegistered) {
// Add event listener for file upload start.
document.addEventListener(types.uploadStarted, e => {
window.console.log(e.target); // This will be the element/section where the file is uploaded to.
currentUploadCount++;
checkUploadCount();
});
// Add event listener for file upload complete.
document.addEventListener(types.uploadCompleted, e => {
window.console.log(e.target); // This will be the element/section where the file is uploaded to.
button.disabled = false;
});
// Add event listener for file upload complete.
document.addEventListener(types.uploadCompleted, e => {
window.console.log(e.target); // This will be the element/section where the file is uploaded to.
currentUploadCount--;
checkUploadCount();
});
uploadListenersRegistered = true;
}
// If the form has double submit protection disabled, do nothing.
if (button.form.dataset.doubleSubmitProtection === 'off') {
-1
View File
@@ -849,7 +849,6 @@ M.form_dndupload.init = function(Y, options) {
process_dlg.after('visibleChange', function(e) {
if (!process_dlg.get('visible')) {
if (self.callbackcancel) {
this.notifyUploadCompleted();
self.callbackcancel();
}
process_dlg.destroy(true);
+5 -1
View File
@@ -255,7 +255,8 @@ echo $quba->render_question($slot, $options, $displaynumber);
// Finish the question form.
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 mr-1 mb-1'));
'name' => 'restart', 'value' => get_string('restart', 'question'), 'class' => 'btn btn-secondary mr-1 mb-1',
'id' => 'id_restart_question_preview'));
echo html_writer::empty_tag('input', $finishdisabled + array('type' => 'submit',
'name' => 'save', 'value' => get_string('save', 'question'), 'class' => 'btn btn-secondary mr-1 mb-1',
'id' => 'id_save_question_preview'));
@@ -295,5 +296,8 @@ $PAGE->requires->strings_for_js(array(
$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']);
$PAGE->requires->js_call_amd('core_form/submit', 'init', ['id_restart_question_preview']);
$PAGE->requires->yui_module('moodle-core-formchangechecker',
'M.core_formchangechecker.init', [['formid' => 'responseform']]);
echo $OUTPUT->footer();