Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 123... Línea 123...
123
     * @property {HTMLElement} target The form field that has changed
123
     * @property {HTMLElement} target The form field that has changed
124
     */
124
     */
125
    fieldStructureChanged: 'core_form/fieldStructureChanged',
125
    fieldStructureChanged: 'core_form/fieldStructureChanged',
126
};
126
};
Línea 127... Línea -...
127
 
-
 
128
// These are only imported for legacy.
-
 
129
import jQuery from 'jquery';
-
 
130
import Y from 'core/yui';
-
 
131
 
127
 
132
/**
128
/**
133
 * Trigger an event to indicate that a form field contained an error.
129
 * Trigger an event to indicate that a form field contained an error.
134
 *
130
 *
135
 * @method notifyFormError
131
 * @method notifyFormError
Línea 267... Línea 263...
267
export const types = {
263
export const types = {
268
    uploadStarted: 'core_form/uploadStarted',
264
    uploadStarted: 'core_form/uploadStarted',
269
    uploadCompleted: 'core_form/uploadCompleted',
265
    uploadCompleted: 'core_form/uploadCompleted',
270
};
266
};
Línea 271... Línea -...
271
 
-
 
272
let legacyEventsRegistered = false;
-
 
273
if (!legacyEventsRegistered) {
-
 
274
    // The following event triggers are legacy and will be removed in the future.
-
 
275
    // The following approach provides a backwards-compatability layer for the new events.
-
 
276
    // Code should be updated to make use of native events.
-
 
277
    Y.use('event', 'moodle-core-event', () => {
-
 
278
 
-
 
279
        // Watch for the new native formError event, and trigger the legacy YUI event.
-
 
280
        document.addEventListener(eventTypes.formError, e => {
-
 
281
            const element = Y.one(e.target);
-
 
282
            const formElement = Y.one(e.target.closest('form'));
-
 
283
 
-
 
284
            Y.Global.fire(
-
 
285
                M.core.globalEvents.FORM_ERROR,
-
 
286
                {
-
 
287
                    formid: formElement.generateID(),
-
 
288
                    elementid: element.generateID(),
-
 
289
                }
-
 
290
            );
-
 
291
        });
-
 
292
 
-
 
293
        // Watch for the new native formSubmittedByJavascript event, and trigger the legacy YUI event.
-
 
294
        document.addEventListener(eventTypes.formSubmittedByJavascript, e => {
-
 
295
            if (e.detail.fallbackHandled) {
-
 
296
                // This event was originally generated by a YUI event.
-
 
297
                // Do not generate another as this will recurse.
-
 
298
                return;
-
 
299
            }
-
 
300
 
-
 
301
            if (e.skipValidation) {
-
 
302
                window.skipClientValidation = true;
-
 
303
            }
-
 
304
 
-
 
305
            // Trigger the legacy YUI event.
-
 
306
            const form = Y.one(e.target);
-
 
307
            form.fire(
-
 
308
                M.core.event.FORM_SUBMIT_AJAX,
-
 
309
                {
-
 
310
                    currentTarget: form,
-
 
311
                    fallbackHandled: true,
-
 
312
                }
-
 
313
            );
-
 
314
 
-
 
315
            if (e.skipValidation) {
-
 
316
                window.skipClientValidation = false;
-
 
317
            }
-
 
318
        });
-
 
319
    });
-
 
320
 
-
 
321
    // Watch for the new native formFieldValidationFailed event, and trigger the legacy jQuery event.
-
 
322
    document.addEventListener(eventTypes.formFieldValidationFailed, e => {
-
 
323
        // Note: The "core_form-field-validation" event is hard-coded in core/event.
-
 
324
        // This is not included to prevent cyclic module dependencies.
-
 
325
        const legacyEvent = jQuery.Event("core_form-field-validation");
-
 
326
 
-
 
327
        jQuery(e.target).trigger(legacyEvent, e.detail.message);
-
 
328
    });
-
 
329
 
-
 
330
    legacyEventsRegistered = true;
-
 
331
}
-
 
332
 
267
 
333
/**
268
/**
334
 * Trigger an event to notify the file upload field has been changed.
269
 * Trigger an event to notify the file upload field has been changed.
335
 *
270
 *
336
 * @method
271
 * @method