From d4e4a8fca9c2731035f00e476376d64709617d48 Mon Sep 17 00:00:00 2001 From: PMKuipers Date: Thu, 19 Oct 2023 17:38:16 +0200 Subject: [PATCH] Minor fix in mfom helper javascript --- amd/build/util/mform-helper.min.js | 2 +- amd/build/util/mform-helper.min.js.map | 2 +- amd/src/util/mform-helper.js | 13 +++---------- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/amd/build/util/mform-helper.min.js b/amd/build/util/mform-helper.min.js index a33841d..e11be9f 100644 --- a/amd/build/util/mform-helper.min.js +++ b/amd/build/util/mform-helper.min.js @@ -1,3 +1,3 @@ -define("local_treestudyplan/util/mform-helper",["exports","core/ajax","core/fragment","core/notification","./string-helper","./debugger"],(function(_exports,_ajax,_fragment,_notification,_stringHelper,_debugger){function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_notification=_interopRequireDefault(_notification),_debugger=_interopRequireDefault(_debugger);var _default={install:function(Vue){var debug=new _debugger.default("treestudyplan-mform-helper"),strings=(0,_stringHelper.load_strings)({editmod:{save$core:"save$core",cancel$core:"cancel$core"}});Vue.component("mform",{props:{name:{type:String},params:{type:Object}},data:function(){return{content:"",loading:!0,uuid:void 0!==crypto.randomUUID?crypto.randomUUID():"10000000-1000-4000-8000-100000000000".replace(/[018]/g,(function(c){return(c^crypto.getRandomValues(new Uint8Array(1))[0]&15>>c/4).toString(16)})),text:strings}},computed:{},methods:{openForm:function(){this.$refs.editormodal.show()},onShown:function(){var self=this;debug.info('Loading form "'.concat(self.name,'" with params'),self.params),self.loading=!1,(0,_ajax.call)([{methodname:"local_treestudyplan_get_mform",args:{name:self.name,params:self.params}}])[0].then((function(data){self.content=data.html,self.loading=!1,(0,_fragment.processCollectedJavascript)(data.js)})).catch(_notification.default.exception)},onSave:function(){var self=this,form=this.$refs.content.getElementsByTagName("form")[0];form.dispatchEvent(new Event("save-form-state"));var formdata=new FormData(form),data=new URLSearchParams(formdata).toString();(0,_ajax.call)([{methodname:"local_treestudyplan_submit_mform",args:{name:self.name,params:self.params,data:data}}])[0].then((function(){self.$emit("saved",formdata)})).catch(_notification.default.exception)}},template:'\n \n
\n \n '})}};return _exports.default=_default,_exports.default})); +define("local_treestudyplan/util/mform-helper",["exports","core/ajax","core/fragment","core/notification","./string-helper","./debugger"],(function(_exports,_ajax,_fragment,_notification,_stringHelper,_debugger){function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_notification=_interopRequireDefault(_notification),_debugger=_interopRequireDefault(_debugger);var _default={install:function(Vue){var debug=new _debugger.default("treestudyplan-mform-helper"),strings=(0,_stringHelper.load_strings)({editmod:{save$core:"save$core",cancel$core:"cancel$core"}});Vue.component("mform",{props:{name:{type:String},params:{type:Object}},data:function(){return{content:"",loading:!0,uuid:void 0!==crypto.randomUUID?crypto.randomUUID():"10000000-1000-4000-8000-100000000000".replace(/[018]/g,(function(c){return(c^crypto.getRandomValues(new Uint8Array(1))[0]&15>>c/4).toString(16)})),text:strings}},computed:{},methods:{openForm:function(){this.$refs.editormodal.show()},onShown:function(){var self=this;debug.info('Loading form "'.concat(self.name,'" with params'),self.params),self.loading=!1,(0,_ajax.call)([{methodname:"local_treestudyplan_get_mform",args:{name:self.name,params:JSON.stringify(self.params)}}])[0].then((function(data){self.content=data.html,self.loading=!1,(0,_fragment.processCollectedJavascript)(data.js)})).catch(_notification.default.exception)},onSave:function(){var self=this,form=this.$refs.content.getElementsByTagName("form")[0];form.dispatchEvent(new Event("save-form-state"));var formdata=new FormData(form),data=new URLSearchParams(formdata).toString();(0,_ajax.call)([{methodname:"local_treestudyplan_submit_mform",args:{name:self.name,params:JSON.stringify(self.params),data:data}}])[0].then((function(){self.$emit("saved",formdata)})).catch(_notification.default.exception)}},template:'\n \n
\n \n '})}};return _exports.default=_default,_exports.default})); //# sourceMappingURL=mform-helper.min.js.map \ No newline at end of file diff --git a/amd/build/util/mform-helper.min.js.map b/amd/build/util/mform-helper.min.js.map index 8bbc41d..5d7c691 100644 --- a/amd/build/util/mform-helper.min.js.map +++ b/amd/build/util/mform-helper.min.js.map @@ -1 +1 @@ -{"version":3,"file":"mform-helper.min.js","sources":["../../src/util/mform-helper.js"],"sourcesContent":["/*eslint no-var: \"error\"*/\n/*eslint no-console: \"off\"*/\n/*eslint no-bitwise: \"off\"*/\n/*eslint-disable no-trailing-spaces*/\n/*eslint-env es6*/\n// Put this file in path/to/plugin/amd/src\n\nimport {call} from 'core/ajax';\nimport {processCollectedJavascript} from 'core/fragment';\n//import {replaceNodeContents} from 'core/templates';\nimport notification from 'core/notification';\nimport {load_strings} from './string-helper';\nimport Debugger from './debugger';\n//import {markFormSubmitted} from 'core_form/changechecker'; // Moodle 4.00+ only\n//import {notifyFormSubmittedByJavascript} from 'core_form/events'; // Moodle 4.00+ only\n\n/**\n * Create a random UUID in both secure and insecure contexts\n * @returns UUID\n */\nfunction create_uuid() {\n if (crypto.randomUUID !== undefined ) {\n return crypto.randomUUID();\n } else {\n return \"10000000-1000-4000-8000-100000000000\".replace(/[018]/g, c =>\n (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)\n );\n }\n}\n\nexport default {\n install(Vue/*,options*/){\n let debug = new Debugger(\"treestudyplan-mform-helper\");\n let strings = load_strings({\n editmod: {\n save$core: \"save$core\",\n cancel$core: \"cancel$core\",\n }\n });\n\n Vue.component('mform', {\n props: {\n name: {\n type: String,\n },\n params: {\n type: Object,\n }\n },\n data() {\n return {\n content: \"\",\n loading: true,\n uuid: create_uuid(),\n text: strings,\n };\n },\n computed: {\n },\n methods: {\n openForm(){\n const self = this;\n self.$refs[\"editormodal\"].show();\n },\n onShown(){\n const self = this;\n debug.info(`Loading form \"${self.name}\" with params`,self.params);\n self.loading = false;\n call([{\n methodname: 'local_treestudyplan_get_mform',\n args: {name: self.name, params: self.params}\n }])[0].then((data)=>{\n self.content = data.html;\n self.loading = false;\n // Process the collected javascript;\n processCollectedJavascript(data.js);\n }).catch(notification.exception);\n\n //loadFragment('local_treestudyplan', 'mod_edit_form', this.coursectxid, params).then((html,js) =>{\n // replaceNodeContents(self.$refs[\"content\"], html, js);\n //}).catch(notification.exception);\n\n },\n onSave(){\n const self = this;\n let form = this.$refs[\"content\"].getElementsByTagName(\"form\")[0];\n\n // markFormSubmitted(form); // Moodle 4.00+ only\n // We call this, so other modules can update the form with the latest state.\n form.dispatchEvent(new Event(\"save-form-state\"));\n // Tell all form fields we are about to submit the form.\n // notifyFormSubmittedByJavascript(form); // Moodle 4.00+ only\n\n const formdata = new FormData(form);\n const data =new URLSearchParams(formdata).toString();\n //const formdata = new FormData(form);\n //const data = {};\n //formdata.forEach((value, key) => (data[key] = value));\n\n call([{\n methodname: 'local_treestudyplan_submit_mform',\n args: {name: self.name, params: self.params, data: data}\n }])[0].then(()=>{\n self.$emit(\"saved\",formdata);\n }).catch(notification.exception);\n\n }\n },\n template: `\n \n
\n \n `,\n });\n }\n};\n\n"],"names":["install","Vue","debug","Debugger","strings","editmod","save$core","cancel$core","component","props","name","type","String","params","Object","data","content","loading","uuid","undefined","crypto","randomUUID","replace","c","getRandomValues","Uint8Array","toString","text","computed","methods","openForm","this","$refs","show","onShown","self","info","methodname","args","then","html","js","catch","notification","exception","onSave","form","getElementsByTagName","dispatchEvent","Event","formdata","FormData","URLSearchParams","$emit","template"],"mappings":"meA8Be,CACXA,iBAAQC,SACAC,MAAQ,IAAIC,kBAAS,8BACrBC,SAAU,8BAAa,CACvBC,QAAS,CACLC,UAAW,YACXC,YAAa,iBAIrBN,IAAIO,UAAU,QAAS,CACnBC,MAAO,CACHC,KAAM,CACFC,KAAMC,QAEVC,OAAQ,CACJF,KAAMG,SAGdC,sBACW,CACHC,QAAS,GACTC,SAAS,EACTC,UAhCUC,IAAtBC,OAAOC,WACAD,OAAOC,aAEP,uCAAuCC,QAAQ,UAAU,SAAAC,UAC3DA,EAAIH,OAAOI,gBAAgB,IAAIC,WAAW,IAAI,GAAK,IAAMF,EAAI,GAAGG,SAAS,OA6BlEC,KAAMvB,UAGdwB,SAAU,GAEVC,QAAS,CACLC,oBACiBC,KACRC,MAAL,YAA0BC,QAE9BC,uBACUC,KAAOJ,KACb7B,MAAMkC,6BAAsBD,KAAKzB,sBAAoByB,KAAKtB,QAC1DsB,KAAKlB,SAAU,iBACV,CAAC,CACFoB,WAAY,gCACZC,KAAM,CAAC5B,KAAMyB,KAAKzB,KAAMG,OAAQsB,KAAKtB,WACrC,GAAG0B,MAAK,SAACxB,MACToB,KAAKnB,QAAUD,KAAKyB,KACpBL,KAAKlB,SAAU,2CAEYF,KAAK0B,OACjCC,MAAMC,sBAAaC,YAO1BC,sBACUV,KAAOJ,KACTe,KAAOf,KAAKC,MAAL,QAAsBe,qBAAqB,QAAQ,GAI9DD,KAAKE,cAAc,IAAIC,MAAM,wBAIvBC,SAAW,IAAIC,SAASL,MACxB/B,KAAM,IAAIqC,gBAAgBF,UAAUxB,0BAKrC,CAAC,CACFW,WAAY,mCACZC,KAAM,CAAC5B,KAAMyB,KAAKzB,KAAMG,OAAQsB,KAAKtB,OAAQE,KAAMA,SACnD,GAAGwB,MAAK,WACRJ,KAAKkB,MAAM,QAAQH,aACpBR,MAAMC,sBAAaC,aAI9BU"} \ No newline at end of file +{"version":3,"file":"mform-helper.min.js","sources":["../../src/util/mform-helper.js"],"sourcesContent":["/*eslint no-var: \"error\"*/\n/*eslint no-console: \"off\"*/\n/*eslint no-bitwise: \"off\"*/\n/*eslint-disable no-trailing-spaces*/\n/*eslint-env es6*/\n// Put this file in path/to/plugin/amd/src\n\nimport {call} from 'core/ajax';\nimport {processCollectedJavascript} from 'core/fragment';\n//import {replaceNodeContents} from 'core/templates';\nimport notification from 'core/notification';\nimport {load_strings} from './string-helper';\nimport Debugger from './debugger';\n//import {markFormSubmitted} from 'core_form/changechecker'; // Moodle 4.00+ only\n//import {notifyFormSubmittedByJavascript} from 'core_form/events'; // Moodle 4.00+ only\n\n/**\n * Create a random UUID in both secure and insecure contexts\n * @returns UUID\n */\nfunction create_uuid() {\n if (crypto.randomUUID !== undefined ) {\n return crypto.randomUUID();\n } else {\n return \"10000000-1000-4000-8000-100000000000\".replace(/[018]/g, c =>\n (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)\n );\n }\n}\n\nexport default {\n install(Vue/*,options*/){\n let debug = new Debugger(\"treestudyplan-mform-helper\");\n let strings = load_strings({\n editmod: {\n save$core: \"save$core\",\n cancel$core: \"cancel$core\",\n }\n });\n\n Vue.component('mform', {\n props: {\n name: {\n type: String,\n },\n params: {\n type: Object,\n }\n },\n data() {\n return {\n content: \"\",\n loading: true,\n uuid: create_uuid(),\n text: strings,\n };\n },\n computed: {\n },\n methods: {\n openForm(){\n const self = this;\n self.$refs[\"editormodal\"].show();\n },\n onShown(){\n const self = this;\n debug.info(`Loading form \"${self.name}\" with params`,self.params);\n self.loading = false;\n call([{\n methodname: 'local_treestudyplan_get_mform',\n args: {name: self.name, params: JSON.stringify(self.params)}\n }])[0].then((data)=>{\n self.content = data.html;\n self.loading = false;\n // Process the collected javascript;\n processCollectedJavascript(data.js);\n }).catch(notification.exception);\n\n },\n onSave(){\n const self = this;\n let form = this.$refs[\"content\"].getElementsByTagName(\"form\")[0];\n\n // markFormSubmitted(form); // Moodle 4.00+ only\n // We call this, so other modules can update the form with the latest state.\n form.dispatchEvent(new Event(\"save-form-state\"));\n // Tell all form fields we are about to submit the form.\n // notifyFormSubmittedByJavascript(form); // Moodle 4.00+ only\n\n const formdata = new FormData(form);\n const data = new URLSearchParams(formdata).toString();\n\n call([{\n methodname: 'local_treestudyplan_submit_mform',\n args: {name: self.name, params: JSON.stringify(self.params), data: data}\n }])[0].then(()=>{\n self.$emit(\"saved\",formdata);\n }).catch(notification.exception);\n\n }\n },\n template: `\n \n
\n \n `,\n });\n }\n};\n\n"],"names":["install","Vue","debug","Debugger","strings","editmod","save$core","cancel$core","component","props","name","type","String","params","Object","data","content","loading","uuid","undefined","crypto","randomUUID","replace","c","getRandomValues","Uint8Array","toString","text","computed","methods","openForm","this","$refs","show","onShown","self","info","methodname","args","JSON","stringify","then","html","js","catch","notification","exception","onSave","form","getElementsByTagName","dispatchEvent","Event","formdata","FormData","URLSearchParams","$emit","template"],"mappings":"meA8Be,CACXA,iBAAQC,SACAC,MAAQ,IAAIC,kBAAS,8BACrBC,SAAU,8BAAa,CACvBC,QAAS,CACLC,UAAW,YACXC,YAAa,iBAIrBN,IAAIO,UAAU,QAAS,CACnBC,MAAO,CACHC,KAAM,CACFC,KAAMC,QAEVC,OAAQ,CACJF,KAAMG,SAGdC,sBACW,CACHC,QAAS,GACTC,SAAS,EACTC,UAhCUC,IAAtBC,OAAOC,WACAD,OAAOC,aAEP,uCAAuCC,QAAQ,UAAU,SAAAC,UAC3DA,EAAIH,OAAOI,gBAAgB,IAAIC,WAAW,IAAI,GAAK,IAAMF,EAAI,GAAGG,SAAS,OA6BlEC,KAAMvB,UAGdwB,SAAU,GAEVC,QAAS,CACLC,oBACiBC,KACRC,MAAL,YAA0BC,QAE9BC,uBACUC,KAAOJ,KACb7B,MAAMkC,6BAAsBD,KAAKzB,sBAAoByB,KAAKtB,QAC1DsB,KAAKlB,SAAU,iBACV,CAAC,CACFoB,WAAY,gCACZC,KAAM,CAAC5B,KAAMyB,KAAKzB,KAAMG,OAAQ0B,KAAKC,UAAUL,KAAKtB,YACpD,GAAG4B,MAAK,SAAC1B,MACToB,KAAKnB,QAAUD,KAAK2B,KACpBP,KAAKlB,SAAU,2CAEYF,KAAK4B,OACjCC,MAAMC,sBAAaC,YAG1BC,sBACUZ,KAAOJ,KACTiB,KAAOjB,KAAKC,MAAL,QAAsBiB,qBAAqB,QAAQ,GAI9DD,KAAKE,cAAc,IAAIC,MAAM,wBAIvBC,SAAW,IAAIC,SAASL,MACxBjC,KAAO,IAAIuC,gBAAgBF,UAAU1B,0BAEtC,CAAC,CACFW,WAAY,mCACZC,KAAM,CAAC5B,KAAMyB,KAAKzB,KAAMG,OAAQ0B,KAAKC,UAAUL,KAAKtB,QAASE,KAAMA,SACnE,GAAG0B,MAAK,WACRN,KAAKoB,MAAM,QAAQH,aACpBR,MAAMC,sBAAaC,aAI9BU"} \ No newline at end of file diff --git a/amd/src/util/mform-helper.js b/amd/src/util/mform-helper.js index cf7abe3..6d2c011 100644 --- a/amd/src/util/mform-helper.js +++ b/amd/src/util/mform-helper.js @@ -68,7 +68,7 @@ export default { self.loading = false; call([{ methodname: 'local_treestudyplan_get_mform', - args: {name: self.name, params: self.params} + args: {name: self.name, params: JSON.stringify(self.params)} }])[0].then((data)=>{ self.content = data.html; self.loading = false; @@ -76,10 +76,6 @@ export default { processCollectedJavascript(data.js); }).catch(notification.exception); - //loadFragment('local_treestudyplan', 'mod_edit_form', this.coursectxid, params).then((html,js) =>{ - // replaceNodeContents(self.$refs["content"], html, js); - //}).catch(notification.exception); - }, onSave(){ const self = this; @@ -92,14 +88,11 @@ export default { // notifyFormSubmittedByJavascript(form); // Moodle 4.00+ only const formdata = new FormData(form); - const data =new URLSearchParams(formdata).toString(); - //const formdata = new FormData(form); - //const data = {}; - //formdata.forEach((value, key) => (data[key] = value)); + const data = new URLSearchParams(formdata).toString(); call([{ methodname: 'local_treestudyplan_submit_mform', - args: {name: self.name, params: self.params, data: data} + args: {name: self.name, params: JSON.stringify(self.params), data: data} }])[0].then(()=>{ self.$emit("saved",formdata); }).catch(notification.exception);