MDL-68728 calendar: Pending promises for event summary
authorAndrew Nicols <andrew@nicols.co.uk>
Mon, 18 May 2020 00:06:58 +0000 (08:06 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Mon, 18 May 2020 05:00:32 +0000 (13:00 +0800)
calendar/amd/build/crud.min.js
calendar/amd/build/crud.min.js.map
calendar/amd/build/summary_modal.min.js
calendar/amd/build/summary_modal.min.js.map
calendar/amd/build/view_manager.min.js
calendar/amd/build/view_manager.min.js.map
calendar/amd/src/crud.js
calendar/amd/src/summary_modal.js
calendar/amd/src/view_manager.js

index de454aa..9f0d0e1 100644 (file)
Binary files a/calendar/amd/build/crud.min.js and b/calendar/amd/build/crud.min.js differ
index b8789cb..ff94570 100644 (file)
Binary files a/calendar/amd/build/crud.min.js.map and b/calendar/amd/build/crud.min.js.map differ
index 9413150..dcba8cd 100644 (file)
Binary files a/calendar/amd/build/summary_modal.min.js and b/calendar/amd/build/summary_modal.min.js differ
index d0c92b5..9146ef8 100644 (file)
Binary files a/calendar/amd/build/summary_modal.min.js.map and b/calendar/amd/build/summary_modal.min.js.map differ
index c095ee1..fa3574a 100644 (file)
Binary files a/calendar/amd/build/view_manager.min.js and b/calendar/amd/build/view_manager.min.js differ
index e40ea6f..5d5a0c2 100644 (file)
Binary files a/calendar/amd/build/view_manager.min.js.map and b/calendar/amd/build/view_manager.min.js.map differ
index c005a42..a82bee1 100644 (file)
@@ -239,7 +239,9 @@ function(
      * @returns {Promise}
      */
     function registerEditListeners(root, eventFormModalPromise) {
-        eventFormModalPromise
+        var pendingPromise = new Pending('core_calendar/crud:registerEditListeners');
+
+        return eventFormModalPromise
         .then(function(modal) {
             // When something within the calendar tells us the user wants
             // to edit an event then show the event form modal.
@@ -251,11 +253,14 @@ function(
 
                 e.stopImmediatePropagation();
             });
-            return;
+            return modal;
         })
-        .fail(Notification.exception);
+        .then(function(modal) {
+            pendingPromise.resolve();
 
-        return eventFormModalPromise;
+            return modal;
+        })
+        .catch(Notification.exception);
     }
 
     return {
index 3cd7aa0..5f92706 100644 (file)
@@ -165,6 +165,7 @@ function(
 
         // We have to wait for the modal to finish rendering in order to ensure that
         // the data-event-title property is available to use as the modal title.
+        M.util.js_pending('core_calendar/summary_modal:registerEventListeners:bodyRendered');
         this.getRoot().on(ModalEvents.bodyRendered, function() {
             this.getModal().data({
                 eventTitle: this.getEventTitle(),
@@ -173,7 +174,7 @@ function(
             })
             .attr('data-type', 'event');
             CalendarCrud.registerRemove(this.getModal());
-
+            M.util.js_complete('core_calendar/summary_modal:registerEventListeners:bodyRendered');
         }.bind(this));
 
         $('body').on(CalendarEvents.deleted, function() {
index ba7cd23..d89d148 100644 (file)
@@ -32,6 +32,7 @@ import ModalFactory from 'core/modal_factory';
 import ModalEvents from 'core/modal_events';
 import SummaryModal from 'core_calendar/summary_modal';
 import CustomEvents from 'core/custom_interaction_events';
+import Pending from 'core/pending';
 
 /**
  * Register event listeners for the module.
@@ -46,6 +47,7 @@ const registerEventListeners = (root) => {
         const target = e.target;
         let eventLink = null;
         let eventId = null;
+        const pendingPromise = new Pending('core_calendar/view_manager:eventLink:click');
 
         if (target.matches(CalendarSelectors.actions.viewEvent)) {
             eventLink = target;
@@ -67,7 +69,11 @@ const registerEventListeners = (root) => {
             // and causing the day click handler to fire.
             e.stopPropagation();
 
-            renderEventSummaryModal(eventId);
+            renderEventSummaryModal(eventId)
+            .then(pendingPromise.resolve)
+            .catch();
+        } else {
+            pendingPromise.resolve();
         }
     });
 
@@ -372,20 +378,21 @@ const getEventTypeClassFromType = (eventType) => {
  * Render the event summary modal.
  *
  * @param {Number} eventId The calendar event id.
+ * @returns {Promise}
  */
 const renderEventSummaryModal = (eventId) => {
-    let typeClass = '';
+    const pendingPromise = new Pending('core_calendar/view_manager:renderEventSummaryModal');
 
     // Calendar repository promise.
-    CalendarRepository.getEventById(eventId).then((getEventResponse) => {
+    return CalendarRepository.getEventById(eventId)
+    .then((getEventResponse) => {
         if (!getEventResponse.event) {
             throw new Error('Error encountered while trying to fetch calendar event with ID: ' + eventId);
         }
-        const eventData = getEventResponse.event;
-        typeClass = getEventTypeClassFromType(eventData.normalisedeventtype);
 
-        return eventData;
-    }).then((eventData) => {
+        return getEventResponse.event;
+    })
+    .then(eventData => {
         // Build the modal parameters from the event data.
         const modalParams = {
             title: eventData.name,
@@ -394,7 +401,7 @@ const renderEventSummaryModal = (eventId) => {
             templateContext: {
                 canedit: eventData.canedit,
                 candelete: eventData.candelete,
-                headerclasses: typeClass,
+                headerclasses: getEventTypeClassFromType(eventData.normalisedeventtype),
                 isactionevent: eventData.isactionevent,
                 url: eventData.url
             }
@@ -402,8 +409,8 @@ const renderEventSummaryModal = (eventId) => {
 
         // Create the modal.
         return ModalFactory.create(modalParams);
-
-    }).done(function(modal) {
+    })
+    .then(modal => {
         // Handle hidden event.
         modal.getRoot().on(ModalEvents.hidden, function() {
             // Destroy when hidden.
@@ -413,7 +420,14 @@ const renderEventSummaryModal = (eventId) => {
         // Finally, render the modal!
         modal.show();
 
-    }).fail(Notification.exception);
+        return modal;
+    })
+    .then(modal => {
+        pendingPromise.resolve();
+
+        return modal;
+    })
+    .catch(Notification.exception);
 };
 
 export const init = (root, view) => {