From 76c0a743bf23f87c134cd6346438c2378411645a Mon Sep 17 00:00:00 2001 From: Thong Bui Date: Thu, 23 Sep 2021 09:04:36 +0700 Subject: [PATCH] MDL-71750 File upload: Disable submittion when uploading multiple files Fixed issue "Save" and "Submit and finish" button is not disabled when file uploading in the ticket MDL-71644 --- lib/form/amd/build/submit.min.js | 2 +- lib/form/amd/build/submit.min.js.map | 2 +- lib/form/amd/src/submit.js | 53 +++++++++++++++---- lib/form/dndupload.js | 1 - question/bank/previewquestion/preview.php | 4 ++ .../templates/preview_question.mustache | 6 +-- 6 files changed, 52 insertions(+), 16 deletions(-) diff --git a/lib/form/amd/build/submit.min.js b/lib/form/amd/build/submit.min.js index 3ee06b9cb78..df8fce4738e 100644 --- a/lib/form/amd/build/submit.min.js +++ b/lib/form/amd/build/submit.min.js @@ -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.eventTypes.uploadStarted,function(a){window.console.log(a.target);c.disabled=!0});document.addEventListener(b.eventTypes.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.eventTypes.uploadStarted,function(a){window.console.log(a.target);f++;l()});document.addEventListener(b.eventTypes.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 diff --git a/lib/form/amd/build/submit.min.js.map b/lib/form/amd/build/submit.min.js.map index 119f6ed4bb7..0605585bb87 100644 --- a/lib/form/amd/build/submit.min.js.map +++ b/lib/form/amd/build/submit.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/submit.js"],"names":["cookieListener","cookieListeningButtons","listenForDownloadCookie","button","push","setInterval","parts","document","cookie","split","getCookieName","length","clearDownloadCookie","clearInterval","forEach","disabled","M","cfg","sesskey","encodeURIComponent","Date","toUTCString","init","elementId","getElementById","addEventListener","eventTypes","uploadStarted","e","window","console","log","target","uploadCompleted","form","dataset","doubleSubmitProtection","event","disableAction","defaultPrevented","setTimeout","removeEventListener"],"mappings":"uJA4BIA,CAAAA,CAAc,CAAG,C,CAGfC,CAAsB,CAAG,E,CAazBC,CAAuB,CAAG,SAACC,CAAD,CAAY,CACxCF,CAAsB,CAACG,IAAvB,CAA4BD,CAA5B,EACA,GAAI,CAACH,CAAL,CAAqB,CACjBA,CAAc,CAAGK,WAAW,CAAC,UAAM,CAE/B,GA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,CAA6B,QAA7B,CAAuC,SAASY,CAAT,CAAgB,CAGnD,GAAMC,CAAAA,CAAa,CAAG,UAAW,CAE7B,GAAID,CAAK,CAACE,gBAAN,EAA0BpC,CAAM,CAACY,QAArC,CAA+C,CAC3C,MACH,CAEDZ,CAAM,CAACY,QAAP,IACAH,CAAmB,GACnBV,CAAuB,CAACC,CAAD,CAC1B,CATD,CAUA0B,MAAM,CAACJ,gBAAP,CAAwB,cAAxB,CAAwCa,CAAxC,EAIAE,UAAU,CAAC,UAAW,CAClBX,MAAM,CAACY,mBAAP,CAA2B,cAA3B,CAA2CH,CAA3C,CACH,CAFS,CAEP,CAFO,CAGb,CApBD,IAqBH,C","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Submit button JavaScript. All submit buttons will be automatically disabled once the form is\n * submitted, unless that submission results in an error/cancelling the submit.\n *\n * @module core_form/submit\n * @copyright 2019 The Open University\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @since 3.8\n */\n\nimport {eventTypes} from 'core_form/events';\n\n/** @property {number} ID for setInterval used when polling for download cookie */\nlet cookieListener = 0;\n\n/** @property {Array} Array of buttons that need re-enabling if we get a download cookie */\nconst cookieListeningButtons = [];\n\n/**\n * Listens in case a download cookie is provided.\n *\n * This function is used to detect file downloads. If there is a file download then we get a\n * beforeunload event, but the page is never unloaded and when the file download completes we\n * should re-enable the buttons. We detect this by watching for a specific cookie.\n *\n * PHP function \\core_form\\util::form_download_complete() can be used to send this cookie.\n *\n * @param {HTMLElement} button Button to re-enable\n */\nconst listenForDownloadCookie = (button) => {\n cookieListeningButtons.push(button);\n if (!cookieListener) {\n cookieListener = setInterval(() => {\n // Look for cookie.\n const parts = document.cookie.split(getCookieName() + '=');\n if (parts.length == 2) {\n // We found the cookie, so the file is ready. Expire the cookie and cancel polling.\n clearDownloadCookie();\n clearInterval(cookieListener);\n cookieListener = 0;\n\n // Re-enable all the buttons.\n cookieListeningButtons.forEach((button) => {\n button.disabled = false;\n });\n }\n }, 500);\n }\n};\n\n/**\n * Gets a unique name for the download cookie.\n *\n * @returns {string} Cookie name\n */\nconst getCookieName = () => {\n return 'moodledownload_' + M.cfg.sesskey;\n};\n\n/**\n * Clears the download cookie if there is one.\n */\nconst clearDownloadCookie = () => {\n document.cookie = encodeURIComponent(getCookieName()) + '=deleted; expires=' + new Date(0).toUTCString();\n};\n\n/**\n * Initialises submit buttons.\n *\n * @param {String} elementId Form element\n * @listens event:uploadStarted\n * @listens event:uploadCompleted\n */\nexport const init = (elementId) => {\n const button = document.getElementById(elementId);\n\n // Add event listener for file upload start.\n document.addEventListener(eventTypes.uploadStarted, e => {\n window.console.log(e.target); // This will be the element/section where the file is uploaded to.\n button.disabled = true;\n });\n\n // Add event listener for file upload complete.\n document.addEventListener(eventTypes.uploadCompleted, e => {\n window.console.log(e.target); // This will be the element/section where the file is uploaded to.\n button.disabled = false;\n });\n\n // If the form has double submit protection disabled, do nothing.\n if (button.form.dataset.doubleSubmitProtection === 'off') {\n return;\n }\n button.form.addEventListener('submit', function(event) {\n // Only disable it if the browser is really going to another page as a result of the\n // submit.\n const disableAction = function() {\n // If the submit was cancelled, or the button is already disabled, don't do anything.\n if (event.defaultPrevented || button.disabled) {\n return;\n }\n\n button.disabled = true;\n clearDownloadCookie();\n listenForDownloadCookie(button);\n };\n window.addEventListener('beforeunload', disableAction);\n // If there is no beforeunload event as a result of this form submit, then the form\n // submit must have been cancelled, so don't disable the button if the page is\n // unloaded later.\n setTimeout(function() {\n window.removeEventListener('beforeunload', disableAction);\n }, 0);\n }, false);\n};\n"],"file":"submit.min.js"} \ No newline at end of file +{"version":3,"sources":["../src/submit.js"],"names":["cookieListener","cookieListeningButtons","currentUploadCount","uploadListeningButtons","uploadListenersRegistered","listenForDownloadCookie","button","push","setInterval","parts","document","cookie","split","getCookieName","length","clearDownloadCookie","clearInterval","forEach","disabled","M","cfg","sesskey","encodeURIComponent","Date","toUTCString","checkUploadCount","init","elementId","getElementById","addEventListener","eventTypes","uploadStarted","e","window","console","log","target","uploadCompleted","form","dataset","doubleSubmitProtection","event","disableAction","defaultPrevented","setTimeout","removeEventListener"],"mappings":"uJA4BIA,CAAAA,CAAc,CAAG,C,CAGfC,CAAsB,CAAG,E,CAG3BC,CAAkB,CAAG,C,CAGnBC,CAAsB,CAAG,E,CAG3BC,CAAyB,G,CAavBC,CAAuB,CAAG,SAACC,CAAD,CAAY,CACxCL,CAAsB,CAACM,IAAvB,CAA4BD,CAA5B,EACA,GAAI,CAACN,CAAL,CAAqB,CACjBA,CAAc,CAAGQ,WAAW,CAAC,UAAM,CAE/B,GAAMC,CAAAA,CAAK,CAAGC,QAAQ,CAACC,MAAT,CAAgBC,KAAhB,CAAsBC,CAAa,GAAK,GAAxC,CAAd,CACA,GAAoB,CAAhB,EAAAJ,CAAK,CAACK,MAAV,CAAuB,CAEnBC,CAAmB,GACnBC,aAAa,CAAChB,CAAD,CAAb,CACAA,CAAc,CAAG,CAAjB,CAGAC,CAAsB,CAACgB,OAAvB,CAA+B,SAACX,CAAD,CAAY,CACvCA,CAAM,CAACY,QAAP,GACH,CAFD,CAGH,CACJ,CAd2B,CAczB,GAdyB,CAe/B,CACJ,C,CAOKL,CAAa,CAAG,UAAM,CACxB,MAAO,kBAAoBM,CAAC,CAACC,GAAF,CAAMC,OACpC,C,CAKKN,CAAmB,CAAG,UAAM,CAC9BL,QAAQ,CAACC,MAAT,CAAkBW,kBAAkB,CAACT,CAAa,EAAd,CAAlB,CAAsC,oBAAtC,CAA6D,GAAIU,CAAAA,IAAJ,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CAEDZ,CAAM,CAACY,QAAP,IACAH,CAAmB,GACnBV,CAAuB,CAACC,CAAD,CAC1B,CATD,CAUA2B,MAAM,CAACJ,gBAAP,CAAwB,cAAxB,CAAwCa,CAAxC,EAIAE,UAAU,CAAC,UAAW,CAClBX,MAAM,CAACY,mBAAP,CAA2B,cAA3B,CAA2CH,CAA3C,CACH,CAFS,CAEP,CAFO,CAGb,CApBD,IAqBH,C","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Submit button JavaScript. All submit buttons will be automatically disabled once the form is\n * submitted, unless that submission results in an error/cancelling the submit.\n *\n * @module core_form/submit\n * @copyright 2019 The Open University\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @since 3.8\n */\n\nimport {eventTypes} from 'core_form/events';\n\n/** @property {number} ID for setInterval used when polling for download cookie */\nlet cookieListener = 0;\n\n/** @property {Array} Array of buttons that need re-enabling if we get a download cookie */\nconst cookieListeningButtons = [];\n\n/** @property {number} Number of files uploading. */\nlet currentUploadCount = 0;\n\n/** @property {Array} Array of buttons that need re-enabling if we get a upload process. */\nconst uploadListeningButtons = [];\n\n/** @property {Boolean} Is upload listeners registered? */\nlet uploadListenersRegistered = false;\n\n/**\n * Listens in case a download cookie is provided.\n *\n * This function is used to detect file downloads. If there is a file download then we get a\n * beforeunload event, but the page is never unloaded and when the file download completes we\n * should re-enable the buttons. We detect this by watching for a specific cookie.\n *\n * PHP function \\core_form\\util::form_download_complete() can be used to send this cookie.\n *\n * @param {HTMLElement} button Button to re-enable\n */\nconst listenForDownloadCookie = (button) => {\n cookieListeningButtons.push(button);\n if (!cookieListener) {\n cookieListener = setInterval(() => {\n // Look for cookie.\n const parts = document.cookie.split(getCookieName() + '=');\n if (parts.length == 2) {\n // We found the cookie, so the file is ready. Expire the cookie and cancel polling.\n clearDownloadCookie();\n clearInterval(cookieListener);\n cookieListener = 0;\n\n // Re-enable all the buttons.\n cookieListeningButtons.forEach((button) => {\n button.disabled = false;\n });\n }\n }, 500);\n }\n};\n\n/**\n * Gets a unique name for the download cookie.\n *\n * @returns {string} Cookie name\n */\nconst getCookieName = () => {\n return 'moodledownload_' + M.cfg.sesskey;\n};\n\n/**\n * Clears the download cookie if there is one.\n */\nconst clearDownloadCookie = () => {\n document.cookie = encodeURIComponent(getCookieName()) + '=deleted; expires=' + new Date(0).toUTCString();\n};\n\n/**\n * Enable submit buttons when all files are uploaded.\n */\nconst checkUploadCount = () => {\n if (currentUploadCount) {\n uploadListeningButtons.forEach(button => {\n button.disabled = true;\n });\n } else {\n uploadListeningButtons.forEach(button => {\n button.disabled = false;\n });\n }\n};\n\n/**\n * Initialises submit buttons.\n *\n * @param {String} elementId Form element\n * @listens event:uploadStarted\n * @listens event:uploadCompleted\n */\nexport const init = (elementId) => {\n const button = document.getElementById(elementId);\n // If buttons are disabled by default, we do not enable them when file upload completed event is fired.\n if (!button.disabled) {\n uploadListeningButtons.push(button);\n }\n\n if (!uploadListenersRegistered) {\n // Add event listener for file upload start.\n document.addEventListener(eventTypes.uploadStarted, e => {\n window.console.log(e.target); // This will be the element/section where the file is uploaded to.\n currentUploadCount++;\n checkUploadCount();\n });\n\n // Add event listener for file upload complete.\n document.addEventListener(eventTypes.uploadCompleted, e => {\n window.console.log(e.target); // This will be the element/section where the file is uploaded to.\n currentUploadCount--;\n checkUploadCount();\n });\n uploadListenersRegistered = true;\n }\n\n // If the form has double submit protection disabled, do nothing.\n if (button.form.dataset.doubleSubmitProtection === 'off') {\n return;\n }\n button.form.addEventListener('submit', function(event) {\n // Only disable it if the browser is really going to another page as a result of the\n // submit.\n const disableAction = function() {\n // If the submit was cancelled, or the button is already disabled, don't do anything.\n if (event.defaultPrevented || button.disabled) {\n return;\n }\n\n button.disabled = true;\n clearDownloadCookie();\n listenForDownloadCookie(button);\n };\n window.addEventListener('beforeunload', disableAction);\n // If there is no beforeunload event as a result of this form submit, then the form\n // submit must have been cancelled, so don't disable the button if the page is\n // unloaded later.\n setTimeout(function() {\n window.removeEventListener('beforeunload', disableAction);\n }, 0);\n }, false);\n};\n"],"file":"submit.min.js"} \ No newline at end of file diff --git a/lib/form/amd/src/submit.js b/lib/form/amd/src/submit.js index 2f26fb650fd..64608043866 100644 --- a/lib/form/amd/src/submit.js +++ b/lib/form/amd/src/submit.js @@ -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. * @@ -88,18 +112,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(eventTypes.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(eventTypes.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(eventTypes.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(eventTypes.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') { diff --git a/lib/form/dndupload.js b/lib/form/dndupload.js index d8e8e8721e7..de60baf4ade 100644 --- a/lib/form/dndupload.js +++ b/lib/form/dndupload.js @@ -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); diff --git a/question/bank/previewquestion/preview.php b/question/bank/previewquestion/preview.php index 7ea555c5eac..0342a1c6240 100644 --- a/question/bank/previewquestion/preview.php +++ b/question/bank/previewquestion/preview.php @@ -312,4 +312,8 @@ $event = \core\event\question_viewed::create_from_question_instance($question, $ $event->trigger(); $PAGE->requires->js_call_amd('qbank_previewquestion/preview', 'init', [$previewdata['redirect']]); +$PAGE->requires->js_call_amd('core_form/changechecker', 'watchFormById', ['responseform']); +$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']); echo $OUTPUT->footer(); diff --git a/question/bank/previewquestion/templates/preview_question.mustache b/question/bank/previewquestion/templates/preview_question.mustache index 67c540a8993..6abbf4a2240 100644 --- a/question/bank/previewquestion/templates/preview_question.mustache +++ b/question/bank/previewquestion/templates/preview_question.mustache @@ -57,10 +57,10 @@ {{{question}}}
- - + + - + {{^redirect}} {{/redirect}}