Merge branch 'MDL-71750-master' of https://github.com/NashTechOpenUniversity/moodle
This commit is contained in:
Vendored
+1
-1
@@ -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
|
||||
|
||||
File diff suppressed because one or more lines are too long
+43
-10
@@ -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') {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -57,10 +57,10 @@
|
||||
</div>
|
||||
{{{question}}}
|
||||
<div id="previewcontrols" class="controls input-group">
|
||||
<input type="submit" name="restart" value="{{#str}} restart, question{{/str}}" class="btn btn-secondary mr-1 mb-1" {{{restartdisabled}}}>
|
||||
<input type="submit" name="save" value="{{#str}} save, question{{/str}}" class="btn btn-secondary mr-1 mb-1" {{{finishdisabled}}}>
|
||||
<input type="submit" name="restart" value="{{#str}} restart, question{{/str}}" class="btn btn-secondary mr-1 mb-1" id="id_restart_question_preview" {{{restartdisabled}}}>
|
||||
<input type="submit" name="save" value="{{#str}} save, question{{/str}}" class="btn btn-secondary mr-1 mb-1" id="id_save_question_preview" {{{finishdisabled}}}>
|
||||
<input type="submit" name="fill" value="{{#str}} fillincorrect, question{{/str}}" class="btn btn-secondary mr-1 mb-1" {{{filldisabled}}}>
|
||||
<input type="submit" name="finish" value="{{#str}} submitandfinish, question{{/str}}" class="btn btn-secondary mr-1 mb-1" {{{finishdisabled}}}>
|
||||
<input type="submit" name="finish" value="{{#str}} submitandfinish, question{{/str}}" class="btn btn-secondary mr-1 mb-1" id="id_finish_question_preview" {{{finishdisabled}}}>
|
||||
{{^redirect}}
|
||||
<input type="button" name="close" value="{{#str}} closepreview, question{{/str}}" class="btn btn-secondary mr-1 mb-1" id="close-previewquestion-page">
|
||||
{{/redirect}}
|
||||
|
||||
Reference in New Issue
Block a user