MDL-74287 forms: request changesmade string as required.

Unconditionally requesting the string was triggering exceptions
during installation, before the required external functions had
been populated.
This commit is contained in:
Paul Holden
2022-06-16 08:07:44 +01:00
parent d1e8870fb5
commit c8aa905ef0
3 changed files with 4 additions and 16 deletions
+1 -10
View File
@@ -1,12 +1,3 @@
define("core_form/events",["exports","core/str"],(function(_exports,_str){
/**
* Contain the events the form component can trigger.
*
* @module core_form/events
* @copyright 2021 Huong Nguyen <huongnv13@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since 3.10
*/
var changesMadeString;Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.types=_exports.triggerUploadStarted=_exports.triggerUploadCompleted=_exports.notifyUploadChanged=void 0,(0,_str.get_string)("changesmadereallygoaway","moodle").then((function(string){return changesMadeString=string,string})).catch();var changesMadeCheck=function(e){e&&(e.returnValue=changesMadeString)},types={uploadStarted:"core_form/uploadStarted",uploadCompleted:"core_form/uploadCompleted",uploadChanged:"core_form/uploadChanged"};_exports.types=types;_exports.triggerUploadStarted=function(elementId){window.addEventListener("beforeunload",changesMadeCheck);var customEvent=new CustomEvent(types.uploadStarted,{bubbles:!0,cancellable:!1});return document.getElementById(elementId).dispatchEvent(customEvent),customEvent};_exports.triggerUploadCompleted=function(elementId){window.removeEventListener("beforeunload",changesMadeCheck);var customEvent=new CustomEvent(types.uploadCompleted,{bubbles:!0,cancellable:!1});return document.getElementById(elementId).dispatchEvent(customEvent),customEvent};_exports.notifyUploadChanged=function(elementId){var customEvent=new CustomEvent(types.uploadChanged,{bubbles:!0,cancellable:!1});return document.getElementById(elementId).dispatchEvent(customEvent),customEvent}}));
define("core_form/events",["exports","core/str"],(function(_exports,_str){function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg),value=info.value}catch(error){return void reject(error)}info.done?resolve(value):Promise.resolve(value).then(_next,_throw)}var changesMadeString;Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.types=_exports.triggerUploadStarted=_exports.triggerUploadCompleted=_exports.notifyUploadChanged=void 0;var changesMadeCheck=function(e){e&&(e.returnValue=changesMadeString)},types={uploadStarted:"core_form/uploadStarted",uploadCompleted:"core_form/uploadCompleted",uploadChanged:"core_form/uploadChanged"};_exports.types=types;var fn,_ref,triggerUploadStarted=(fn=regeneratorRuntime.mark((function _callee(elementId){var customEvent;return regeneratorRuntime.wrap((function(_context){for(;;)switch(_context.prev=_context.next){case 0:return _context.next=2,(0,_str.get_string)("changesmadereallygoaway","moodle");case 2:return changesMadeString=_context.sent,window.addEventListener("beforeunload",changesMadeCheck),customEvent=new CustomEvent(types.uploadStarted,{bubbles:!0,cancellable:!1}),document.getElementById(elementId).dispatchEvent(customEvent),_context.abrupt("return",customEvent);case 8:case"end":return _context.stop()}}),_callee)})),_ref=function(){var self=this,args=arguments;return new Promise((function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value)}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err)}_next(void 0)}))},function(_x){return _ref.apply(this,arguments)});_exports.triggerUploadStarted=triggerUploadStarted;_exports.triggerUploadCompleted=function(elementId){window.removeEventListener("beforeunload",changesMadeCheck);var customEvent=new CustomEvent(types.uploadCompleted,{bubbles:!0,cancellable:!1});return document.getElementById(elementId).dispatchEvent(customEvent),customEvent};_exports.notifyUploadChanged=function(elementId){var customEvent=new CustomEvent(types.uploadChanged,{bubbles:!0,cancellable:!1});return document.getElementById(elementId).dispatchEvent(customEvent),customEvent}}));
//# sourceMappingURL=events.min.js.map
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"events.min.js","sources":["../src/events.js"],"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 <http://www.gnu.org/licenses/>.\n\n/**\n * Contain the events the form component can trigger.\n *\n * @module core_form/events\n * @copyright 2021 Huong Nguyen <[email protected]>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @since 3.10\n */\n\nimport {get_string as getString} from 'core/str';\n\nlet changesMadeString;\ngetString('changesmadereallygoaway', 'moodle').then(string => {\n changesMadeString = string;\n return string;\n}).catch();\n\n/**\n * Prevent user navigate away when upload progress still running.\n * @param {Event} e The event\n */\nconst changesMadeCheck = e => {\n if (e) {\n e.returnValue = changesMadeString;\n }\n};\n\n/**\n * List of the events.\n **/\nexport const types = {\n uploadStarted: 'core_form/uploadStarted',\n uploadCompleted: 'core_form/uploadCompleted',\n uploadChanged: 'core_form/uploadChanged'\n};\n\n/**\n * Trigger upload start event.\n *\n * @param {String} elementId\n * @returns {CustomEvent<unknown>}\n */\nexport const triggerUploadStarted = elementId => {\n // Add an additional check for changes made.\n window.addEventListener('beforeunload', changesMadeCheck);\n const customEvent = new CustomEvent(types.uploadStarted, {\n bubbles: true,\n cancellable: false\n });\n const element = document.getElementById(elementId);\n element.dispatchEvent(customEvent);\n\n return customEvent;\n};\n\n/**\n * Trigger upload complete event.\n *\n * @param {String} elementId\n * @returns {CustomEvent<unknown>}\n */\nexport const triggerUploadCompleted = elementId => {\n // Remove the additional check for changes made.\n window.removeEventListener('beforeunload', changesMadeCheck);\n const customEvent = new CustomEvent(types.uploadCompleted, {\n bubbles: true,\n cancellable: false\n });\n const element = document.getElementById(elementId);\n element.dispatchEvent(customEvent);\n\n return customEvent;\n};\n\n/**\n * Trigger an event to notify the file upload field has been changed.\n *\n * @method\n * @param {String} elementId The element which was changed\n * @returns {CustomEvent}\n */\n export const notifyUploadChanged = elementId => {\n\n const customEvent = new CustomEvent(types.uploadChanged, {\n bubbles: true,\n cancellable: false\n });\n\n const element = document.getElementById(elementId);\n element.dispatchEvent(customEvent);\n\n return customEvent;\n};\n"],"names":["changesMadeString","then","string","catch","changesMadeCheck","e","returnValue","types","uploadStarted","uploadCompleted","uploadChanged","elementId","window","addEventListener","customEvent","CustomEvent","bubbles","cancellable","document","getElementById","dispatchEvent","removeEventListener"],"mappings":";;;;;;;;;IA0BIA,+MACM,0BAA2B,UAAUC,MAAK,SAAAC,eAChDF,kBAAoBE,OACbA,UACRC,YAMGC,iBAAmB,SAAAC,GACjBA,IACAA,EAAEC,YAAcN,oBAOXO,MAAQ,CACjBC,cAAe,0BACfC,gBAAiB,4BACjBC,cAAe,8EASiB,SAAAC,WAEhCC,OAAOC,iBAAiB,eAAgBT,sBAClCU,YAAc,IAAIC,YAAYR,MAAMC,cAAe,CACrDQ,SAAS,EACTC,aAAa,WAEDC,SAASC,eAAeR,WAChCS,cAAcN,aAEfA,6CAS2B,SAAAH,WAElCC,OAAOS,oBAAoB,eAAgBjB,sBACrCU,YAAc,IAAIC,YAAYR,MAAME,gBAAiB,CACvDO,SAAS,EACTC,aAAa,WAEDC,SAASC,eAAeR,WAChCS,cAAcN,aAEfA,0CAUyB,SAAAH,eAE1BG,YAAc,IAAIC,YAAYR,MAAMG,cAAe,CACrDM,SAAS,EACTC,aAAa,WAGDC,SAASC,eAAeR,WAChCS,cAAcN,aAEfA"}
{"version":3,"file":"events.min.js","sources":["../src/events.js"],"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 <http://www.gnu.org/licenses/>.\n\n/**\n * Contain the events the form component can trigger.\n *\n * @module core_form/events\n * @copyright 2021 Huong Nguyen <[email protected]>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @since 3.10\n */\n\nimport {get_string as getString} from 'core/str';\n\nlet changesMadeString;\n\n/**\n * Prevent user navigate away when upload progress still running.\n * @param {Event} e The event\n */\nconst changesMadeCheck = e => {\n if (e) {\n e.returnValue = changesMadeString;\n }\n};\n\n/**\n * List of the events.\n **/\nexport const types = {\n uploadStarted: 'core_form/uploadStarted',\n uploadCompleted: 'core_form/uploadCompleted',\n uploadChanged: 'core_form/uploadChanged'\n};\n\n/**\n * Trigger upload start event.\n *\n * @param {String} elementId\n * @returns {CustomEvent<unknown>}\n */\nexport const triggerUploadStarted = async elementId => {\n // Add an additional check for changes made.\n changesMadeString = await getString('changesmadereallygoaway', 'moodle');\n window.addEventListener('beforeunload', changesMadeCheck);\n const customEvent = new CustomEvent(types.uploadStarted, {\n bubbles: true,\n cancellable: false\n });\n const element = document.getElementById(elementId);\n element.dispatchEvent(customEvent);\n\n return customEvent;\n};\n\n/**\n * Trigger upload complete event.\n *\n * @param {String} elementId\n * @returns {CustomEvent<unknown>}\n */\nexport const triggerUploadCompleted = elementId => {\n // Remove the additional check for changes made.\n window.removeEventListener('beforeunload', changesMadeCheck);\n const customEvent = new CustomEvent(types.uploadCompleted, {\n bubbles: true,\n cancellable: false\n });\n const element = document.getElementById(elementId);\n element.dispatchEvent(customEvent);\n\n return customEvent;\n};\n\n/**\n * Trigger an event to notify the file upload field has been changed.\n *\n * @method\n * @param {String} elementId The element which was changed\n * @returns {CustomEvent}\n */\n export const notifyUploadChanged = elementId => {\n\n const customEvent = new CustomEvent(types.uploadChanged, {\n bubbles: true,\n cancellable: false\n });\n\n const element = document.getElementById(elementId);\n element.dispatchEvent(customEvent);\n\n return customEvent;\n};\n"],"names":["changesMadeString","changesMadeCheck","e","returnValue","types","uploadStarted","uploadCompleted","uploadChanged","triggerUploadStarted","elementId","window","addEventListener","customEvent","CustomEvent","bubbles","cancellable","document","getElementById","dispatchEvent","removeEventListener"],"mappings":"ySA0BIA,+LAMEC,iBAAmB,SAAAC,GACjBA,IACAA,EAAEC,YAAcH,oBAOXI,MAAQ,CACjBC,cAAe,0BACfC,gBAAiB,4BACjBC,cAAe,4DASNC,kDAAuB,iBAAMC,wJAEZ,mBAAU,0BAA2B,wBAA/DT,gCACAU,OAAOC,iBAAiB,eAAgBV,kBAClCW,YAAc,IAAIC,YAAYT,MAAMC,cAAe,CACrDS,SAAS,EACTC,aAAa,IAEDC,SAASC,eAAeR,WAChCS,cAAcN,sCAEfA,4fAS2B,SAAAH,WAElCC,OAAOS,oBAAoB,eAAgBlB,sBACrCW,YAAc,IAAIC,YAAYT,MAAME,gBAAiB,CACvDQ,SAAS,EACTC,aAAa,WAEDC,SAASC,eAAeR,WAChCS,cAAcN,aAEfA,0CAUyB,SAAAH,eAE1BG,YAAc,IAAIC,YAAYT,MAAMG,cAAe,CACrDO,SAAS,EACTC,aAAa,WAGDC,SAASC,eAAeR,WAChCS,cAAcN,aAEfA"}
+2 -5
View File
@@ -25,10 +25,6 @@
import {get_string as getString} from 'core/str';
let changesMadeString;
getString('changesmadereallygoaway', 'moodle').then(string => {
changesMadeString = string;
return string;
}).catch();
/**
* Prevent user navigate away when upload progress still running.
@@ -55,8 +51,9 @@ export const types = {
* @param {String} elementId
* @returns {CustomEvent<unknown>}
*/
export const triggerUploadStarted = elementId => {
export const triggerUploadStarted = async elementId => {
// Add an additional check for changes made.
changesMadeString = await getString('changesmadereallygoaway', 'moodle');
window.addEventListener('beforeunload', changesMadeCheck);
const customEvent = new CustomEvent(types.uploadStarted, {
bubbles: true,