MDL-82547 javascript: convert to native inplace editable events.

This commit is contained in:
Paul Holden 2024-07-22 15:39:34 +01:00
parent 6cd55074c7
commit 3a4c0f32b2
No known key found for this signature in database
GPG Key ID: A81A96D6045F6164
6 changed files with 25 additions and 19 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

@ -37,6 +37,7 @@ define(
'core/log',
'core_courseformat/courseeditor',
'core/event_dispatcher',
'core/local/inplace_editable/events',
'core_course/events'
],
function(
@ -54,6 +55,7 @@ define(
log,
editor,
EventDispatcher,
InplaceEditableEvents,
CourseEvents
) {
@ -995,18 +997,21 @@ define(
// The section and activity names are edited using inplace editable.
// The "update" jQuery event must be captured in order to update the course state.
$('body').on('updated', `${SELECTOR.SECTIONITEM} [data-inplaceeditable]`, function(e) {
if (e.ajaxreturn && e.ajaxreturn.itemid) {
$('body').on(InplaceEditableEvents.eventTypes.elementUpdated,
`${SELECTOR.SECTIONITEM} [data-inplaceeditable]`, function(e) {
if (e.detail.ajaxreturn.itemid) {
const state = courseeditor.state;
const section = state.section.get(e.ajaxreturn.itemid);
const section = state.section.get(e.detail.ajaxreturn.itemid);
if (section !== undefined) {
courseeditor.dispatch('sectionState', [e.ajaxreturn.itemid]);
courseeditor.dispatch('sectionState', [e.detail.ajaxreturn.itemid]);
}
}
});
$('body').on('updated', `${SELECTOR.ACTIVITYLI} [data-itemtype="activityname"][data-inplaceeditable]`, function(e) {
if (e.ajaxreturn && e.ajaxreturn.itemid) {
courseeditor.dispatch('cmState', [e.ajaxreturn.itemid]);
$('body').on(InplaceEditableEvents.eventTypes.elementUpdated,
`${SELECTOR.ACTIVITYLI} [data-itemtype="activityname"][data-inplaceeditable]`, function(e) {
if (e.detail.ajaxreturn.itemid) {
courseeditor.dispatch('cmState', [e.detail.ajaxreturn.itemid]);
}
});

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -31,6 +31,7 @@ import * as ModalEvents from 'core/modal_events';
import Pending from 'core/pending';
import SaveCancelModal from 'core/modal_save_cancel';
import Config from 'core/config';
import {eventTypes as inplaceEditableEvents} from 'core/local/inplace_editable/events';
import * as reportSelectors from 'core_reportbuilder/local/selectors';
const getTagIndex = (tagindex) => fetchMany([{
@ -323,9 +324,9 @@ export const initTagindexPage = async() => {
*/
export const initManagePage = () => {
// Toggle row class when updating flag.
$('body').on('updated', '[data-inplaceeditable][data-itemtype=tagflag]', function(e) {
$('body').on(inplaceEditableEvents.elementUpdated, '[data-inplaceeditable][data-itemtype=tagflag]', function(e) {
var row = $(e.target).closest('tr');
row.toggleClass('table-warning', e.ajaxreturn.value === '1');
row.toggleClass('table-warning', e.detail.ajaxreturn.value === '1');
});
// Confirmation for bulk tag combine button.
@ -355,9 +356,9 @@ export const initManagePage = () => {
});
// When user changes tag name to some name that already exists suggest to combine the tags.
$('body').on('updatefailed', '[data-inplaceeditable][data-itemtype=tagname]', async(e) => {
var exception = e.exception; // The exception object returned by the callback.
var newvalue = e.newvalue; // The value that user tried to udpated the element to.
$('body').on(inplaceEditableEvents.elementUpdateFailed, '[data-inplaceeditable][data-itemtype=tagname]', async(e) => {
var exception = e.detail.exception; // The exception object returned by the callback.
var newvalue = e.detail.newvalue; // The value that user tried to udpated the element to.
var tagid = $(e.target).attr('data-itemid');
if (exception.errorcode !== 'namesalreadybeeingused') {
return;
@ -392,10 +393,10 @@ export const initManagePage = () => {
* @method initManageCollectionsPage
*/
export const initManageCollectionsPage = () => {
$('body').on('updated', '[data-inplaceeditable]', function(e) {
$('body').on(inplaceEditableEvents.elementUpdated, '[data-inplaceeditable]', function(e) {
var pendingPromise = new Pending('core/tag:initManageCollectionsPage-updated');
var ajaxreturn = e.ajaxreturn,
var ajaxreturn = e.detail.ajaxreturn,
areaid, collid, isenabled;
if (ajaxreturn.component === 'core_tag' && ajaxreturn.itemtype === 'tagareaenable') {
areaid = $(this).attr('data-itemid');