moodle_local_treestudyplan/amd/build/util/mform-helper.min.js.map
2024-06-05 22:32:18 +02:00

1 line
11 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 camelcase: \"off\" */\n/* eslint capitalized-comments: \"off\" */\n/* eslint-env es6 */\n\nimport {call} from 'core/ajax';\nimport {processCollectedJavascript} from 'core/fragment';\nimport {replaceNodeContents} from 'core/templates';\nimport notification from 'core/notification';\nimport {loadStrings} 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/* Moodle 3.11 safe import for when needed\nlet markFormSubmitted = () => {};\nlet notifyFormSubmittedByJavascript = () => {};\n\nimport('core_form/changechecker').then((ns) => {\n debug.info(ns);\n if(ns.markFormSubmitted) {\n markFormSubmitted = ns.markFormSubmitted;\n }\n if(ns.notifyFormSubmittedByJavascript) {\n notifyFormSubmittedByJavascript = ns.notifyFormSubmittedByJavascript;\n }\n}).catch(()=>{});\n*/\n\n/**\n * Create a random UUID in both secure and insecure contexts\n * @returns {String} 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 = loadStrings({\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 variant: {\n type: String,\n 'default': \"primary\",\n },\n type: {\n type: String,\n 'default': \"link\",\n }\n },\n data() {\n return {\n content: \"\",\n loading: true,\n uuid: create_uuid(),\n text: strings,\n submitok: false,\n observer: null,\n inputs: [],\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 replaceNodeContents(self.$refs.content, html, js);\n self.initListenChanges();\n return;\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 if (this.checkSave()) {\n call([{\n methodname: 'local_treestudyplan_submit_mform',\n args: {formname: self.name, params: JSON.stringify(self.params), formdata: data}\n }])[0].then((response) => {\n const updatedplan = JSON.parse(response.data);\n self.$emit(\"saved\", updatedplan, formdata);\n return;\n }).catch(notification.exception);\n }\n /* No error if we cannot save, since it would just be to handle the edge case \n where someone clicks on the save button before\n an invalid input got a chance to update. */\n },\n checkSave() {\n let canSave = true;\n this.inputs.forEach(el => {\n el.focus();\n el.blur();\n if (el.classList.contains(\"is-invalid\")) {\n canSave = false;\n }\n }, this);\n this.submitok = canSave;\n return canSave;\n },\n initListenChanges() {\n const content = this.$refs.content;\n this.inputs = content.querySelectorAll(\"input.form-control\");\n\n // Check if save needs to be blocked immediately. (delay call by a few ms)\n setTimeout(this.checkSave, 100);\n\n // Disconnect any existing observer.\n if (this.observer) {\n this.observer.disconnect();\n }\n // Initialize new observer and callback.\n this.observer = new MutationObserver((mutationList) => {\n for (const mix in mutationList) {\n const mutation = mutationList[mix];\n if (mutation.type === 'attributes' && mutation.attributeName === 'class') {\n this.checkSave();\n }\n }\n });\n\n // Connect the observer to the form inputs.\n this.inputs.forEach(el => {\n this.observer.observe(el, {attributes: true});\n }, this);\n\n \n },\n \n },\n unmount() {\n if (this.observer) {\n this.observer.disconnect();\n }\n },\n template: `\n <span class='mform-container'>\n <b-button :variant=\"variant\" v-if='type == \"button\"' @click.prevent='openForm'\n ><slot><i class='fa fa-gear'></i></slot></b-button>\n <a variant=\"variant\" v-else href='#' @click.prevent='openForm'\n ><slot><i class='fa fa-gear'></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 :ok-disabled=\"!submitok\"\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","variant","data","content","loading","uuid","undefined","crypto","randomUUID","replace","c","getRandomValues","Uint8Array","toString","text","submitok","observer","inputs","computed","methods","openForm","this","$refs","editormodal","show","onShown","self","info","methodname","args","formname","JSON","stringify","then","html","js","javascript","initListenChanges","catch","notification","exception","onSave","form","getElementsByTagName","dispatchEvent","Event","formdata","FormData","URLSearchParams","checkSave","response","updatedplan","parse","$emit","canSave","forEach","el","focus","blur","classList","contains","querySelectorAll","setTimeout","disconnect","MutationObserver","mutationList","mix","mutation","attributeName","observe","attributes","unmount","template"],"mappings":"+fA8Ce,CACXA,QAAQC,SACAC,MAAQ,IAAIC,kBAAS,8BACrBC,SAA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