1 line
7.1 KiB
Plaintext
1 line
7.1 KiB
Plaintext
{"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';\nimport {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 title: {\n type: String,\n default: \"\",\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: {formname: self.name, params: JSON.stringify(self.params)}\n }])[0].then((data)=>{\n const html = data.html;\n self.loading = false;\n // Process the collected javascript;\n const js = processCollectedJavascript(data.javascript);\n debug.info(\"Replacing content / el\",self.$refs[\"content\"]);\n debug.info(\"Replacing content / html\", html);\n debug.info(\"Replacing content / js\",js);\n\n const r = replaceNodeContents(self.$refs[\"content\"], html, js);\n debug.info(\"R:\",r);\n \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: {formname: self.name, params: JSON.stringify(self.params), formdata: data}\n }])[0].then(()=>{\n self.$emit(\"saved\",formdata);\n }).catch(notification.exception);\n\n }\n },\n template: `\n <span class='mform-container'><a href='#' @click.prevent=\"openForm\"><slot><i class=\"fa fa-cog\"></i></slot></a>\n <b-modal\n ref=\"editormodal\"\n scrollable\n centered\n size=\"xl\"\n id=\"'modal-'+uuid\"\n @shown=\"onShown\"\n @ok=\"onSave\"\n :title=\"title\"\n :ok-title=\"text.save$core\"\n ><div :class=\"'s-mform-content'\" ref=\"content\"\n ><div class=\"d-flex justify-content-center mb-3\"\n ><b-spinner variant=\"primary\"></b-spinner\n ></div\n ></div\n ></b-modal>\n </span>\n `,\n });\n }\n};\n\n"],"names":["install","Vue","debug","Debugger","strings","editmod","save$core","cancel$core","component","props","name","type","String","params","Object","title","default","data","content","loading","uuid","undefined","crypto","randomUUID","replace","c","getRandomValues","Uint8Array","toString","text","computed","methods","openForm","this","$refs","show","onShown","self","info","methodname","args","formname","JSON","stringify","then","html","js","javascript","r","catch","notification","exception","onSave","form","getElementsByTagName","dispatchEvent","Event","formdata","FormData","URLSearchParams","$emit","template"],"mappings":"+fA8Be,CACXA,iBAAQC,SACAC,MAAQ,IAAIC,kBAAS,8BACrBC,SAAU,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