diff --git a/calendar/amd/build/calendar.min.js b/calendar/amd/build/calendar.min.js
index cb7a44325a9c3..eadb3e66efe92 100644
--- a/calendar/amd/build/calendar.min.js
+++ b/calendar/amd/build/calendar.min.js
@@ -1,2 +1,2 @@
-define ("core_calendar/calendar",["jquery","core/ajax","core/str","core/templates","core/notification","core/custom_interaction_events","core/modal_events","core/modal_factory","core_calendar/modal_event_form","core_calendar/summary_modal","core_calendar/repository","core_calendar/events","core_calendar/view_manager","core_calendar/crud","core_calendar/selectors","core/config"],function(a,b,c,d,f,g,h,i,j,k,l,m,n,o,p,q){var r={ROOT:"[data-region='calendar']",DAY:"[data-region='day']",NEW_EVENT_BUTTON:"[data-action='new-event-button']",DAY_CONTENT:"[data-region='day-content']",LOADING_ICON:".loading-icon",VIEW_DAY_LINK:"[data-action='view-day-link']",CALENDAR_MONTH_WRAPPER:".calendarwrapper",TODAY:".today",DAY_NUMBER_CIRCLE:".day-number-circle",DAY_NUMBER:".day-number"},s=function(b,c,e,g){var h=null,i=g.attr("data-day-timestamp");if(e){h=e.attr("data-day-timestamp")}if(!e||h!=i){d.render("core/loading",{}).then(function(a,b){g.find(r.DAY_CONTENT).addClass("hidden");d.appendNodeContents(g,a,b);if(e){e.find(r.DAY_CONTENT).addClass("hidden");d.appendNodeContents(e,a,b)}}).then(function(){return l.updateEventStartDay(c,i)}).then(function(){a("body").trigger(m.eventMoved,[c,e,g])}).always(function(){var a=g.find(r.LOADING_ICON);g.find(r.DAY_CONTENT).removeClass("hidden");d.replaceNode(a,"","");if(e){var b=e.find(r.LOADING_ICON);e.find(r.DAY_CONTENT).removeClass("hidden");d.replaceNode(b,"","")}}).fail(f.exception)}},t=function(b,c){var d=a("body");d.on(m.created,function(){n.reloadCurrentMonth(b)});d.on(m.deleted,function(){n.reloadCurrentMonth(b)});d.on(m.updated,function(){n.reloadCurrentMonth(b)});d.on(m.editActionEvent,function(a,b){window.location.assign(b)});d.on(m.moveEvent,s);d.on(m.eventMoved,function(){n.reloadCurrentMonth(b)});o.registerEditListeners(b,c)},u=function(b){var c=document.getElementById(p.fullCalendarView);b.on("click",r.VIEW_DAY_LINK,function(d){var e=a(d.target).closest(r.VIEW_DAY_LINK),g=e.data("year"),h=e.data("month"),i=e.data("day"),j=e.data("courseid"),k=e.data("categoryid"),l="?view=day&time="+e.data("timestamp");if(c){n.refreshDayContent(b,g,h,i,j,k,b,"core_calendar/calendar_day").then(function(){d.preventDefault();return n.updateUrl(l)}).fail(f.exception)}else{window.location.assign(q.wwwroot+"/calendar/view.php"+l)}});b.on("change",p.elements.courseSelector,function(){var c=a(this),d=c.val();n.reloadCurrentMonth(b,d,null).then(function(){return b.find(p.elements.courseSelector).val(d)}).fail(f.exception)});var d=o.registerEventFormModal(b),e=a(r.CALENDAR_MONTH_WRAPPER).data("context-id");t(b,d);if(e){b.on("click",r.DAY,function(g){var e=a(g.target),h="side-pre"===b.parents("aside").data("blockregion");if(!c&&h){var i=e.closest(r.DAY),j="?view=day&time="+i.data("day-timestamp");window.location.assign(q.wwwroot+"/calendar/view.php"+j)}else{var k=e.closest(r.VIEW_DAY_LINK);if(!k){var l=a(this).attr("data-new-event-timestamp");d.then(function(a){var b=e.closest(p.wrapper);a.setCourseId(b.data("courseid"));var c=b.data("categoryid");if("undefined"!=typeof c){a.setCategoryId(c)}a.setContextId(b.data("contextId"));a.setStartTime(l);a.show()}).fail(f.exception)}}g.preventDefault()})}};return{init:function init(b){b=a(b);n.init(b);u(b)}}});
+define ("core_calendar/calendar",["jquery","core/ajax","core/str","core/templates","core/notification","core/custom_interaction_events","core/modal_events","core/modal_factory","core_calendar/modal_event_form","core_calendar/summary_modal","core_calendar/repository","core_calendar/events","core_calendar/view_manager","core_calendar/crud","core_calendar/selectors","core/config"],function(a,b,c,d,f,g,h,i,j,k,l,m,n,o,p,q){var r={ROOT:"[data-region='calendar']",DAY:"[data-region='day']",NEW_EVENT_BUTTON:"[data-action='new-event-button']",DAY_CONTENT:"[data-region='day-content']",LOADING_ICON:".loading-icon",VIEW_DAY_LINK:"[data-action='view-day-link']",CALENDAR_MONTH_WRAPPER:".calendarwrapper",TODAY:".today",DAY_NUMBER_CIRCLE:".day-number-circle",DAY_NUMBER:".day-number"},s=function(b,c,e,g){var h=null,i=g.attr("data-day-timestamp");if(e){h=e.attr("data-day-timestamp")}if(!e||h!=i){d.render("core/loading",{}).then(function(a,b){g.find(r.DAY_CONTENT).addClass("hidden");d.appendNodeContents(g,a,b);if(e){e.find(r.DAY_CONTENT).addClass("hidden");d.appendNodeContents(e,a,b)}}).then(function(){return l.updateEventStartDay(c,i)}).then(function(){a("body").trigger(m.eventMoved,[c,e,g])}).always(function(){var a=g.find(r.LOADING_ICON);g.find(r.DAY_CONTENT).removeClass("hidden");d.replaceNode(a,"","");if(e){var b=e.find(r.LOADING_ICON);e.find(r.DAY_CONTENT).removeClass("hidden");d.replaceNode(b,"","")}}).fail(f.exception)}},t=function(b,c){var d=a("body");d.on(m.created,function(){n.reloadCurrentMonth(b)});d.on(m.deleted,function(){n.reloadCurrentMonth(b)});d.on(m.updated,function(){n.reloadCurrentMonth(b)});d.on(m.editActionEvent,function(a,b){window.location.assign(b)});d.on(m.moveEvent,s);d.on(m.eventMoved,function(){n.reloadCurrentMonth(b)});o.registerEditListeners(b,c)},u=function(b){var c=document.getElementById(p.fullCalendarView);b.on("click",r.VIEW_DAY_LINK,function(d){var e=a(d.target).closest(r.VIEW_DAY_LINK),g=e.data("year"),h=e.data("month"),i=e.data("day"),j=e.data("courseid"),k=e.data("categoryid"),l="?view=day&time="+e.data("timestamp");if(c){n.refreshDayContent(b,g,h,i,j,k,b,"core_calendar/calendar_day").then(function(){d.preventDefault();return n.updateUrl(l)}).fail(f.exception)}else{window.location.assign(q.wwwroot+"/calendar/view.php"+l)}});b.on("change",p.elements.courseSelector,function(){var c=a(this),d=c.val();n.reloadCurrentMonth(b,d,null).then(function(){return b.find(p.elements.courseSelector).val(d)}).fail(f.exception)});var d=o.registerEventFormModal(b),e=a(r.CALENDAR_MONTH_WRAPPER).data("context-id");t(b,d);if(e){b.on("click",r.DAY,function(g){var e=a(g.target),h="side-pre"===b.parents("aside").data("blockregion");if(!c&&h){var i=e.closest(r.DAY),j="?view=day&time="+i.data("day-timestamp");window.location.assign(q.wwwroot+"/calendar/view.php"+j)}else{var k=e.closest(r.VIEW_DAY_LINK).length;if(!k){var l=a(this).attr("data-new-event-timestamp");d.then(function(a){var b=e.closest(p.wrapper);a.setCourseId(b.data("courseid"));var c=b.data("categoryid");if("undefined"!=typeof c){a.setCategoryId(c)}a.setContextId(b.data("contextId"));a.setStartTime(l);a.show()}).fail(f.exception)}}g.preventDefault()})}};return{init:function init(b){b=a(b);n.init(b);u(b)}}});
//# sourceMappingURL=calendar.min.js.map
diff --git a/calendar/amd/build/calendar.min.js.map b/calendar/amd/build/calendar.min.js.map
index 0de1056fc595b..c923c58fa945a 100644
--- a/calendar/amd/build/calendar.min.js.map
+++ b/calendar/amd/build/calendar.min.js.map
@@ -1 +1 @@
-{"version":3,"sources":["../src/calendar.js"],"names":["define","$","Ajax","Str","Templates","Notification","CustomEvents","ModalEvents","ModalFactory","ModalEventForm","SummaryModal","CalendarRepository","CalendarEvents","CalendarViewManager","CalendarCrud","CalendarSelectors","Config","SELECTORS","ROOT","DAY","NEW_EVENT_BUTTON","DAY_CONTENT","LOADING_ICON","VIEW_DAY_LINK","CALENDAR_MONTH_WRAPPER","TODAY","DAY_NUMBER_CIRCLE","DAY_NUMBER","handleMoveEvent","e","eventId","originElement","destinationElement","originTimestamp","destinationTimestamp","attr","render","then","html","js","find","addClass","appendNodeContents","updateEventStartDay","trigger","eventMoved","always","destinationLoadingElement","removeClass","replaceNode","originLoadingElement","fail","exception","registerCalendarEventListeners","root","eventFormModalPromise","body","on","created","reloadCurrentMonth","deleted","updated","editActionEvent","url","window","location","assign","moveEvent","registerEditListeners","registerEventListeners","viewingFullCalendar","document","getElementById","fullCalendarView","dayLink","target","closest","year","data","month","day","courseId","categoryId","refreshDayContent","preventDefault","updateUrl","wwwroot","elements","courseSelector","selectElement","val","eventFormPromise","registerEventFormModal","contextId","displayingSmallBlockCalendar","parents","dateContainer","hasViewDayLink","startTime","modal","wrapper","setCourseId","setCategoryId","setContextId","setStartTime","show","init"],"mappings":"AA0BAA,OAAM,0BAAC,CACK,QADL,CAEK,WAFL,CAGK,UAHL,CAIK,gBAJL,CAKK,mBALL,CAMK,gCANL,CAOK,mBAPL,CAQK,oBARL,CASK,gCATL,CAUK,6BAVL,CAWK,0BAXL,CAYK,sBAZL,CAaK,4BAbL,CAcK,oBAdL,CAeK,yBAfL,CAgBK,aAhBL,CAAD,CAkBE,SACIC,CADJ,CAEIC,CAFJ,CAGIC,CAHJ,CAIIC,CAJJ,CAKIC,CALJ,CAMIC,CANJ,CAOIC,CAPJ,CAQIC,CARJ,CASIC,CATJ,CAUIC,CAVJ,CAWIC,CAXJ,CAYIC,CAZJ,CAaIC,CAbJ,CAcIC,CAdJ,CAeIC,CAfJ,CAgBIC,CAhBJ,CAiBE,IAEFC,CAAAA,CAAS,CAAG,CACZC,IAAI,CAAE,0BADM,CAEZC,GAAG,CAAE,qBAFO,CAGZC,gBAAgB,CAAE,kCAHN,CAIZC,WAAW,CAAE,6BAJD,CAKZC,YAAY,CAAE,eALF,CAMZC,aAAa,CAAE,+BANH,CAOZC,sBAAsB,CAAE,kBAPZ,CAQZC,KAAK,CAAE,QARK,CASZC,iBAAiB,CAAE,oBATP,CAUZC,UAAU,CAAE,aAVA,CAFV,CA2BFC,CAAe,CAAG,SAASC,CAAT,CAAYC,CAAZ,CAAqBC,CAArB,CAAoCC,CAApC,CAAwD,IACtEC,CAAAA,CAAe,CAAG,IADoD,CAEtEC,CAAoB,CAAGF,CAAkB,CAACG,IAAnB,CAAwB,oBAAxB,CAF+C,CAI1E,GAAIJ,CAAJ,CAAmB,CACfE,CAAe,CAAGF,CAAa,CAACI,IAAd,CAAmB,oBAAnB,CACrB,CAGD,GAAI,CAACJ,CAAD,EAAkBE,CAAe,EAAIC,C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CAAe3D,CAAS,CAACM,aAAzB,CADpB,CAGH,GADgC,CAAC0E,CACjC,CAA6B,CACzB,GAAIC,CAAAA,CAAS,CAAGjG,CAAC,CAAC,IAAD,CAAD,CAAQkC,IAAR,CAAa,0BAAb,CAAhB,CACAwD,CAAgB,CAACtD,IAAjB,CAAsB,SAAS8D,CAAT,CAAgB,CAClC,GAAIC,CAAAA,CAAO,CAAGzB,CAAM,CAACC,OAAP,CAAe7D,CAAiB,CAACqF,OAAjC,CAAd,CACAD,CAAK,CAACE,WAAN,CAAkBD,CAAO,CAACtB,IAAR,CAAa,UAAb,CAAlB,EAEA,GAAII,CAAAA,CAAU,CAAGkB,CAAO,CAACtB,IAAR,CAAa,YAAb,CAAjB,CACA,GAA0B,WAAtB,QAAOI,CAAAA,CAAX,CAAuC,CACnCiB,CAAK,CAACG,aAAN,CAAoBpB,CAApB,CACH,CAEDiB,CAAK,CAACI,YAAN,CAAmBH,CAAO,CAACtB,IAAR,CAAa,WAAb,CAAnB,EACAqB,CAAK,CAACK,YAAN,CAAmBN,CAAnB,EACAC,CAAK,CAACM,IAAN,EAEH,CAbD,EAaGtD,IAbH,CAaQ9C,CAAY,CAAC+C,SAbrB,CAcH,CACJ,CACDvB,CAAC,CAACuD,cAAF,EACH,CA9BD,CA+BH,CACJ,CA1LK,CA4LN,MAAO,CACHsB,IAAI,CAAE,cAASpD,CAAT,CAAe,CACjBA,CAAI,CAAGrD,CAAC,CAACqD,CAAD,CAAR,CACAzC,CAAmB,CAAC6F,IAApB,CAAyBpD,CAAzB,EACAe,CAAsB,CAACf,CAAD,CACzB,CALE,CAOV,CAtOK,CAAN","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * This module is the highest level module for the calendar. It is\n * responsible for initialising all of the components required for\n * the calendar to run. It also coordinates the interaction between\n * components by listening for and responding to different events\n * triggered within the calendar UI.\n *\n * @module core_calendar/calendar\n * @copyright 2017 Simey Lameze \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine([\n 'jquery',\n 'core/ajax',\n 'core/str',\n 'core/templates',\n 'core/notification',\n 'core/custom_interaction_events',\n 'core/modal_events',\n 'core/modal_factory',\n 'core_calendar/modal_event_form',\n 'core_calendar/summary_modal',\n 'core_calendar/repository',\n 'core_calendar/events',\n 'core_calendar/view_manager',\n 'core_calendar/crud',\n 'core_calendar/selectors',\n 'core/config',\n ],\n function(\n $,\n Ajax,\n Str,\n Templates,\n Notification,\n CustomEvents,\n ModalEvents,\n ModalFactory,\n ModalEventForm,\n SummaryModal,\n CalendarRepository,\n CalendarEvents,\n CalendarViewManager,\n CalendarCrud,\n CalendarSelectors,\n Config,\n ) {\n\n var SELECTORS = {\n ROOT: \"[data-region='calendar']\",\n DAY: \"[data-region='day']\",\n NEW_EVENT_BUTTON: \"[data-action='new-event-button']\",\n DAY_CONTENT: \"[data-region='day-content']\",\n LOADING_ICON: '.loading-icon',\n VIEW_DAY_LINK: \"[data-action='view-day-link']\",\n CALENDAR_MONTH_WRAPPER: \".calendarwrapper\",\n TODAY: '.today',\n DAY_NUMBER_CIRCLE: '.day-number-circle',\n DAY_NUMBER: '.day-number'\n };\n\n /**\n * Handler for the drag and drop move event. Provides a loading indicator\n * while the request is sent to the server to update the event start date.\n *\n * Triggers a eventMoved calendar javascript event if the event was successfully\n * updated.\n *\n * @param {event} e The calendar move event\n * @param {int} eventId The event id being moved\n * @param {object|null} originElement The jQuery element for where the event is moving from\n * @param {object} destinationElement The jQuery element for where the event is moving to\n */\n var handleMoveEvent = function(e, eventId, originElement, destinationElement) {\n var originTimestamp = null;\n var destinationTimestamp = destinationElement.attr('data-day-timestamp');\n\n if (originElement) {\n originTimestamp = originElement.attr('data-day-timestamp');\n }\n\n // If the event has actually changed day.\n if (!originElement || originTimestamp != destinationTimestamp) {\n Templates.render('core/loading', {})\n .then(function(html, js) {\n // First we show some loading icons in each of the days being affected.\n destinationElement.find(SELECTORS.DAY_CONTENT).addClass('hidden');\n Templates.appendNodeContents(destinationElement, html, js);\n\n if (originElement) {\n originElement.find(SELECTORS.DAY_CONTENT).addClass('hidden');\n Templates.appendNodeContents(originElement, html, js);\n }\n return;\n })\n .then(function() {\n // Send a request to the server to make the change.\n return CalendarRepository.updateEventStartDay(eventId, destinationTimestamp);\n })\n .then(function() {\n // If the update was successful then broadcast an event letting the calendar\n // know that an event has been moved.\n $('body').trigger(CalendarEvents.eventMoved, [eventId, originElement, destinationElement]);\n return;\n })\n .always(function() {\n // Always remove the loading icons regardless of whether the update\n // request was successful or not.\n var destinationLoadingElement = destinationElement.find(SELECTORS.LOADING_ICON);\n destinationElement.find(SELECTORS.DAY_CONTENT).removeClass('hidden');\n Templates.replaceNode(destinationLoadingElement, '', '');\n\n if (originElement) {\n var originLoadingElement = originElement.find(SELECTORS.LOADING_ICON);\n originElement.find(SELECTORS.DAY_CONTENT).removeClass('hidden');\n Templates.replaceNode(originLoadingElement, '', '');\n }\n return;\n })\n .fail(Notification.exception);\n }\n };\n\n /**\n * Listen to and handle any calendar events fired by the calendar UI.\n *\n * @method registerCalendarEventListeners\n * @param {object} root The calendar root element\n * @param {object} eventFormModalPromise A promise reolved with the event form modal\n */\n var registerCalendarEventListeners = function(root, eventFormModalPromise) {\n var body = $('body');\n\n body.on(CalendarEvents.created, function() {\n CalendarViewManager.reloadCurrentMonth(root);\n });\n body.on(CalendarEvents.deleted, function() {\n CalendarViewManager.reloadCurrentMonth(root);\n });\n body.on(CalendarEvents.updated, function() {\n CalendarViewManager.reloadCurrentMonth(root);\n });\n body.on(CalendarEvents.editActionEvent, function(e, url) {\n // Action events needs to be edit directly on the course module.\n window.location.assign(url);\n });\n // Handle the event fired by the drag and drop code.\n body.on(CalendarEvents.moveEvent, handleMoveEvent);\n // When an event is successfully moved we should updated the UI.\n body.on(CalendarEvents.eventMoved, function() {\n CalendarViewManager.reloadCurrentMonth(root);\n });\n\n CalendarCrud.registerEditListeners(root, eventFormModalPromise);\n };\n\n /**\n * Register event listeners for the module.\n *\n * @param {object} root The calendar root element\n */\n var registerEventListeners = function(root) {\n const viewingFullCalendar = document.getElementById(CalendarSelectors.fullCalendarView);\n // Listen the click on the day link to render the day view.\n root.on('click', SELECTORS.VIEW_DAY_LINK, function(e) {\n var dayLink = $(e.target).closest(SELECTORS.VIEW_DAY_LINK);\n var year = dayLink.data('year'),\n month = dayLink.data('month'),\n day = dayLink.data('day'),\n courseId = dayLink.data('courseid'),\n categoryId = dayLink.data('categoryid');\n const url = '?view=day&time=' + dayLink.data('timestamp');\n if (viewingFullCalendar) {\n CalendarViewManager.refreshDayContent(root, year, month, day, courseId, categoryId, root,\n 'core_calendar/calendar_day').then(function() {\n e.preventDefault();\n return CalendarViewManager.updateUrl(url);\n }).fail(Notification.exception);\n } else {\n window.location.assign(Config.wwwroot + '/calendar/view.php' + url);\n }\n });\n\n root.on('change', CalendarSelectors.elements.courseSelector, function() {\n var selectElement = $(this);\n var courseId = selectElement.val();\n CalendarViewManager.reloadCurrentMonth(root, courseId, null)\n .then(function() {\n // We need to get the selector again because the content has changed.\n return root.find(CalendarSelectors.elements.courseSelector).val(courseId);\n })\n .fail(Notification.exception);\n });\n\n var eventFormPromise = CalendarCrud.registerEventFormModal(root),\n contextId = $(SELECTORS.CALENDAR_MONTH_WRAPPER).data('context-id');\n registerCalendarEventListeners(root, eventFormPromise);\n\n if (contextId) {\n // Bind click events to calendar days.\n root.on('click', SELECTORS.DAY, function(e) {\n var target = $(e.target);\n const displayingSmallBlockCalendar = root.parents('aside').data('blockregion') === 'side-pre';\n\n if (!viewingFullCalendar && displayingSmallBlockCalendar) {\n const dateContainer = target.closest(SELECTORS.DAY);\n const url = '?view=day&time=' + dateContainer.data('day-timestamp');\n window.location.assign(Config.wwwroot + '/calendar/view.php' + url);\n } else {\n const hasViewDayLink = target.closest(SELECTORS.VIEW_DAY_LINK);\n const shouldShowNewEventModal = !hasViewDayLink;\n if (shouldShowNewEventModal) {\n var startTime = $(this).attr('data-new-event-timestamp');\n eventFormPromise.then(function(modal) {\n var wrapper = target.closest(CalendarSelectors.wrapper);\n modal.setCourseId(wrapper.data('courseid'));\n\n var categoryId = wrapper.data('categoryid');\n if (typeof categoryId !== 'undefined') {\n modal.setCategoryId(categoryId);\n }\n\n modal.setContextId(wrapper.data('contextId'));\n modal.setStartTime(startTime);\n modal.show();\n return;\n }).fail(Notification.exception);\n }\n }\n e.preventDefault();\n });\n }\n };\n\n return {\n init: function(root) {\n root = $(root);\n CalendarViewManager.init(root);\n registerEventListeners(root);\n }\n };\n});\n"],"file":"calendar.min.js"}
\ No newline at end of file
+{"version":3,"sources":["../src/calendar.js"],"names":["define","$","Ajax","Str","Templates","Notification","CustomEvents","ModalEvents","ModalFactory","ModalEventForm","SummaryModal","CalendarRepository","CalendarEvents","CalendarViewManager","CalendarCrud","CalendarSelectors","Config","SELECTORS","ROOT","DAY","NEW_EVENT_BUTTON","DAY_CONTENT","LOADING_ICON","VIEW_DAY_LINK","CALENDAR_MONTH_WRAPPER","TODAY","DAY_NUMBER_CIRCLE","DAY_NUMBER","handleMoveEvent","e","eventId","originElement","destinationElement","originTimestamp","destinationTimestamp","attr","render","then","html","js","find","addClass","appendNodeContents","updateEventStartDay","trigger","eventMoved","always","destinationLoadingElement","removeClass","replaceNode","originLoadingElement","fail","exception","registerCalendarEventListeners","root","eventFormModalPromise","body","on","created","reloadCurrentMonth","deleted","updated","editActionEvent","url","window","location","assign","moveEvent","registerEditListeners","registerEventListeners","viewingFullCalendar","document","getElementById","fullCalendarView","dayLink","target","closest","year","data","month","day","courseId","categoryId","refreshDayContent","preventDefault","updateUrl","wwwroot","elements","courseSelector","selectElement","val","eventFormPromise","registerEventFormModal","contextId","displayingSmallBlockCalendar","parents","dateContainer","hasViewDayLink","length","startTime","modal","wrapper","setCourseId","setCategoryId","setContextId","setStartTime","show","init"],"mappings":"AA0BAA,OAAM,0BAAC,CACK,QADL,CAEK,WAFL,CAGK,UAHL,CAIK,gBAJL,CAKK,mBALL,CAMK,gCANL,CAOK,mBAPL,CAQK,oBARL,CASK,gCATL,CAUK,6BAVL,CAWK,0BAXL,CAYK,sBAZL,CAaK,4BAbL,CAcK,oBAdL,CAeK,yBAfL,CAgBK,aAhBL,CAAD,CAkBE,SACIC,CADJ,CAEIC,CAFJ,CAGIC,CAHJ,CAIIC,CAJJ,CAKIC,CALJ,CAMIC,CANJ,CAOIC,CAPJ,CAQIC,CARJ,CASIC,CATJ,CAUIC,CAVJ,CAWIC,CAXJ,CAYIC,CAZJ,CAaIC,CAbJ,CAcIC,CAdJ,CAeIC,CAfJ,CAgBIC,CAhBJ,CAiBE,IAEFC,CAAAA,CAAS,CAAG,CACZC,IAAI,CAAE,0BADM,CAEZC,GAAG,CAAE,qBAFO,CAGZC,gBAAgB,CAAE,kCAHN,CAIZC,WAAW,CAAE,6BAJD,CAKZC,YAAY,CAAE,eALF,CAMZC,aAAa,CAAE,+BANH,CAOZC,sBAAsB,CAAE,kBAPZ,CAQZC,KAAK,CAAE,QARK,CASZC,iBAAiB,CAAE,oBATP,CAUZC,UAAU,CAAE,aAVA,CAFV,CA2BFC,CAAe,CAAG,SAASC,CAAT,CAAYC,CAAZ,CAAqBC,CAArB,CAAoCC,CAApC,CAAwD,IACtEC,CAAAA,CAAe,CAAG,IADoD,CAEtEC,CAAoB,CAAGF,CAAkB,CAACG,IAAnB,CAAwB,oBAAxB,CAF+C,CAI1E,GAAIJ,CAAJ,CAAmB,CACfE,CAAe,CAAGF,CAAa,CAACI,IAAd,CAAmB,oBAAnB,CACrB,CAGD,GAAI,CAACJ,CAAD,EAAkBE,CAAe,E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,OAAP,CAAe3D,CAAS,CAACM,aAAzB,EAAwC2E,MAD5D,CAGH,GADgC,CAACD,CACjC,CAA6B,CACzB,GAAIE,CAAAA,CAAS,CAAGlG,CAAC,CAAC,IAAD,CAAD,CAAQkC,IAAR,CAAa,0BAAb,CAAhB,CACAwD,CAAgB,CAACtD,IAAjB,CAAsB,SAAS+D,CAAT,CAAgB,CAClC,GAAIC,CAAAA,CAAO,CAAG1B,CAAM,CAACC,OAAP,CAAe7D,CAAiB,CAACsF,OAAjC,CAAd,CACAD,CAAK,CAACE,WAAN,CAAkBD,CAAO,CAACvB,IAAR,CAAa,UAAb,CAAlB,EAEA,GAAII,CAAAA,CAAU,CAAGmB,CAAO,CAACvB,IAAR,CAAa,YAAb,CAAjB,CACA,GAA0B,WAAtB,QAAOI,CAAAA,CAAX,CAAuC,CACnCkB,CAAK,CAACG,aAAN,CAAoBrB,CAApB,CACH,CAEDkB,CAAK,CAACI,YAAN,CAAmBH,CAAO,CAACvB,IAAR,CAAa,WAAb,CAAnB,EACAsB,CAAK,CAACK,YAAN,CAAmBN,CAAnB,EACAC,CAAK,CAACM,IAAN,EAEH,CAbD,EAaGvD,IAbH,CAaQ9C,CAAY,CAAC+C,SAbrB,CAcH,CACJ,CACDvB,CAAC,CAACuD,cAAF,EACH,CA9BD,CA+BH,CACJ,CA1LK,CA4LN,MAAO,CACHuB,IAAI,CAAE,cAASrD,CAAT,CAAe,CACjBA,CAAI,CAAGrD,CAAC,CAACqD,CAAD,CAAR,CACAzC,CAAmB,CAAC8F,IAApB,CAAyBrD,CAAzB,EACAe,CAAsB,CAACf,CAAD,CACzB,CALE,CAOV,CAtOK,CAAN","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * This module is the highest level module for the calendar. It is\n * responsible for initialising all of the components required for\n * the calendar to run. It also coordinates the interaction between\n * components by listening for and responding to different events\n * triggered within the calendar UI.\n *\n * @module core_calendar/calendar\n * @copyright 2017 Simey Lameze \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine([\n 'jquery',\n 'core/ajax',\n 'core/str',\n 'core/templates',\n 'core/notification',\n 'core/custom_interaction_events',\n 'core/modal_events',\n 'core/modal_factory',\n 'core_calendar/modal_event_form',\n 'core_calendar/summary_modal',\n 'core_calendar/repository',\n 'core_calendar/events',\n 'core_calendar/view_manager',\n 'core_calendar/crud',\n 'core_calendar/selectors',\n 'core/config',\n ],\n function(\n $,\n Ajax,\n Str,\n Templates,\n Notification,\n CustomEvents,\n ModalEvents,\n ModalFactory,\n ModalEventForm,\n SummaryModal,\n CalendarRepository,\n CalendarEvents,\n CalendarViewManager,\n CalendarCrud,\n CalendarSelectors,\n Config,\n ) {\n\n var SELECTORS = {\n ROOT: \"[data-region='calendar']\",\n DAY: \"[data-region='day']\",\n NEW_EVENT_BUTTON: \"[data-action='new-event-button']\",\n DAY_CONTENT: \"[data-region='day-content']\",\n LOADING_ICON: '.loading-icon',\n VIEW_DAY_LINK: \"[data-action='view-day-link']\",\n CALENDAR_MONTH_WRAPPER: \".calendarwrapper\",\n TODAY: '.today',\n DAY_NUMBER_CIRCLE: '.day-number-circle',\n DAY_NUMBER: '.day-number'\n };\n\n /**\n * Handler for the drag and drop move event. Provides a loading indicator\n * while the request is sent to the server to update the event start date.\n *\n * Triggers a eventMoved calendar javascript event if the event was successfully\n * updated.\n *\n * @param {event} e The calendar move event\n * @param {int} eventId The event id being moved\n * @param {object|null} originElement The jQuery element for where the event is moving from\n * @param {object} destinationElement The jQuery element for where the event is moving to\n */\n var handleMoveEvent = function(e, eventId, originElement, destinationElement) {\n var originTimestamp = null;\n var destinationTimestamp = destinationElement.attr('data-day-timestamp');\n\n if (originElement) {\n originTimestamp = originElement.attr('data-day-timestamp');\n }\n\n // If the event has actually changed day.\n if (!originElement || originTimestamp != destinationTimestamp) {\n Templates.render('core/loading', {})\n .then(function(html, js) {\n // First we show some loading icons in each of the days being affected.\n destinationElement.find(SELECTORS.DAY_CONTENT).addClass('hidden');\n Templates.appendNodeContents(destinationElement, html, js);\n\n if (originElement) {\n originElement.find(SELECTORS.DAY_CONTENT).addClass('hidden');\n Templates.appendNodeContents(originElement, html, js);\n }\n return;\n })\n .then(function() {\n // Send a request to the server to make the change.\n return CalendarRepository.updateEventStartDay(eventId, destinationTimestamp);\n })\n .then(function() {\n // If the update was successful then broadcast an event letting the calendar\n // know that an event has been moved.\n $('body').trigger(CalendarEvents.eventMoved, [eventId, originElement, destinationElement]);\n return;\n })\n .always(function() {\n // Always remove the loading icons regardless of whether the update\n // request was successful or not.\n var destinationLoadingElement = destinationElement.find(SELECTORS.LOADING_ICON);\n destinationElement.find(SELECTORS.DAY_CONTENT).removeClass('hidden');\n Templates.replaceNode(destinationLoadingElement, '', '');\n\n if (originElement) {\n var originLoadingElement = originElement.find(SELECTORS.LOADING_ICON);\n originElement.find(SELECTORS.DAY_CONTENT).removeClass('hidden');\n Templates.replaceNode(originLoadingElement, '', '');\n }\n return;\n })\n .fail(Notification.exception);\n }\n };\n\n /**\n * Listen to and handle any calendar events fired by the calendar UI.\n *\n * @method registerCalendarEventListeners\n * @param {object} root The calendar root element\n * @param {object} eventFormModalPromise A promise reolved with the event form modal\n */\n var registerCalendarEventListeners = function(root, eventFormModalPromise) {\n var body = $('body');\n\n body.on(CalendarEvents.created, function() {\n CalendarViewManager.reloadCurrentMonth(root);\n });\n body.on(CalendarEvents.deleted, function() {\n CalendarViewManager.reloadCurrentMonth(root);\n });\n body.on(CalendarEvents.updated, function() {\n CalendarViewManager.reloadCurrentMonth(root);\n });\n body.on(CalendarEvents.editActionEvent, function(e, url) {\n // Action events needs to be edit directly on the course module.\n window.location.assign(url);\n });\n // Handle the event fired by the drag and drop code.\n body.on(CalendarEvents.moveEvent, handleMoveEvent);\n // When an event is successfully moved we should updated the UI.\n body.on(CalendarEvents.eventMoved, function() {\n CalendarViewManager.reloadCurrentMonth(root);\n });\n\n CalendarCrud.registerEditListeners(root, eventFormModalPromise);\n };\n\n /**\n * Register event listeners for the module.\n *\n * @param {object} root The calendar root element\n */\n var registerEventListeners = function(root) {\n const viewingFullCalendar = document.getElementById(CalendarSelectors.fullCalendarView);\n // Listen the click on the day link to render the day view.\n root.on('click', SELECTORS.VIEW_DAY_LINK, function(e) {\n var dayLink = $(e.target).closest(SELECTORS.VIEW_DAY_LINK);\n var year = dayLink.data('year'),\n month = dayLink.data('month'),\n day = dayLink.data('day'),\n courseId = dayLink.data('courseid'),\n categoryId = dayLink.data('categoryid');\n const url = '?view=day&time=' + dayLink.data('timestamp');\n if (viewingFullCalendar) {\n CalendarViewManager.refreshDayContent(root, year, month, day, courseId, categoryId, root,\n 'core_calendar/calendar_day').then(function() {\n e.preventDefault();\n return CalendarViewManager.updateUrl(url);\n }).fail(Notification.exception);\n } else {\n window.location.assign(Config.wwwroot + '/calendar/view.php' + url);\n }\n });\n\n root.on('change', CalendarSelectors.elements.courseSelector, function() {\n var selectElement = $(this);\n var courseId = selectElement.val();\n CalendarViewManager.reloadCurrentMonth(root, courseId, null)\n .then(function() {\n // We need to get the selector again because the content has changed.\n return root.find(CalendarSelectors.elements.courseSelector).val(courseId);\n })\n .fail(Notification.exception);\n });\n\n var eventFormPromise = CalendarCrud.registerEventFormModal(root),\n contextId = $(SELECTORS.CALENDAR_MONTH_WRAPPER).data('context-id');\n registerCalendarEventListeners(root, eventFormPromise);\n\n if (contextId) {\n // Bind click events to calendar days.\n root.on('click', SELECTORS.DAY, function(e) {\n var target = $(e.target);\n const displayingSmallBlockCalendar = root.parents('aside').data('blockregion') === 'side-pre';\n\n if (!viewingFullCalendar && displayingSmallBlockCalendar) {\n const dateContainer = target.closest(SELECTORS.DAY);\n const url = '?view=day&time=' + dateContainer.data('day-timestamp');\n window.location.assign(Config.wwwroot + '/calendar/view.php' + url);\n } else {\n const hasViewDayLink = target.closest(SELECTORS.VIEW_DAY_LINK).length;\n const shouldShowNewEventModal = !hasViewDayLink;\n if (shouldShowNewEventModal) {\n var startTime = $(this).attr('data-new-event-timestamp');\n eventFormPromise.then(function(modal) {\n var wrapper = target.closest(CalendarSelectors.wrapper);\n modal.setCourseId(wrapper.data('courseid'));\n\n var categoryId = wrapper.data('categoryid');\n if (typeof categoryId !== 'undefined') {\n modal.setCategoryId(categoryId);\n }\n\n modal.setContextId(wrapper.data('contextId'));\n modal.setStartTime(startTime);\n modal.show();\n return;\n }).fail(Notification.exception);\n }\n }\n e.preventDefault();\n });\n }\n };\n\n return {\n init: function(root) {\n root = $(root);\n CalendarViewManager.init(root);\n registerEventListeners(root);\n }\n };\n});\n"],"file":"calendar.min.js"}
\ No newline at end of file
diff --git a/calendar/amd/src/calendar.js b/calendar/amd/src/calendar.js
index fc9eca40b277f..6523169e2e5c2 100644
--- a/calendar/amd/src/calendar.js
+++ b/calendar/amd/src/calendar.js
@@ -222,7 +222,7 @@ define([
const url = '?view=day&time=' + dateContainer.data('day-timestamp');
window.location.assign(Config.wwwroot + '/calendar/view.php' + url);
} else {
- const hasViewDayLink = target.closest(SELECTORS.VIEW_DAY_LINK);
+ const hasViewDayLink = target.closest(SELECTORS.VIEW_DAY_LINK).length;
const shouldShowNewEventModal = !hasViewDayLink;
if (shouldShowNewEventModal) {
var startTime = $(this).attr('data-new-event-timestamp');