Bugfixes and learning things
This commit is contained in:
parent
abb74795ca
commit
602bb6e0b3
9 changed files with 29 additions and 19 deletions
2
amd/build/studyplan-editor-components.min.js
vendored
2
amd/build/studyplan-editor-components.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
2
amd/build/util/mform-helper.min.js
vendored
2
amd/build/util/mform-helper.min.js
vendored
|
@ -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: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 <span class=\'s-edit-mod\'><a href=\'#\' @click.prevent="open"><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-edit-mod-form \'+ (genericonly?\'genericonly\':\'\')" ref="content"\n ><div v-if="loading" class="d-flex justify-content-center mb-3"\n ><b-spinner variant="primary"></b-spinner\n ></div\n ><span v-else v-html="content"\n ></div\n ></b-modal>\n </span>\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:{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 <span class=\'s-edit-mod\'><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-edit-mod-form \'" ref="content"\n ><div v-if="loading" class="d-flex justify-content-center mb-3"\n ><b-spinner variant="primary"></b-spinner\n ></div\n ><span v-else v-html="content"\n ></div\n ></b-modal>\n </span>\n '})}};return _exports.default=_default,_exports.default}));
|
||||||
|
|
||||||
//# sourceMappingURL=mform-helper.min.js.map
|
//# sourceMappingURL=mform-helper.min.js.map
|
File diff suppressed because one or more lines are too long
|
@ -18,6 +18,7 @@ import {download,upload} from './downloader';
|
||||||
import {ProcessStudyplan} from './studyplan-processor';
|
import {ProcessStudyplan} from './studyplan-processor';
|
||||||
|
|
||||||
import TSComponents from './treestudyplan-components';
|
import TSComponents from './treestudyplan-components';
|
||||||
|
import mFormComponents from "./util/mform-helper";
|
||||||
|
|
||||||
|
|
||||||
const STUDYPLAN_EDITOR_FIELDS =
|
const STUDYPLAN_EDITOR_FIELDS =
|
||||||
|
@ -39,6 +40,7 @@ export default {
|
||||||
STUDYPLAN_EDITOR_FIELDS: STUDYPLAN_EDITOR_FIELDS, // make copy available in plugin
|
STUDYPLAN_EDITOR_FIELDS: STUDYPLAN_EDITOR_FIELDS, // make copy available in plugin
|
||||||
install(Vue/*,options*/){
|
install(Vue/*,options*/){
|
||||||
Vue.use(TSComponents);
|
Vue.use(TSComponents);
|
||||||
|
Vue.use(mFormComponents);
|
||||||
let debug = new Debugger("treestudyplan-editor");
|
let debug = new Debugger("treestudyplan-editor");
|
||||||
|
|
||||||
/************************************
|
/************************************
|
||||||
|
|
|
@ -68,7 +68,7 @@ export default {
|
||||||
self.loading = false;
|
self.loading = false;
|
||||||
call([{
|
call([{
|
||||||
methodname: 'local_treestudyplan_get_mform',
|
methodname: 'local_treestudyplan_get_mform',
|
||||||
args: {name: self.name, params: JSON.stringify(self.params)}
|
args: {formname: self.name, params: JSON.stringify(self.params)}
|
||||||
}])[0].then((data)=>{
|
}])[0].then((data)=>{
|
||||||
self.content = data.html;
|
self.content = data.html;
|
||||||
self.loading = false;
|
self.loading = false;
|
||||||
|
@ -92,7 +92,7 @@ export default {
|
||||||
|
|
||||||
call([{
|
call([{
|
||||||
methodname: 'local_treestudyplan_submit_mform',
|
methodname: 'local_treestudyplan_submit_mform',
|
||||||
args: {name: self.name, params: JSON.stringify(self.params), data: data}
|
args: {formname: self.name, params: JSON.stringify(self.params), data: data}
|
||||||
}])[0].then(()=>{
|
}])[0].then(()=>{
|
||||||
self.$emit("saved",formdata);
|
self.$emit("saved",formdata);
|
||||||
}).catch(notification.exception);
|
}).catch(notification.exception);
|
||||||
|
@ -100,7 +100,7 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
template: `
|
template: `
|
||||||
<span class='s-edit-mod'><a href='#' @click.prevent="open"><slot><i class="fa fa-cog"></i></slot></a>
|
<span class='s-edit-mod'><a href='#' @click.prevent="openForm"><slot><i class="fa fa-cog"></i></slot></a>
|
||||||
<b-modal
|
<b-modal
|
||||||
ref="editormodal"
|
ref="editormodal"
|
||||||
scrollable
|
scrollable
|
||||||
|
@ -111,7 +111,7 @@ export default {
|
||||||
@ok="onSave"
|
@ok="onSave"
|
||||||
:title="title"
|
:title="title"
|
||||||
:ok-title="text.save$core"
|
:ok-title="text.save$core"
|
||||||
><div :class="'s-edit-mod-form '+ (genericonly?'genericonly':'')" ref="content"
|
><div :class="'s-edit-mod-form '" ref="content"
|
||||||
><div v-if="loading" class="d-flex justify-content-center mb-3"
|
><div v-if="loading" class="d-flex justify-content-center mb-3"
|
||||||
><b-spinner variant="primary"></b-spinner
|
><b-spinner variant="primary"></b-spinner
|
||||||
></div
|
></div
|
||||||
|
|
|
@ -1,20 +1,19 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace local_treestudyplan\local\forms;
|
namespace local_treestudyplan\local\forms;
|
||||||
|
require_once($CFG->dirroot."/lib/formslib.php");
|
||||||
|
|
||||||
use moodleform;
|
abstract class formbase extends \moodleform {
|
||||||
|
|
||||||
abstract class formbase extends moodleform {
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the form while providing the correct defaults for our type of forms
|
* Create the form while providing the correct defaults for our type of forms
|
||||||
|
* @param object $params Custom parameters this form needs
|
||||||
* @param array $ajaxformdata Provide submitted form data through Ajax here
|
* @param array $ajaxformdata Provide submitted form data through Ajax here
|
||||||
* @throws \moodle_exception if parameters are invalid or access is denied for a specific reason.
|
* @throws \moodle_exception if parameters are invalid or access is denied for a specific reason.
|
||||||
*/
|
*/
|
||||||
public function __construct($params, $ajaxformdata=null) {
|
public function __construct($params, $ajaxformdata=null) {
|
||||||
$customdata = static::init_customdata($params);
|
$customdata = static::init_customdata($params);
|
||||||
if (static::check_security($customdata)) {
|
if (static::check_security($customdata) !== false) {
|
||||||
|
|
||||||
parent::__construct(null, (array)$customdata, 'post', '', null, true, $ajaxformdata);
|
parent::__construct(null, (array)$customdata, 'post', '', null, true, $ajaxformdata);
|
||||||
// Initialize the initial data based on the parameter validation
|
// Initialize the initial data based on the parameter validation
|
||||||
$this->set_data($this->init_formdata((object)$this->_customdata));
|
$this->set_data($this->init_formdata((object)$this->_customdata));
|
||||||
|
|
|
@ -24,7 +24,7 @@ class studyplan_editform extends formbase {
|
||||||
*/
|
*/
|
||||||
public static function init_customdata(object $params) {
|
public static function init_customdata(object $params) {
|
||||||
$customdata = new stdClass;
|
$customdata = new stdClass;
|
||||||
$customdata->plan = studyplan::find_by_id($params->studyplanid);
|
$customdata->plan = studyplan::find_by_id($params->studyplan_id);
|
||||||
$customdata->context = $customdata->plan->context();
|
$customdata->context = $customdata->plan->context();
|
||||||
$customdata->editoroptions = [
|
$customdata->editoroptions = [
|
||||||
'trusttext' => true,
|
'trusttext' => true,
|
||||||
|
|
|
@ -48,9 +48,12 @@ class utilityservice extends \external_api {
|
||||||
|
|
||||||
protected function load_mform($formname, $params, $ajaxformdata = null) {
|
protected function load_mform($formname, $params, $ajaxformdata = null) {
|
||||||
global $CFG;
|
global $CFG;
|
||||||
$modmoodleform = "$CFG->dirroot/local/treestudyplan/local/forms/{$formname}.php";
|
/* We don't need to load the form php file (class autoloading will handle that)
|
||||||
|
but we do need to check it's existence to give a nice developer warning
|
||||||
|
and protect against some forms of hacking
|
||||||
|
*/
|
||||||
|
$modmoodleform = "$CFG->dirroot/local/treestudyplan/classes/local/forms/{$formname}.php";
|
||||||
if (!file_exists($modmoodleform)) {
|
if (!file_exists($modmoodleform)) {
|
||||||
// We don't need to load the form (autoloading will handle that) but do need to check it's existence
|
|
||||||
throw new \moodle_exception('noformdesc', 'local_treestudyplan');;
|
throw new \moodle_exception('noformdesc', 'local_treestudyplan');;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,16 +86,22 @@ class utilityservice extends \external_api {
|
||||||
public static function get_mform($formname, $params = '') {
|
public static function get_mform($formname, $params = '') {
|
||||||
global $OUTPUT, $PAGE, $CFG;
|
global $OUTPUT, $PAGE, $CFG;
|
||||||
|
|
||||||
|
\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.
|
// Hack alert: Set a default URL to stop the annoying debug.
|
||||||
$PAGE->set_url('/');
|
$PAGE->set_url('/');
|
||||||
// Hack alert: Forcing bootstrap_renderer to initiate moodle page.
|
// Hack alert: Forcing bootstrap_renderer to initiate moodle page.
|
||||||
$OUTPUT->header();
|
$OUTPUT->header();
|
||||||
|
|
||||||
// Overwriting page_requirements_manager with the fragment one so only JS included from.
|
/* Overwriting page_requirements_manager with the fragment one so only JS included from
|
||||||
// this point is returned to the user.
|
this point is returned to the user. */
|
||||||
$PAGE->start_collecting_javascript_requirements();
|
$PAGE->start_collecting_javascript_requirements();
|
||||||
|
|
||||||
$mform = self::load_mform($formname, $params);
|
// Perform actual render.
|
||||||
$html = $mform->render();
|
$html = $mform->render();
|
||||||
|
|
||||||
$jsfooter = $PAGE->requires->get_end_code();
|
$jsfooter = $PAGE->requires->get_end_code();
|
||||||
|
|
Loading…
Reference in a new issue