MDL-59940 calendar: Improve event start time default
authorAndrew Nicols <andrew@nicols.co.uk>
Tue, 12 Sep 2017 00:33:46 +0000 (08:33 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Mon, 25 Sep 2017 03:52:08 +0000 (11:52 +0800)
Create events on the first day of the month when not in the current
month.

calendar/amd/build/calendar.min.js
calendar/amd/src/calendar.js

index 8e4150a..c9f858f 100644 (file)
Binary files a/calendar/amd/build/calendar.min.js and b/calendar/amd/build/calendar.min.js differ
index 10af845..6e988e8 100644 (file)
@@ -66,7 +66,8 @@ define([
         LOADING_ICON: '.loading-icon',
         VIEW_DAY_LINK: "[data-action='view-day-link']",
         CALENDAR_MONTH_WRAPPER: ".calendarwrapper",
-        COURSE_SELECTOR: 'select[name="course"]'
+        COURSE_SELECTOR: 'select[name="course"]',
+        TODAY: '.today',
     };
 
     /**
@@ -210,8 +211,7 @@ define([
                 templateContext: {
                     contextid: contextId
                 }
-            },
-            [root, SELECTORS.NEW_EVENT_BUTTON]
+            }
         );
     };
 
@@ -295,6 +295,24 @@ define([
         var eventFormPromise = registerEventFormModal(root);
         registerCalendarEventListeners(root, eventFormPromise);
 
+        // Bind click event on the new event button.
+        root.on('click', SELECTORS.NEW_EVENT_BUTTON, function(e) {
+            eventFormPromise.then(function(modal) {
+                // Attempt to find the cell for today.
+                // If it can't be found, then use the start time of the first day on the calendar.
+                var today = root.find(SELECTORS.TODAY);
+                if (!today.length) {
+                    modal.setStartTime(root.find(SELECTORS.DAY).attr('data-new-event-timestamp'));
+                }
+
+                modal.show();
+                return;
+            })
+            .fail(Notification.exception);
+
+            e.preventDefault();
+        });
+
         // Bind click events to calendar days.
         root.on('click', SELECTORS.DAY, function(e) {
             var target = $(e.target);