Merge branch 'MDL-71686-master' of https://github.com/marinaglancy/moodle

This commit is contained in:
Andrew Nicols 2022-10-06 10:20:56 +08:00
commit 2423c26749
6 changed files with 21 additions and 8 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -136,9 +136,15 @@ export default class DynamicForm {
* @public
*/
load(args = null) {
const formData = new URLSearchParams(Object.entries(args || {}));
const serialize = function(obj, prefix = '') {
return [].concat(...Object.entries(obj).map(([idx, v]) => {
const k = prefix ? prefix + "[" + idx + "]" : idx;
return (typeof v === "object") ? serialize(v, k) : `${k}=${encodeURIComponent(v)}`;
})).join("&");
};
const formData = serialize(args || {});
const pendingPromise = new Pending('core_form/dynamicform:load');
return this.getBody(formData.toString())
return this.getBody(formData)
.then((resp) => this.updateForm(resp))
.then(pendingPromise.resolve);
}

View file

@ -115,6 +115,13 @@ export default class ModalForm {
*/
show() {
const pendingPromise = new Pending('core_form/modalform:init');
const serialize = function(obj, prefix = '') {
return [].concat(...Object.entries(obj).map(([idx, v]) => {
const k = prefix ? prefix + "[" + idx + "]" : idx;
return (typeof v === "object") ? serialize(v, k) : `${k}=${encodeURIComponent(v)}`;
})).join("&");
};
return ModalFactory.create(this.config.modalConfig)
.then((modal) => {
this.modal = modal;
@ -122,8 +129,8 @@ export default class ModalForm {
// Retrieve the form and set the modal body. We can not set the body in the modalConfig,
// we need to make sure that the modal already exists when we render the form. Some form elements
// such as date_selector inspect the existing elements on the page to find the highest z-index.
const formParams = new URLSearchParams(Object.entries(this.config.args || {}));
const bodyContent = this.getBody(formParams.toString());
const formParams = serialize(this.config.args || {});
const bodyContent = this.getBody(formParams);
this.modal.setBodyContent(bodyContent);
bodyContent.catch(Notification.exception);