MDL-82341 core_courseformat: migrate events for inplace editable

This commit is contained in:
ferran 2024-11-05 12:36:18 +01:00
parent 074645571b
commit f081373156
3 changed files with 34 additions and 3 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -26,6 +26,7 @@
*/
import {BaseComponent} from 'core/reactive';
import {eventTypes} from 'core/local/inplace_editable/events';
import Modal from 'core/modal';
import ModalSaveCancel from 'core/modal_save_cancel';
import ModalDeleteCancel from 'core/modal_delete_cancel';
@ -131,6 +132,12 @@ export default class extends BaseComponent {
CourseEvents.sectionRefreshed,
() => this._checkSectionlist({state})
);
// Any inplace editable update needs state refresh.
this.addEventListener(
this.element,
eventTypes.elementUpdated,
this._inplaceEditableHandler
);
}
/**
@ -191,6 +198,30 @@ export default class extends BaseComponent {
this._setAddSectionLocked(state.course.sectionlist.length > state.course.maxsections);
}
/**
* Handle inplace editable updates.
*
* @param {Event} event the triggered event
* @private
*/
_inplaceEditableHandler(event) {
const itemtype = event.detail?.ajaxreturn?.itemtype;
const itemid = parseInt(event.detail?.ajaxreturn?.itemid);
if (!Number.isFinite(itemid) || !itemtype) {
return;
}
if (itemtype === 'activityname') {
this.reactive.dispatch('cmState', [itemid]);
return;
}
// Sections uses sectionname for normal sections and sectionnamenl for the no link sections.
if (itemtype === 'sectionname' || itemtype === 'sectionnamenl') {
this.reactive.dispatch('sectionState', [itemid]);
return;
}
}
/**
* Return the ids represented by this element.
*