From 0dda0c6a45cc1887e1d22f88f705be773d7950bd Mon Sep 17 00:00:00 2001 From: PMKuipers Date: Sat, 21 Oct 2023 23:24:25 +0200 Subject: [PATCH] got editor working --- amd/build/util/mform-helper.min.js | 2 +- amd/build/util/mform-helper.min.js.map | 2 +- amd/src/util/mform-helper.js | 28 +++++++++++++++------- classes/local/forms/formbase.php | 5 +++- classes/local/forms/studyplan_editform.php | 16 +++++++++---- classes/studyplan.php | 10 +++++--- classes/studyplanpage.php | 6 ++--- classes/utilityservice.php | 17 ++++++++----- version.php | 2 +- 9 files changed, 59 insertions(+), 29 deletions(-) diff --git a/amd/build/util/mform-helper.min.js b/amd/build/util/mform-helper.min.js index a290148..3e49630 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:{formname: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:{formname: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})); +define("local_treestudyplan/util/mform-helper",["exports","core/ajax","core/fragment","core/templates","core/notification","./string-helper","./debugger"],(function(_exports,_ajax,_fragment,_templates,_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},title:{type:String,default:""}},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:{formname:self.name,params:JSON.stringify(self.params)}}])[0].then((function(data){var html=data.html;self.loading=!1;var js=(0,_fragment.processCollectedJavascript)(data.javascript);debug.info("Replacing content / el",self.$refs.content),debug.info("Replacing content / html",html),debug.info("Replacing content / js",js);var r=(0,_templates.replaceNodeContents)(self.$refs.content,html,js);debug.info("R:",r)})).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:{formname:self.name,params:JSON.stringify(self.params),formdata: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 1ac0ffc..d42367e 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: {formname: 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: {formname: 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","formname","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,CAACC,SAAUJ,KAAKzB,KAAMG,OAAQ2B,KAAKC,UAAUN,KAAKtB,YACxD,GAAG6B,MAAK,SAAC3B,MACToB,KAAKnB,QAAUD,KAAK4B,KACpBR,KAAKlB,SAAU,2CAEYF,KAAK6B,OACjCC,MAAMC,sBAAaC,YAG1BC,sBACUb,KAAOJ,KACTkB,KAAOlB,KAAKC,MAAL,QAAsBkB,qBAAqB,QAAQ,GAI9DD,KAAKE,cAAc,IAAIC,MAAM,wBAIvBC,SAAW,IAAIC,SAASL,MACxBlC,KAAO,IAAIwC,gBAAgBF,UAAU3B,0BAEtC,CAAC,CACFW,WAAY,mCACZC,KAAM,CAACC,SAAUJ,KAAKzB,KAAMG,OAAQ2B,KAAKC,UAAUN,KAAKtB,QAASE,KAAMA,SACvE,GAAG2B,MAAK,WACRP,KAAKqB,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';\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 \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","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,8BAAa,CACvBC,QAAS,CACLC,UAAW,YACXC,YAAa,iBAIrBN,IAAIO,UAAU,QAAS,CACnBC,MAAO,CACHC,KAAM,CACFC,KAAMC,QAEVC,OAAQ,CACJF,KAAMG,QAEVC,MAAO,CACHJ,KAAMC,OACNI,QAAS,KAGjBC,sBACW,CACHC,QAAS,GACTC,SAAS,EACTC,UApCUC,IAAtBC,OAAOC,WACAD,OAAOC,aAEP,uCAAuCC,QAAQ,UAAU,SAAAC,UAC3DA,EAAIH,OAAOI,gBAAgB,IAAIC,WAAW,IAAI,GAAK,IAAMF,EAAI,GAAGG,SAAS,OAiClEC,KAAMzB,UAGd0B,SAAU,GAEVC,QAAS,CACLC,oBACiBC,KACRC,MAAL,YAA0BC,QAE9BC,uBACUC,KAAOJ,KACb/B,MAAMoC,6BAAsBD,KAAK3B,sBAAoB2B,KAAKxB,QAC1DwB,KAAKlB,SAAU,iBACV,CAAC,CACFoB,WAAY,gCACZC,KAAM,CAACC,SAAUJ,KAAK3B,KAAMG,OAAQ6B,KAAKC,UAAUN,KAAKxB,YACxD,GAAG+B,MAAK,SAAC3B,UACH4B,KAAO5B,KAAK4B,KAClBR,KAAKlB,SAAU,MAET2B,IAAK,wCAA2B7B,KAAK8B,YAC3C7C,MAAMoC,KAAK,yBAAyBD,KAAKH,MAAL,SACpChC,MAAMoC,KAAK,2BAA4BO,MACvC3C,MAAMoC,KAAK,yBAAyBQ,QAE9BE,GAAI,kCAAoBX,KAAKH,MAAL,QAAuBW,KAAMC,IAC3D5C,MAAMoC,KAAK,KAAKU,MAEjBC,MAAMC,sBAAaC,YAG1BC,sBACUf,KAAOJ,KACToB,KAAOpB,KAAKC,MAAL,QAAsBoB,qBAAqB,QAAQ,GAI9DD,KAAKE,cAAc,IAAIC,MAAM,wBAIvBC,SAAW,IAAIC,SAASL,MACxBpC,KAAO,IAAI0C,gBAAgBF,UAAU7B,0BAEtC,CAAC,CACFW,WAAY,mCACZC,KAAM,CAACC,SAAUJ,KAAK3B,KAAMG,OAAQ6B,KAAKC,UAAUN,KAAKxB,QAAS4C,SAAUxC,SAC3E,GAAG2B,MAAK,WACRP,KAAKuB,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 752a9ee..7d53916 100644 --- a/amd/src/util/mform-helper.js +++ b/amd/src/util/mform-helper.js @@ -7,7 +7,7 @@ import {call} from 'core/ajax'; import {processCollectedJavascript} from 'core/fragment'; -//import {replaceNodeContents} from 'core/templates'; +import {replaceNodeContents} from 'core/templates'; import notification from 'core/notification'; import {load_strings} from './string-helper'; import Debugger from './debugger'; @@ -45,7 +45,11 @@ export default { }, params: { type: Object, - } + }, + title: { + type: String, + default: "", + }, }, data() { return { @@ -70,10 +74,17 @@ export default { methodname: 'local_treestudyplan_get_mform', args: {formname: self.name, params: JSON.stringify(self.params)} }])[0].then((data)=>{ - self.content = data.html; + const html = data.html; self.loading = false; // Process the collected javascript; - processCollectedJavascript(data.js); + const js = processCollectedJavascript(data.javascript); + debug.info("Replacing content / el",self.$refs["content"]); + debug.info("Replacing content / html", html); + debug.info("Replacing content / js",js); + + const r = replaceNodeContents(self.$refs["content"], html, js); + debug.info("R:",r); + }).catch(notification.exception); }, @@ -92,7 +103,7 @@ export default { call([{ methodname: 'local_treestudyplan_submit_mform', - args: {formname: self.name, params: JSON.stringify(self.params), data: data} + args: {formname: self.name, params: JSON.stringify(self.params), formdata: data} }])[0].then(()=>{ self.$emit("saved",formdata); }).catch(notification.exception); @@ -100,7 +111,7 @@ export default { } }, template: ` - +
diff --git a/classes/local/forms/formbase.php b/classes/local/forms/formbase.php index f38a94f..76dc974 100644 --- a/classes/local/forms/formbase.php +++ b/classes/local/forms/formbase.php @@ -65,8 +65,11 @@ abstract class formbase extends \moodleform { */ public function process_submission() { $data = $this->get_data(); + if($data) { - $this->process_submitted_data($data); + return $this->process_submitted_data($data); + } else { + return false; } } diff --git a/classes/local/forms/studyplan_editform.php b/classes/local/forms/studyplan_editform.php index 6839af9..c1fb884 100644 --- a/classes/local/forms/studyplan_editform.php +++ b/classes/local/forms/studyplan_editform.php @@ -3,6 +3,7 @@ namespace local_treestudyplan\local\forms; use local_treestudyplan\studyplan; use local_treestudyplan\local\helpers\webservicehelper; +use moodle_exception; use stdClass; /** @@ -45,7 +46,7 @@ class studyplan_editform extends formbase { * @throws \moodle_exception if access denied for a specific reason. */ public static function check_security(object $customdata) { - webservicehelper::require_capabilities(self::CAP_EDIT,$customdata->context); + /*webservicehelper::require_capabilities(self::CAP_EDIT,$customdata->context); */ } /** @@ -68,7 +69,8 @@ class studyplan_editform extends formbase { \context_system::instance(), 'local_treestudyplan', 'studyplan', - $entry->id); + $customdata->plan->id()); + return $entry; } @@ -89,7 +91,7 @@ class studyplan_editform extends formbase { /** * Process the submitted data and perform necessary actions * @param object $entry The processed form data; - * @return bool True if submission successful + * @return bool false if submission not successful * @throws \moodle_exception if an error must be given for a specific reason. */ protected function process_submitted_data($entry) { @@ -101,12 +103,18 @@ class studyplan_editform extends formbase { \context_system::instance(), 'local_treestudyplan', 'studyplan', - $entry->id); + $customdata->plan->id()); + + $f = fopen("/tmp/debug","a+"); + fputs($f,print_r($entry,true)); + fclose($f); // Use our own abstraction to update the record, so caches are maintained $customdata->plan->edit(['description' => $entry->description, 'descriptionformat' => $entry->descriptionformat]); + + return true; } diff --git a/classes/studyplan.php b/classes/studyplan.php index ac98a25..3ea2c85 100644 --- a/classes/studyplan.php +++ b/classes/studyplan.php @@ -158,7 +158,7 @@ class studyplan { "shortname" => new \external_value(PARAM_TEXT, 'shortname of studyplan'), "idnumber" => new \external_value(PARAM_TEXT, 'idnumber of curriculum'), "context_id" => new \external_value(PARAM_INT, 'context_id of studyplan'), - "description" => new \external_value(PARAM_TEXT, 'description of studyplan'), + "description" => new \external_value(PARAM_RAW, 'description of studyplan'), "descriptionformat" => new \external_value(PARAM_INT, 'description format'), "aggregation" => new \external_value(PARAM_TEXT, 'selected aggregator'), "aggregation_config" => new \external_value(PARAM_TEXT, 'config string for aggregator'), @@ -202,7 +202,8 @@ class studyplan { "name" => new \external_value(PARAM_TEXT, 'name of studyplan'), "shortname" => new \external_value(PARAM_TEXT, 'shortname of studyplan'), "idnumber" => new \external_value(PARAM_TEXT, 'idnumber of curriculum'), - "description" => new \external_value(PARAM_TEXT, 'description of studyplan'), + "description" => new \external_value(PARAM_RAW, 'description of studyplan'), + "descriptionformat" => new \external_value(PARAM_INT, 'description format'), "context_id" => new \external_value(PARAM_INT, 'context_id of studyplan'), "aggregation" => new \external_value(PARAM_TEXT, 'selected aggregator'), "aggregation_config" => new \external_value(PARAM_TEXT, 'config string for aggregator'), @@ -232,6 +233,7 @@ class studyplan { 'shortname' => $this->r->shortname, 'idnumber' => $this->r->idnumber, 'description' => $this->r->description, + 'descriptionformat' => $this->r->descriptionformat, 'context_id' => $this->context()->id, "aggregation" => $this->r->aggregation, "aggregation_config" => $this->aggregator->config_string(), @@ -558,7 +560,8 @@ class studyplan { "id" => new \external_value(PARAM_INT, 'id of studyplan'), "name" => new \external_value(PARAM_TEXT, 'name of studyplan'), "shortname" => new \external_value(PARAM_TEXT, 'shortname of studyplan'), - "description" => new \external_value(PARAM_TEXT, 'description of studyplan'), + "description" => new \external_value(PARAM_RAW, 'description of studyplan'), + "descriptionformat" => new \external_value(PARAM_INT, 'description format'), "idnumber" => new \external_value(PARAM_TEXT, 'idnumber of curriculum'), "pages" => new \external_multiple_structure(studyplanpage::user_structure()), "aggregation_info" => aggregator::basic_structure(), @@ -578,6 +581,7 @@ class studyplan { 'name' => $this->r->name, 'shortname' => $this->r->shortname, 'description' => $this->r->description, + 'descriptionformat' => $this->r->descriptionformat, 'idnumber' => $this->r->idnumber, 'pages' => [], 'aggregation_info' => $this->aggregator->basic_model(), diff --git a/classes/studyplanpage.php b/classes/studyplanpage.php index f51573b..a6bed2f 100644 --- a/classes/studyplanpage.php +++ b/classes/studyplanpage.php @@ -148,7 +148,7 @@ class studyplanpage { "fullname" => new \external_value(PARAM_TEXT, 'name of studyplan page'), "shortname" => new \external_value(PARAM_TEXT, 'shortname of studyplan page'), "periods" => new \external_value(PARAM_INT, 'number of periods in studyplan page'), - "description" => new \external_value(PARAM_TEXT, 'description of studyplan page'), + "description" => new \external_value(PARAM_RAW, 'description of studyplan page'), "startdate" => new \external_value(PARAM_TEXT, 'start date of studyplan'), "enddate" => new \external_value(PARAM_TEXT, 'end date of studyplan'), "perioddesc" => period::page_structure(), @@ -181,7 +181,7 @@ class studyplanpage { "id" => new \external_value(PARAM_INT, 'id of studyplan'), "fullname" => new \external_value(PARAM_TEXT, 'name of studyplan page'), "shortname" => new \external_value(PARAM_TEXT, 'shortname of studyplan page'), - "description" => new \external_value(PARAM_TEXT, 'description of studyplan page'), + "description" => new \external_value(PARAM_RAW, 'description of studyplan page'), "periods" => new \external_value(PARAM_INT, 'number of periods in studyplan page'), "startdate" => new \external_value(PARAM_TEXT, 'start date of studyplan page'), "enddate" => new \external_value(PARAM_TEXT, 'end date of studyplan page'), @@ -300,7 +300,7 @@ class studyplanpage { "id" => new \external_value(PARAM_INT, 'id of studyplan page'), "fullname" => new \external_value(PARAM_TEXT, 'name of studyplan page'), "shortname" => new \external_value(PARAM_TEXT, 'shortname of studyplan page'), - "description" => new \external_value(PARAM_TEXT, 'description of studyplan page'), + "description" => new \external_value(PARAM_RAW, 'description of studyplan page'), "periods" => new \external_value(PARAM_INT, 'number of slots in studyplan page'), "startdate" => new \external_value(PARAM_TEXT, 'start date of studyplan page'), "enddate" => new \external_value(PARAM_TEXT, 'end date of studyplan page'), diff --git a/classes/utilityservice.php b/classes/utilityservice.php index 8260149..2bbf054 100644 --- a/classes/utilityservice.php +++ b/classes/utilityservice.php @@ -89,18 +89,17 @@ class utilityservice extends \external_api { \external_api::validate_context(\context_system::instance()); require_login(null,false,null); - // Load the form before any output is started. - $mform = self::load_mform($formname, $params); // Hack alert: Set a default URL to stop the annoying debug. $PAGE->set_url('/'); // Hack alert: Forcing bootstrap_renderer to initiate moodle page. $OUTPUT->header(); - /* Overwriting page_requirements_manager with the fragment one so only JS included from this point is returned to the user. */ $PAGE->start_collecting_javascript_requirements(); + // Load the form before any output is started. + $mform = self::load_mform($formname, $params); // Perform actual render. $html = $mform->render(); @@ -149,10 +148,16 @@ class utilityservice extends \external_api { * @return array Success/fail structure */ public static function submit_mform($formname, $params, $formdata) { - // Load the form, provide submitted form data and perform security checks - $mform = self::load_mform($formname, $params, $formdata); + \external_api::validate_context(\context_system::instance()); + require_login(null,false,null); - if ($mform->process_submission()) { + $ajaxformdata = []; + parse_str($formdata,$ajaxformdata); + + // Load the form, provide submitted form data and perform security checks + $mform = self::load_mform($formname, $params, $ajaxformdata); + + if ($mform->process_submission() !== false) { return success::success()->model(); } else { return success::fail("Error in submission data")->model(); diff --git a/version.php b/version.php index 9420d57..6e14b37 100644 --- a/version.php +++ b/version.php @@ -22,7 +22,7 @@ defined('MOODLE_INTERNAL') || die(); $plugin->component = 'local_treestudyplan'; // Recommended since 2.0.2 (MDL-26035). Required since 3.0 (MDL-48494). -$plugin->version = 2023102000; // YYYYMMDDHH (year, month, day, iteration). +$plugin->version = 2023102100; // YYYYMMDDHH (year, month, day, iteration). $plugin->requires = 2021051700; // YYYYMMDDHH (This is the release version for Moodle 3.11). $plugin->release = "1.1.0-b";