Merge branch 'mdl-83262_main' of https://github.com/james-cnz/moodle

This commit is contained in:
Huong Nguyen
2025-04-21 09:12:23 +07:00
3 changed files with 28 additions and 5 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+26 -3
View File
@@ -321,13 +321,18 @@ export default class Component extends BaseComponent {
if (!target) {
return;
}
const sectionIsCollapsible = this._getCollapsibleSections();
// Check if we have all sections collapsed/expanded.
let allcollapsed = true;
let allexpanded = true;
state.section.forEach(
section => {
allcollapsed = allcollapsed && section.contentcollapsed;
allexpanded = allexpanded && !section.contentcollapsed;
if (sectionIsCollapsible[section.id]) {
allcollapsed = allcollapsed && section.contentcollapsed;
allexpanded = allexpanded && !section.contentcollapsed;
}
}
);
if (allcollapsed) {
@@ -340,6 +345,21 @@ export default class Component extends BaseComponent {
}
}
/**
* Find collapsible sections.
*/
_getCollapsibleSections() {
let sectionIsCollapsible = {};
const togglerDoms = this.element.querySelectorAll(this.selectors.COLLAPSE);
for (let togglerDom of togglerDoms) {
const headerDom = togglerDom.closest(this.selectors.SECTION_ITEM);
if (headerDom) {
sectionIsCollapsible[headerDom.dataset.id] = true;
}
}
return sectionIsCollapsible;
}
/**
* Setup the component to start a transaction.
*
@@ -455,9 +475,10 @@ export default class Component extends BaseComponent {
* Refresh a section cm list.
*
* @param {Object} param
* @param {Object} param.state the full state object.
* @param {Object} param.element details the update details.
*/
_refreshSectionCmlist({element}) {
_refreshSectionCmlist({state, element}) {
const cmlist = element.cmlist ?? [];
const section = this.getElement(this.selectors.SECTION, element.id);
const listparent = section?.querySelector(this.selectors.SECTION_CMLIST);
@@ -466,6 +487,7 @@ export default class Component extends BaseComponent {
if (listparent) {
this._fixOrder(listparent, cmlist, this.selectors.CM, this.dettachedCms, createCm);
}
this._refreshAllSectionsToggler(state);
}
/**
@@ -486,6 +508,7 @@ export default class Component extends BaseComponent {
if (listparent) {
this._fixOrder(listparent, sectionlist, this.selectors.SECTION, this.dettachedSections, createSection);
}
this._refreshAllSectionsToggler(state);
}
/**