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',
};
/**
templateContext: {
contextid: contextId
}
- },
- [root, SELECTORS.NEW_EVENT_BUTTON]
+ }
);
};
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);