From c8435454a70baf7ea445dc711a6538de7fd1768e Mon Sep 17 00:00:00 2001 From: Shamim Rezaie Date: Wed, 20 Nov 2019 21:16:10 +1100 Subject: [PATCH] MDL-67152 calendar: The day view should start from the current day --- calendar/amd/build/repository.min.js | 2 +- calendar/amd/build/repository.min.js.map | 2 +- calendar/amd/build/view_manager.min.js | 2 +- calendar/amd/build/view_manager.min.js.map | 2 +- calendar/amd/src/repository.js | 11 +++++++---- calendar/amd/src/view_manager.js | 20 +++++++++++++------- calendar/externallib.php | 9 ++++++--- calendar/templates/month_mini.mustache | 1 + calendar/tests/externallib_test.php | 22 +++++++++++++++++++--- 9 files changed, 50 insertions(+), 21 deletions(-) diff --git a/calendar/amd/build/repository.min.js b/calendar/amd/build/repository.min.js index 55d3e1e34b6..a5c672efc1f 100644 --- a/calendar/amd/build/repository.min.js +++ b/calendar/amd/build/repository.min.js @@ -1,2 +1,2 @@ -define ("core_calendar/repository",["jquery","core/ajax"],function(a,b){return{getEventById:function getEventById(a){return b.call([{methodname:"core_calendar_get_calendar_event_by_id",args:{eventid:a}}])[0]},deleteEvent:function deleteEvent(a,c){if("undefined"==typeof c){c=!1}var d={methodname:"core_calendar_delete_calendar_events",args:{events:[{eventid:a,repeat:c}]}};return b.call([d])[0]},updateEventStartDay:function updateEventStartDay(a,c){return b.call([{methodname:"core_calendar_update_event_start_day",args:{eventid:a,daytimestamp:c}}])[0]},submitCreateUpdateForm:function submitCreateUpdateForm(a){return b.call([{methodname:"core_calendar_submit_create_update_form",args:{formdata:a}}])[0]},getCalendarMonthData:function getCalendarMonthData(a,c,d,e,f,g){return b.call([{methodname:"core_calendar_get_calendar_monthly_view",args:{year:a,month:c,courseid:d,categoryid:e,includenavigation:f,mini:g}}])[0]},getCalendarDayData:function getCalendarDayData(a,c,d,e,f){return b.call([{methodname:"core_calendar_get_calendar_day_view",args:{year:a,month:c,day:d,courseid:e,categoryid:f}}])[0]},getCalendarUpcomingData:function getCalendarUpcomingData(a,c){return b.call([{methodname:"core_calendar_get_calendar_upcoming_view",args:{courseid:a,categoryid:c}}])[0]},getCourseGroupsData:function getCourseGroupsData(a){return b.call([{methodname:"core_group_get_course_groups",args:{courseid:a}}])[0]}}}); +define ("core_calendar/repository",["jquery","core/ajax"],function(a,b){return{getEventById:function getEventById(a){return b.call([{methodname:"core_calendar_get_calendar_event_by_id",args:{eventid:a}}])[0]},deleteEvent:function deleteEvent(a,c){if("undefined"==typeof c){c=!1}var d={methodname:"core_calendar_delete_calendar_events",args:{events:[{eventid:a,repeat:c}]}};return b.call([d])[0]},updateEventStartDay:function updateEventStartDay(a,c){return b.call([{methodname:"core_calendar_update_event_start_day",args:{eventid:a,daytimestamp:c}}])[0]},submitCreateUpdateForm:function submitCreateUpdateForm(a){return b.call([{methodname:"core_calendar_submit_create_update_form",args:{formdata:a}}])[0]},getCalendarMonthData:function getCalendarMonthData(a,c,d,e,f,g,h){h=h||1;var i={methodname:"core_calendar_get_calendar_monthly_view",args:{year:a,month:c,courseid:d,categoryid:e,includenavigation:f,mini:g,day:h}};return b.call([i])[0]},getCalendarDayData:function getCalendarDayData(a,c,d,e,f){return b.call([{methodname:"core_calendar_get_calendar_day_view",args:{year:a,month:c,day:d,courseid:e,categoryid:f}}])[0]},getCalendarUpcomingData:function getCalendarUpcomingData(a,c){return b.call([{methodname:"core_calendar_get_calendar_upcoming_view",args:{courseid:a,categoryid:c}}])[0]},getCourseGroupsData:function getCourseGroupsData(a){return b.call([{methodname:"core_group_get_course_groups",args:{courseid:a}}])[0]}}}); //# sourceMappingURL=repository.min.js.map diff --git a/calendar/amd/build/repository.min.js.map b/calendar/amd/build/repository.min.js.map index 368cbd89dc2..74c07abc343 100644 --- a/calendar/amd/build/repository.min.js.map +++ b/calendar/amd/build/repository.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/repository.js"],"names":["define","$","Ajax","getEventById","eventId","call","methodname","args","eventid","deleteEvent","deleteSeries","request","events","repeat","updateEventStartDay","dayTimestamp","daytimestamp","submitCreateUpdateForm","formdata","getCalendarMonthData","year","month","courseid","categoryid","includenavigation","mini","getCalendarDayData","day","categoryId","getCalendarUpcomingData","getCourseGroupsData"],"mappings":"AAwBAA,OAAM,4BAAC,CAAC,QAAD,CAAW,WAAX,CAAD,CAA0B,SAASC,CAAT,CAAYC,CAAZ,CAAkB,CAgL9C,MAAO,CACHC,YAAY,CA/IG,QAAfA,CAAAA,YAAe,CAASC,CAAT,CAAkB,CASjC,MAAOF,CAAAA,CAAI,CAACG,IAAL,CAAU,CAPH,CACVC,UAAU,CAAE,wCADF,CAEVC,IAAI,CAAE,CACFC,OAAO,CAAEJ,CADP,CAFI,CAOG,CAAV,EAAqB,CAArB,CACV,CAoIM,CAEHK,WAAW,CAxKG,QAAdA,CAAAA,WAAc,CAASL,CAAT,CAAkBM,CAAlB,CAAgC,CAC9C,GAA4B,WAAxB,QAAOA,CAAAA,CAAX,CAAyC,CACrCA,CAAY,GACf,CACD,GAAIC,CAAAA,CAAO,CAAG,CACVL,UAAU,CAAE,sCADF,CAEVC,IAAI,CAAE,CACFK,MAAM,CAAE,CAAC,CACLJ,OAAO,CAAEJ,CADJ,CAELS,MAAM,CAAEH,CAFH,CAAD,CADN,CAFI,CAAd,CAUA,MAAOR,CAAAA,CAAI,CAACG,IAAL,CAAU,CAACM,CAAD,CAAV,EAAqB,CAArB,CACV,CAuJM,CAGHG,mBAAmB,CApDG,QAAtBA,CAAAA,mBAAsB,CAASV,CAAT,CAAkBW,CAAlB,CAAgC,CAStD,MAAOb,CAAAA,CAAI,CAACG,IAAL,CAAU,CARH,CACVC,UAAU,CAAE,sCADF,CAEVC,IAAI,CAAE,CACFC,OAAO,CAAEJ,CADP,CAEFY,YAAY,CAAED,CAFZ,CAFI,CAQG,CAAV,EAAqB,CAArB,CACV,CAuCM,CAIHE,sBAAsB,CA/HG,QAAzBA,CAAAA,sBAAyB,CAASC,CAAT,CAAmB,CAQ5C,MAAOhB,CAAAA,CAAI,CAACG,IAAL,CAAU,CAPH,CACV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AnBG,QAAtBA,CAAAA,mBAAsB,CAASR,CAAT,CAAmB,CAQzC,MAAOpB,CAAAA,CAAI,CAACG,IAAL,CAAU,CAPH,CACVC,UAAU,CAAE,8BADF,CAEVC,IAAI,CAAE,CACFe,QAAQ,CAAEA,CADR,CAFI,CAOG,CAAV,EAAqB,CAArB,CACV,CAEM,CAUV,CA1LK,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 * A javascript module to handle calendar ajax actions.\n *\n * @module core_calendar/repository\n * @class repository\n * @package core_calendar\n * @copyright 2017 Simey Lameze \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(['jquery', 'core/ajax'], function($, Ajax) {\n\n /**\n * Delete a calendar event.\n *\n * @method deleteEvent\n * @param {int} eventId The event id.\n * @param {bool} deleteSeries Whether to delete all events in the series\n * @return {promise} Resolved with requested calendar event\n */\n var deleteEvent = function(eventId, deleteSeries) {\n if (typeof deleteSeries === 'undefined') {\n deleteSeries = false;\n }\n var request = {\n methodname: 'core_calendar_delete_calendar_events',\n args: {\n events: [{\n eventid: eventId,\n repeat: deleteSeries,\n }]\n }\n };\n\n return Ajax.call([request])[0];\n };\n\n /**\n * Get a calendar event by id.\n *\n * @method getEventById\n * @param {int} eventId The event id.\n * @return {promise} Resolved with requested calendar event\n */\n var getEventById = function(eventId) {\n\n var request = {\n methodname: 'core_calendar_get_calendar_event_by_id',\n args: {\n eventid: eventId\n }\n };\n\n return Ajax.call([request])[0];\n };\n\n /**\n * Submit the form data for the event form.\n *\n * @method submitCreateUpdateForm\n * @param {string} formdata The URL encoded values from the form\n * @return {promise} Resolved with the new or edited event\n */\n var submitCreateUpdateForm = function(formdata) {\n var request = {\n methodname: 'core_calendar_submit_create_update_form',\n args: {\n formdata: formdata\n }\n };\n\n return Ajax.call([request])[0];\n };\n\n /**\n * Get calendar data for the month view.\n *\n * @method getCalendarMonthData\n * @param {Number} year Year\n * @param {Number} month Month\n * @param {Number} courseid The course id.\n * @param {Number} categoryid The category id.\n * @param {Bool} includenavigation Whether to include navigation.\n * @param {Bool} mini Whether the month is in mini view.\n * @return {promise} Resolved with the month view data.\n */\n var getCalendarMonthData = function(year, month, courseid, categoryid, includenavigation, mini) {\n var request = {\n methodname: 'core_calendar_get_calendar_monthly_view',\n args: {\n year: year,\n month: month,\n courseid: courseid,\n categoryid: categoryid,\n includenavigation: includenavigation,\n mini: mini\n }\n };\n\n return Ajax.call([request])[0];\n };\n\n /**\n * Get calendar data for the day view.\n *\n * @method getCalendarDayData\n * @param {Number} year Year\n * @param {Number} month Month\n * @param {Number} day Day\n * @param {Number} courseid The course id.\n * @param {Number} categoryId The id of the category whose events are shown\n * @return {promise} Resolved with the day view data.\n */\n var getCalendarDayData = function(year, month, day, courseid, categoryId) {\n var request = {\n methodname: 'core_calendar_get_calendar_day_view',\n args: {\n year: year,\n month: month,\n day: day,\n courseid: courseid,\n categoryid: categoryId,\n }\n };\n\n return Ajax.call([request])[0];\n };\n\n /**\n * Change the start day for the given event id. The day timestamp\n * only has to be any time during the target day because only the\n * date information is extracted, the time of the day is ignored.\n *\n * @param {int} eventId The id of the event to update\n * @param {int} dayTimestamp A timestamp for some time during the target day\n * @return {promise}\n */\n var updateEventStartDay = function(eventId, dayTimestamp) {\n var request = {\n methodname: 'core_calendar_update_event_start_day',\n args: {\n eventid: eventId,\n daytimestamp: dayTimestamp\n }\n };\n\n return Ajax.call([request])[0];\n };\n\n /**\n * Get calendar upcoming data.\n *\n * @method getCalendarUpcomingData\n * @param {Number} courseid The course id.\n * @param {Number} categoryid The category id.\n * @return {promise} Resolved with the month view data.\n */\n var getCalendarUpcomingData = function(courseid, categoryid) {\n var request = {\n methodname: 'core_calendar_get_calendar_upcoming_view',\n args: {\n courseid: courseid,\n categoryid: categoryid,\n }\n };\n\n return Ajax.call([request])[0];\n };\n\n /**\n * Get the groups by course id.\n *\n * @param {Number} courseid The course id to fetch the groups from.\n * @return {promise} Resolved with the course groups.\n */\n var getCourseGroupsData = function(courseid) {\n var request = {\n methodname: 'core_group_get_course_groups',\n args: {\n courseid: courseid\n }\n };\n\n return Ajax.call([request])[0];\n };\n\n return {\n getEventById: getEventById,\n deleteEvent: deleteEvent,\n updateEventStartDay: updateEventStartDay,\n submitCreateUpdateForm: submitCreateUpdateForm,\n getCalendarMonthData: getCalendarMonthData,\n getCalendarDayData: getCalendarDayData,\n getCalendarUpcomingData: getCalendarUpcomingData,\n getCourseGroupsData: getCourseGroupsData\n };\n});\n"],"file":"repository.min.js"} \ No newline at end of file +{"version":3,"sources":["../src/repository.js"],"names":["define","$","Ajax","getEventById","eventId","call","methodname","args","eventid","deleteEvent","deleteSeries","request","events","repeat","updateEventStartDay","dayTimestamp","daytimestamp","submitCreateUpdateForm","formdata","getCalendarMonthData","year","month","courseid","categoryid","includenavigation","mini","day","getCalendarDayData","categoryId","getCalendarUpcomingData","getCourseGroupsData"],"mappings":"AAwBAA,OAAM,4BAAC,CAAC,QAAD,CAAW,WAAX,CAAD,CAA0B,SAASC,CAAT,CAAYC,CAAZ,CAAkB,CAmL9C,MAAO,CACHC,YAAY,CAlJG,QAAfA,CAAAA,YAAe,CAASC,CAAT,CAAkB,CASjC,MAAOF,CAAAA,CAAI,CAACG,IAAL,CAAU,CAPH,CACVC,UAAU,CAAE,wCADF,CAEVC,IAAI,CAAE,CACFC,OAAO,CAAEJ,CADP,CAFI,CAOG,CAAV,EAAqB,CAArB,CACV,CAuIM,CAEHK,WAAW,CA3KG,QAAdA,CAAAA,WAAc,CAASL,CAAT,CAAkBM,CAAlB,C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A,CALjB,CAMFC,IAAI,CAAEA,CANJ,CAOFC,GAAG,CAAEA,CAPH,CAFI,CAAd,CAaA,MAAOxB,CAAAA,CAAI,CAACG,IAAL,CAAU,CAACM,CAAD,CAAV,EAAqB,CAArB,CACV,CAsFM,CAMHgB,kBAAkB,CA/EG,QAArBA,CAAAA,kBAAqB,CAASP,CAAT,CAAeC,CAAf,CAAsBK,CAAtB,CAA2BJ,CAA3B,CAAqCM,CAArC,CAAiD,CAYtE,MAAO1B,CAAAA,CAAI,CAACG,IAAL,CAAU,CAXH,CACVC,UAAU,CAAE,qCADF,CAEVC,IAAI,CAAE,CACFa,IAAI,CAAEA,CADJ,CAEFC,KAAK,CAAEA,CAFL,CAGFK,GAAG,CAAEA,CAHH,CAIFJ,QAAQ,CAAEA,CAJR,CAKFC,UAAU,CAAEK,CALV,CAFI,CAWG,CAAV,EAAqB,CAArB,CACV,CA4DM,CAOHC,uBAAuB,CApCG,QAA1BA,CAAAA,uBAA0B,CAASP,CAAT,CAAmBC,CAAnB,CAA+B,CASzD,MAAOrB,CAAAA,CAAI,CAACG,IAAL,CAAU,CARH,CACVC,UAAU,CAAE,0CADF,CAEVC,IAAI,CAAE,CACFe,QAAQ,CAAEA,CADR,CAEFC,UAAU,CAAEA,CAFV,CAFI,CAQG,CAAV,EAAqB,CAArB,CACV,CAmBM,CAQHO,mBAAmB,CAnBG,QAAtBA,CAAAA,mBAAsB,CAASR,CAAT,CAAmB,CAQzC,MAAOpB,CAAAA,CAAI,CAACG,IAAL,CAAU,CAPH,CACVC,UAAU,CAAE,8BADF,CAEVC,IAAI,CAAE,CACFe,QAAQ,CAAEA,CADR,CAFI,CAOG,CAAV,EAAqB,CAArB,CACV,CAEM,CAUV,CA7LK,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 * A javascript module to handle calendar ajax actions.\n *\n * @module core_calendar/repository\n * @class repository\n * @package core_calendar\n * @copyright 2017 Simey Lameze \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(['jquery', 'core/ajax'], function($, Ajax) {\n\n /**\n * Delete a calendar event.\n *\n * @method deleteEvent\n * @param {int} eventId The event id.\n * @param {bool} deleteSeries Whether to delete all events in the series\n * @return {promise} Resolved with requested calendar event\n */\n var deleteEvent = function(eventId, deleteSeries) {\n if (typeof deleteSeries === 'undefined') {\n deleteSeries = false;\n }\n var request = {\n methodname: 'core_calendar_delete_calendar_events',\n args: {\n events: [{\n eventid: eventId,\n repeat: deleteSeries,\n }]\n }\n };\n\n return Ajax.call([request])[0];\n };\n\n /**\n * Get a calendar event by id.\n *\n * @method getEventById\n * @param {int} eventId The event id.\n * @return {promise} Resolved with requested calendar event\n */\n var getEventById = function(eventId) {\n\n var request = {\n methodname: 'core_calendar_get_calendar_event_by_id',\n args: {\n eventid: eventId\n }\n };\n\n return Ajax.call([request])[0];\n };\n\n /**\n * Submit the form data for the event form.\n *\n * @method submitCreateUpdateForm\n * @param {string} formdata The URL encoded values from the form\n * @return {promise} Resolved with the new or edited event\n */\n var submitCreateUpdateForm = function(formdata) {\n var request = {\n methodname: 'core_calendar_submit_create_update_form',\n args: {\n formdata: formdata\n }\n };\n\n return Ajax.call([request])[0];\n };\n\n /**\n * Get calendar data for the month view.\n *\n * @method getCalendarMonthData\n * @param {Number} year Year\n * @param {Number} month Month\n * @param {Number} courseid The course id.\n * @param {Number} categoryid The category id.\n * @param {Boolean} includenavigation Whether to include navigation.\n * @param {Boolean} mini Whether the month is in mini view.\n * @param {Number} day Day (optional)\n * @return {promise} Resolved with the month view data.\n */\n var getCalendarMonthData = function(year, month, courseid, categoryid, includenavigation, mini, day) {\n day = day || 1;\n var request = {\n methodname: 'core_calendar_get_calendar_monthly_view',\n args: {\n year: year,\n month: month,\n courseid: courseid,\n categoryid: categoryid,\n includenavigation: includenavigation,\n mini: mini,\n day: day\n }\n };\n\n return Ajax.call([request])[0];\n };\n\n /**\n * Get calendar data for the day view.\n *\n * @method getCalendarDayData\n * @param {Number} year Year\n * @param {Number} month Month\n * @param {Number} day Day\n * @param {Number} courseid The course id.\n * @param {Number} categoryId The id of the category whose events are shown\n * @return {promise} Resolved with the day view data.\n */\n var getCalendarDayData = function(year, month, day, courseid, categoryId) {\n var request = {\n methodname: 'core_calendar_get_calendar_day_view',\n args: {\n year: year,\n month: month,\n day: day,\n courseid: courseid,\n categoryid: categoryId,\n }\n };\n\n return Ajax.call([request])[0];\n };\n\n /**\n * Change the start day for the given event id. The day timestamp\n * only has to be any time during the target day because only the\n * date information is extracted, the time of the day is ignored.\n *\n * @param {int} eventId The id of the event to update\n * @param {int} dayTimestamp A timestamp for some time during the target day\n * @return {promise}\n */\n var updateEventStartDay = function(eventId, dayTimestamp) {\n var request = {\n methodname: 'core_calendar_update_event_start_day',\n args: {\n eventid: eventId,\n daytimestamp: dayTimestamp\n }\n };\n\n return Ajax.call([request])[0];\n };\n\n /**\n * Get calendar upcoming data.\n *\n * @method getCalendarUpcomingData\n * @param {Number} courseid The course id.\n * @param {Number} categoryid The category id.\n * @return {promise} Resolved with the month view data.\n */\n var getCalendarUpcomingData = function(courseid, categoryid) {\n var request = {\n methodname: 'core_calendar_get_calendar_upcoming_view',\n args: {\n courseid: courseid,\n categoryid: categoryid,\n }\n };\n\n return Ajax.call([request])[0];\n };\n\n /**\n * Get the groups by course id.\n *\n * @param {Number} courseid The course id to fetch the groups from.\n * @return {promise} Resolved with the course groups.\n */\n var getCourseGroupsData = function(courseid) {\n var request = {\n methodname: 'core_group_get_course_groups',\n args: {\n courseid: courseid\n }\n };\n\n return Ajax.call([request])[0];\n };\n\n return {\n getEventById: getEventById,\n deleteEvent: deleteEvent,\n updateEventStartDay: updateEventStartDay,\n submitCreateUpdateForm: submitCreateUpdateForm,\n getCalendarMonthData: getCalendarMonthData,\n getCalendarDayData: getCalendarDayData,\n getCalendarUpcomingData: getCalendarUpcomingData,\n getCourseGroupsData: getCourseGroupsData\n };\n});\n"],"file":"repository.min.js"} \ No newline at end of file diff --git a/calendar/amd/build/view_manager.min.js b/calendar/amd/build/view_manager.min.js index 79f116ce8e8..e27e2d0aa8f 100644 --- a/calendar/amd/build/view_manager.min.js +++ b/calendar/amd/build/view_manager.min.js @@ -1,2 +1,2 @@ -define ("core_calendar/view_manager",["jquery","core/templates","core/str","core/notification","core_calendar/repository","core_calendar/events","core_calendar/selectors","core/modal_factory","core/modal_events","core_calendar/summary_modal","core/custom_interaction_events"],function(a,b,c,d,e,f,g,h,i,j,k){var l=function(b){b=a(b);b.on("click",g.links.eventLink,function(b){var c=a(b.target),d=null,e;if(c.is(g.actions.viewEvent)){e=c}else{e=c.closest(g.actions.viewEvent)}if(e.length){d=e.data("eventId")}else{d=c.find(g.actions.viewEvent).data("eventId")}if(d){b.preventDefault();b.stopPropagation();u(d)}});b.on("click",g.links.navLink,function(c){var d=b.find(g.wrapper),e=d.data("view"),f=d.data("courseid"),h=d.data("categoryid"),i=a(c.currentTarget);if("month"===e){n(b,i.attr("href"),i.data("year"),i.data("month"),f,h);c.preventDefault()}else if("day"===e){p(b,i.attr("href"),i.data("year"),i.data("month"),i.data("day"),f,h);c.preventDefault()}});var c=b.find(g.viewSelector);k.define(c,[k.events.activate]);c.on(k.events.activate,function(c){c.preventDefault();var e=a(c.target);if(e.hasClass("active")){return}var f=e.data("view"),g=e.data("year"),h=e.data("month"),i=e.data("day"),j=e.data("courseid"),k=e.data("categoryid");if("month"==f){m(b,g,h,j,k,b,"core_calendar/calendar_month").then(function(){return window.history.pushState({},"","?view=month")}).fail(d.exception)}else if("day"==f){o(b,g,h,i,j,k,b,"core_calendar/calendar_day").then(function(){return window.history.pushState({},"","?view=day")}).fail(d.exception)}else if("upcoming"==f){s(b,j,k,b,"core_calendar/calendar_upcoming").then(function(){return window.history.pushState({},"","?view=upcoming")}).fail(d.exception)}})},m=function(c,h,i,j,k,l,m){q(c);l=l||c.find(g.wrapper);m=m||c.attr("data-template");M.util.js_pending([c.get("id"),h,i,j].join("-"));var n=c.data("includenavigation"),o=c.data("mini");return e.getCalendarMonthData(h,i,j,k,n,o).then(function(a){a.viewingmonth=!0;return b.render(m,a)}).then(function(a,c){return b.replaceNode(l,a,c)}).then(function(){a("body").trigger(f.viewUpdated)}).always(function(){M.util.js_complete([c.get("id"),h,i,j].join("-"));return r(c)}).fail(d.exception)},n=function(b,c,d,e,g,h){return m(b,d,e,g,h).then(function(){if(c.length&&"#"!==c){window.history.pushState({},"",c)}return arguments}).then(function(){a("body").trigger(f.monthChanged,[d,e,g,h]);return arguments})},o=function(c,h,i,j,k,l,m,n){q(c);m=m||c.find(g.wrapper);n=n||c.attr("data-template");M.util.js_pending([c.get("id"),h,i,j,k,l].join("-"));var o=c.data("includenavigation");return e.getCalendarDayData(h,i,j,k,l,o).then(function(a){a.viewingday=!0;return b.render(n,a)}).then(function(a,c){return b.replaceNode(m,a,c)}).then(function(){a("body").trigger(f.viewUpdated)}).always(function(){M.util.js_complete([c.get("id"),h,i,j,k,l].join("-"));return r(c)}).fail(d.exception)},p=function(b,c,d,e,g,h,i){return o(b,d,e,g,h,i).then(function(){if(c.length&&"#"!==c){window.history.pushState({},"",c)}return arguments}).then(function(){a("body").trigger(f.dayChanged,[d,e,h,i]);return arguments})},q=function(a){var b=a.find(g.containers.loadingIcon);b.removeClass("hidden")},r=function(a){var b=a.find(g.containers.loadingIcon);b.addClass("hidden")},s=function(c,h,i,j,k){q(c);j=j||c.find(g.wrapper);k=k||c.attr("data-template");if("undefined"==typeof h){h=c.find(g.wrapper).data("courseid")}if("undefined"==typeof i){i=c.find(g.wrapper).data("categoryid")}return e.getCalendarUpcomingData(h,i).then(function(a){a.viewingupcoming=!0;return b.render(k,a)}).then(function(a,c){return b.replaceNode(j,a,c)}).then(function(){a("body").trigger(f.viewUpdated)}).always(function(){return r(c)}).fail(d.exception)},t=function(a){return"calendar_event_"+a},u=function(a){var c="";e.getEventById(a).then(function(b){if(!b.event){throw new Error("Error encountered while trying to fetch calendar event with ID: "+a)}var d=b.event;c=t(d.normalisedeventtype);return d}).then(function(a){var d={title:a.name,type:j.TYPE,body:b.render("core_calendar/event_summary_body",a),templateContext:{canedit:a.canedit,candelete:a.candelete,headerclasses:c,isactionevent:a.isactionevent,url:a.url}};return h.create(d)}).done(function(a){a.getRoot().on(i.hidden,function(){a.destroy()});a.show()}).fail(d.exception)};return{init:function init(a,b){l(a,b)},reloadCurrentMonth:function reloadCurrentMonth(a,b,c){var d=a.find(g.wrapper).data("year"),e=a.find(g.wrapper).data("month");if("undefined"==typeof b){b=a.find(g.wrapper).data("courseid")}if("undefined"==typeof c){c=a.find(g.wrapper).data("categoryid")}return m(a,d,e,b,c)},changeMonth:n,refreshMonthContent:m,reloadCurrentDay:function reloadCurrentDay(a,b,c){var d=a.find(g.wrapper),e=d.data("year"),f=d.data("month"),h=d.data("day");if(!b){b=a.find(g.wrapper).data("courseid")}if("undefined"==typeof c){c=a.find(g.wrapper).data("categoryid")}return o(a,e,f,h,b,c)},changeDay:p,refreshDayContent:o,reloadCurrentUpcoming:s}}); +define ("core_calendar/view_manager",["jquery","core/templates","core/str","core/notification","core_calendar/repository","core_calendar/events","core_calendar/selectors","core/modal_factory","core/modal_events","core_calendar/summary_modal","core/custom_interaction_events"],function(a,b,c,d,e,f,g,h,i,j,k){var l=function(b){b=a(b);b.on("click",g.links.eventLink,function(b){var c=a(b.target),d=null,e;if(c.is(g.actions.viewEvent)){e=c}else{e=c.closest(g.actions.viewEvent)}if(e.length){d=e.data("eventId")}else{d=c.find(g.actions.viewEvent).data("eventId")}if(d){b.preventDefault();b.stopPropagation();u(d)}});b.on("click",g.links.navLink,function(c){var d=b.find(g.wrapper),e=d.data("view"),f=d.data("courseid"),h=d.data("categoryid"),i=a(c.currentTarget);if("month"===e){n(b,i.attr("href"),i.data("year"),i.data("month"),f,h,i.data("day"));c.preventDefault()}else if("day"===e){p(b,i.attr("href"),i.data("year"),i.data("month"),i.data("day"),f,h);c.preventDefault()}});var c=b.find(g.viewSelector);k.define(c,[k.events.activate]);c.on(k.events.activate,function(c){c.preventDefault();var e=a(c.target);if(e.hasClass("active")){return}var f=e.data("view"),g=e.data("year"),h=e.data("month"),i=e.data("day"),j=e.data("courseid"),k=e.data("categoryid");if("month"==f){m(b,g,h,j,k,b,"core_calendar/calendar_month",i).then(function(){return window.history.pushState({},"","?view=month")}).fail(d.exception)}else if("day"==f){o(b,g,h,i,j,k,b,"core_calendar/calendar_day").then(function(){return window.history.pushState({},"","?view=day")}).fail(d.exception)}else if("upcoming"==f){s(b,j,k,b,"core_calendar/calendar_upcoming").then(function(){return window.history.pushState({},"","?view=upcoming")}).fail(d.exception)}})},m=function(c,h,i,j,k,l,m,n){q(c);l=l||c.find(g.wrapper);m=m||c.attr("data-template");n=n||1;M.util.js_pending([c.get("id"),h,i,j].join("-"));var o=c.data("includenavigation"),p=c.data("mini");return e.getCalendarMonthData(h,i,j,k,o,p,n).then(function(a){a.viewingmonth=!0;return b.render(m,a)}).then(function(a,c){return b.replaceNode(l,a,c)}).then(function(){a("body").trigger(f.viewUpdated)}).always(function(){M.util.js_complete([c.get("id"),h,i,j].join("-"));return r(c)}).fail(d.exception)},n=function(b,c,d,e,g,h,i){i=i||1;return m(b,d,e,g,h,null,null,i).then(function(){if(c.length&&"#"!==c){window.history.pushState({},"",c)}return arguments}).then(function(){a("body").trigger(f.monthChanged,[d,e,g,h]);return arguments})},o=function(c,h,i,j,k,l,m,n){q(c);m=m||c.find(g.wrapper);n=n||c.attr("data-template");M.util.js_pending([c.get("id"),h,i,j,k,l].join("-"));var o=c.data("includenavigation");return e.getCalendarDayData(h,i,j,k,l,o).then(function(a){a.viewingday=!0;return b.render(n,a)}).then(function(a,c){return b.replaceNode(m,a,c)}).then(function(){a("body").trigger(f.viewUpdated)}).always(function(){M.util.js_complete([c.get("id"),h,i,j,k,l].join("-"));return r(c)}).fail(d.exception)},p=function(b,c,d,e,g,h,i){return o(b,d,e,g,h,i).then(function(){if(c.length&&"#"!==c){window.history.pushState({},"",c)}return arguments}).then(function(){a("body").trigger(f.dayChanged,[d,e,h,i]);return arguments})},q=function(a){var b=a.find(g.containers.loadingIcon);b.removeClass("hidden")},r=function(a){var b=a.find(g.containers.loadingIcon);b.addClass("hidden")},s=function(c,h,i,j,k){q(c);j=j||c.find(g.wrapper);k=k||c.attr("data-template");if("undefined"==typeof h){h=c.find(g.wrapper).data("courseid")}if("undefined"==typeof i){i=c.find(g.wrapper).data("categoryid")}return e.getCalendarUpcomingData(h,i).then(function(a){a.viewingupcoming=!0;return b.render(k,a)}).then(function(a,c){return b.replaceNode(j,a,c)}).then(function(){a("body").trigger(f.viewUpdated)}).always(function(){return r(c)}).fail(d.exception)},t=function(a){return"calendar_event_"+a},u=function(a){var c="";e.getEventById(a).then(function(b){if(!b.event){throw new Error("Error encountered while trying to fetch calendar event with ID: "+a)}var d=b.event;c=t(d.normalisedeventtype);return d}).then(function(a){var d={title:a.name,type:j.TYPE,body:b.render("core_calendar/event_summary_body",a),templateContext:{canedit:a.canedit,candelete:a.candelete,headerclasses:c,isactionevent:a.isactionevent,url:a.url}};return h.create(d)}).done(function(a){a.getRoot().on(i.hidden,function(){a.destroy()});a.show()}).fail(d.exception)};return{init:function init(a,b){l(a,b)},reloadCurrentMonth:function reloadCurrentMonth(a,b,c){var d=a.find(g.wrapper).data("year"),e=a.find(g.wrapper).data("month"),f=a.find(g.wrapper).data("day");if("undefined"==typeof b){b=a.find(g.wrapper).data("courseid")}if("undefined"==typeof c){c=a.find(g.wrapper).data("categoryid")}return m(a,d,e,b,c,null,null,f)},changeMonth:n,refreshMonthContent:m,reloadCurrentDay:function reloadCurrentDay(a,b,c){var d=a.find(g.wrapper),e=d.data("year"),f=d.data("month"),h=d.data("day");if(!b){b=a.find(g.wrapper).data("courseid")}if("undefined"==typeof c){c=a.find(g.wrapper).data("categoryid")}return o(a,e,f,h,b,c)},changeDay:p,refreshDayContent:o,reloadCurrentUpcoming:s}}); //# sourceMappingURL=view_manager.min.js.map diff --git a/calendar/amd/build/view_manager.min.js.map b/calendar/amd/build/view_manager.min.js.map index 161e7997452..51b20c2862d 100644 --- a/calendar/amd/build/view_manager.min.js.map +++ b/calendar/amd/build/view_manager.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/view_manager.js"],"names":["define","$","Templates","Str","Notification","CalendarRepository","CalendarEvents","CalendarSelectors","ModalFactory","ModalEvents","SummaryModal","CustomEvents","registerEventListeners","root","on","links","eventLink","e","target","eventId","is","actions","viewEvent","closest","length","data","find","preventDefault","stopPropagation","renderEventSummaryModal","navLink","wrapper","view","courseId","categoryId","link","currentTarget","changeMonth","attr","changeDay","viewSelector","events","activate","option","hasClass","year","month","day","refreshMonthContent","then","window","history","pushState","fail","exception","refreshDayContent","reloadCurrentUpcoming","courseid","categoryid","template","startLoading","M","util","js_pending","get","join","includenavigation","mini","getCalendarMonthData","context","viewingmonth","render","html","js","replaceNode","trigger","viewUpdated","always","js_complete","stopLoading","url","arguments","monthChanged","getCalendarDayData","viewingday","dayChanged","loadingIconContainer","containers","loadingIcon","removeClass","addClass","getCalendarUpcomingData","viewingupcoming","getEventTypeClassFromType","eventType","typeClass","getEventById","getEventResponse","event","Error","eventData","normalisedeventtype","modalParams","title","name","type","TYPE","body","templateContext","canedit","candelete","headerclasses","isactionevent","create","done","modal","getRoot","hidden","destroy","show","init","reloadCurrentMonth","reloadCurrentDay"],"mappings":"AAuBAA,OAAM,8BAAC,CACH,QADG,CAEH,gBAFG,CAGH,UAHG,CAIH,mBAJG,CAKH,0BALG,CAMH,sBANG,CAOH,yBAPG,CAQH,oBARG,CASH,mBATG,CAUH,6BAVG,CA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I,CAACa,IAAL,CAAUnB,CAAiB,CAACwB,OAA5B,CAD0C,CAEpDc,CAAI,CAAGd,CAAO,CAACN,IAAR,CAAa,MAAb,CAF6C,CAGpDqB,CAAK,CAAGf,CAAO,CAACN,IAAR,CAAa,OAAb,CAH4C,CAIpDsB,CAAG,CAAGhB,CAAO,CAACN,IAAR,CAAa,KAAb,CAJ8C,CAMxD,GAAI,CAACQ,CAAL,CAAe,CACXA,CAAQ,CAAGpB,CAAI,CAACa,IAAL,CAAUnB,CAAiB,CAACwB,OAA5B,EAAqCN,IAArC,CAA0C,UAA1C,CACd,CAED,GAA0B,WAAtB,QAAOS,CAAAA,CAAX,CAAuC,CACnCA,CAAU,CAAGrB,CAAI,CAACa,IAAL,CAAUnB,CAAiB,CAACwB,OAA5B,EAAqCN,IAArC,CAA0C,YAA1C,CAChB,CAED,MAAO8B,CAAAA,CAAiB,CAAC1C,CAAD,CAAOgC,CAAP,CAAaC,CAAb,CAAoBC,CAApB,CAAyBd,CAAzB,CAAmCC,CAAnC,CAC3B,CAwJM,CAQHK,SAAS,CAAEA,CARR,CASHgB,iBAAiB,CAAEA,CAThB,CAUHC,qBAAqB,CAAEA,CAVpB,CAYV,CArbC,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 * A javascript module to handler calendar view changes.\n *\n * @module core_calendar/view_manager\n * @package core_calendar\n * @copyright 2017 Andrew Nicols \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine([\n 'jquery',\n 'core/templates',\n 'core/str',\n 'core/notification',\n 'core_calendar/repository',\n 'core_calendar/events',\n 'core_calendar/selectors',\n 'core/modal_factory',\n 'core/modal_events',\n 'core_calendar/summary_modal',\n 'core/custom_interaction_events',\n], function(\n $,\n Templates,\n Str,\n Notification,\n CalendarRepository,\n CalendarEvents,\n CalendarSelectors,\n ModalFactory,\n ModalEvents,\n SummaryModal,\n CustomEvents\n) {\n\n /**\n * Register event listeners for the module.\n *\n * @param {object} root The root element.\n */\n var registerEventListeners = function(root) {\n root = $(root);\n\n // Bind click events to event links.\n root.on('click', CalendarSelectors.links.eventLink, function(e) {\n var target = $(e.target);\n var eventId = null;\n\n var eventLink;\n if (target.is(CalendarSelectors.actions.viewEvent)) {\n eventLink = target;\n } else {\n eventLink = target.closest(CalendarSelectors.actions.viewEvent);\n }\n\n if (eventLink.length) {\n eventId = eventLink.data('eventId');\n } else {\n eventId = target.find(CalendarSelectors.actions.viewEvent).data('eventId');\n }\n\n if (eventId) {\n // A link was found. Show the modal.\n\n e.preventDefault();\n // We've handled the event so stop it from bubbling\n // and causing the day click handler to fire.\n e.stopPropagation();\n\n renderEventSummaryModal(eventId);\n }\n });\n\n\n root.on('click', CalendarSelectors.links.navLink, function(e) {\n var wrapper = root.find(CalendarSelectors.wrapper);\n var view = wrapper.data('view');\n var courseId = wrapper.data('courseid');\n var categoryId = wrapper.data('categoryid');\n var link = $(e.currentTarget);\n\n if (view === 'month') {\n changeMonth(root, link.attr('href'), link.data('year'), link.data('month'), courseId, categoryId);\n e.preventDefault();\n } else if (view === 'day') {\n changeDay(root, link.attr('href'), link.data('year'), link.data('month'), link.data('day'),\n courseId, categoryId);\n e.preventDefault();\n }\n\n });\n\n var viewSelector = root.find(CalendarSelectors.viewSelector);\n CustomEvents.define(viewSelector, [CustomEvents.events.activate]);\n viewSelector.on(\n CustomEvents.events.activate,\n function(e) {\n e.preventDefault();\n\n var option = $(e.target);\n if (option.hasClass('active')) {\n return;\n }\n\n var view = option.data('view'),\n year = option.data('year'),\n month = option.data('month'),\n day = option.data('day'),\n courseId = option.data('courseid'),\n categoryId = option.data('categoryid');\n\n if (view == 'month') {\n refreshMonthContent(root, year, month, courseId, categoryId, root, 'core_calendar/calendar_month')\n .then(function() {\n return window.history.pushState({}, '', '?view=month');\n }).fail(Notification.exception);\n } else if (view == 'day') {\n refreshDayContent(root, year, month, day, courseId, categoryId, root, 'core_calendar/calendar_day')\n .then(function() {\n return window.history.pushState({}, '', '?view=day');\n }).fail(Notification.exception);\n } else if (view == 'upcoming') {\n reloadCurrentUpcoming(root, courseId, categoryId, root, 'core_calendar/calendar_upcoming')\n .then(function() {\n return window.history.pushState({}, '', '?view=upcoming');\n }).fail(Notification.exception);\n }\n }\n );\n };\n\n /**\n * Refresh the month content.\n *\n * @param {object} root The root element.\n * @param {Number} year Year\n * @param {Number} month Month\n * @param {Number} courseid The id of the course whose events are shown\n * @param {Number} categoryid The id of the category whose events are shown\n * @param {object} target The element being replaced. If not specified, the calendarwrapper is used.\n * @param {String} template The template to be rendered.\n * @return {promise}\n */\n var refreshMonthContent = function(root, year, month, courseid, categoryid, target, template) {\n startLoading(root);\n\n target = target || root.find(CalendarSelectors.wrapper);\n template = template || root.attr('data-template');\n M.util.js_pending([root.get('id'), year, month, courseid].join('-'));\n var includenavigation = root.data('includenavigation');\n var mini = root.data('mini');\n return CalendarRepository.getCalendarMonthData(year, month, courseid, categoryid, includenavigation, mini)\n .then(function(context) {\n context.viewingmonth = true;\n return Templates.render(template, context);\n })\n .then(function(html, js) {\n return Templates.replaceNode(target, html, js);\n })\n .then(function() {\n $('body').trigger(CalendarEvents.viewUpdated);\n return;\n })\n .always(function() {\n M.util.js_complete([root.get('id'), year, month, courseid].join('-'));\n return stopLoading(root);\n })\n .fail(Notification.exception);\n };\n\n /**\n * Handle changes to the current calendar view.\n *\n * @param {object} root The container element\n * @param {String} url The calendar url to be shown\n * @param {Number} year Year\n * @param {Number} month Month\n * @param {Number} courseid The id of the course whose events are shown\n * @param {Number} categoryid The id of the category whose events are shown\n * @return {promise}\n */\n var changeMonth = function(root, url, year, month, courseid, categoryid) {\n return refreshMonthContent(root, year, month, courseid, categoryid)\n .then(function() {\n if (url.length && url !== '#') {\n window.history.pushState({}, '', url);\n }\n return arguments;\n })\n .then(function() {\n $('body').trigger(CalendarEvents.monthChanged, [year, month, courseid, categoryid]);\n return arguments;\n });\n };\n\n /**\n * Reload the current month view data.\n *\n * @param {object} root The container element.\n * @param {Number} courseId The course id.\n * @param {Number} categoryId The id of the category whose events are shown\n * @return {promise}\n */\n var reloadCurrentMonth = function(root, courseId, categoryId) {\n var year = root.find(CalendarSelectors.wrapper).data('year');\n var month = root.find(CalendarSelectors.wrapper).data('month');\n\n if (typeof courseId === 'undefined') {\n courseId = root.find(CalendarSelectors.wrapper).data('courseid');\n }\n\n if (typeof categoryId === 'undefined') {\n categoryId = root.find(CalendarSelectors.wrapper).data('categoryid');\n }\n\n return refreshMonthContent(root, year, month, courseId, categoryId);\n };\n\n\n /**\n * Refresh the day content.\n *\n * @param {object} root The root element.\n * @param {Number} year Year\n * @param {Number} month Month\n * @param {Number} day Day\n * @param {Number} courseid The id of the course whose events are shown\n * @param {Number} categoryId The id of the category whose events are shown\n * @param {object} target The element being replaced. If not specified, the calendarwrapper is used.\n * @param {String} template The template to be rendered.\n *\n * @return {promise}\n */\n var refreshDayContent = function(root, year, month, day, courseid, categoryId, target, template) {\n startLoading(root);\n\n target = target || root.find(CalendarSelectors.wrapper);\n template = template || root.attr('data-template');\n M.util.js_pending([root.get('id'), year, month, day, courseid, categoryId].join('-'));\n var includenavigation = root.data('includenavigation');\n return CalendarRepository.getCalendarDayData(year, month, day, courseid, categoryId, includenavigation)\n .then(function(context) {\n context.viewingday = true;\n return Templates.render(template, context);\n })\n .then(function(html, js) {\n return Templates.replaceNode(target, html, js);\n })\n .then(function() {\n $('body').trigger(CalendarEvents.viewUpdated);\n return;\n })\n .always(function() {\n M.util.js_complete([root.get('id'), year, month, day, courseid, categoryId].join('-'));\n return stopLoading(root);\n })\n .fail(Notification.exception);\n };\n\n /**\n * Reload the current day view data.\n *\n * @param {object} root The container element.\n * @param {Number} courseId The course id.\n * @param {Number} categoryId The id of the category whose events are shown\n * @return {promise}\n */\n var reloadCurrentDay = function(root, courseId, categoryId) {\n var wrapper = root.find(CalendarSelectors.wrapper);\n var year = wrapper.data('year');\n var month = wrapper.data('month');\n var day = wrapper.data('day');\n\n if (!courseId) {\n courseId = root.find(CalendarSelectors.wrapper).data('courseid');\n }\n\n if (typeof categoryId === 'undefined') {\n categoryId = root.find(CalendarSelectors.wrapper).data('categoryid');\n }\n\n return refreshDayContent(root, year, month, day, courseId, categoryId);\n };\n\n /**\n * Handle changes to the current calendar view.\n *\n * @param {object} root The root element.\n * @param {String} url The calendar url to be shown\n * @param {Number} year Year\n * @param {Number} month Month\n * @param {Number} day Day\n * @param {Number} courseId The id of the course whose events are shown\n * @param {Number} categoryId The id of the category whose events are shown\n * @return {promise}\n */\n var changeDay = function(root, url, year, month, day, courseId, categoryId) {\n return refreshDayContent(root, year, month, day, courseId, categoryId)\n .then(function() {\n if (url.length && url !== '#') {\n window.history.pushState({}, '', url);\n }\n return arguments;\n })\n .then(function() {\n $('body').trigger(CalendarEvents.dayChanged, [year, month, courseId, categoryId]);\n return arguments;\n });\n };\n\n /**\n * Set the element state to loading.\n *\n * @param {object} root The container element\n * @method startLoading\n */\n var startLoading = function(root) {\n var loadingIconContainer = root.find(CalendarSelectors.containers.loadingIcon);\n\n loadingIconContainer.removeClass('hidden');\n };\n\n /**\n * Remove the loading state from the element.\n *\n * @param {object} root The container element\n * @method stopLoading\n */\n var stopLoading = function(root) {\n var loadingIconContainer = root.find(CalendarSelectors.containers.loadingIcon);\n\n loadingIconContainer.addClass('hidden');\n };\n\n /**\n * Reload the current month view data.\n *\n * @param {object} root The container element.\n * @param {Number} courseId The course id.\n * @param {Number} categoryId The id of the category whose events are shown\n * @param {String} template The template to be rendered.\n * @param {object} target The element being replaced. If not specified, the calendarwrapper is used.\n * @return {promise}\n */\n var reloadCurrentUpcoming = function(root, courseId, categoryId, target, template) {\n startLoading(root);\n\n target = target || root.find(CalendarSelectors.wrapper);\n template = template || root.attr('data-template');\n\n if (typeof courseId === 'undefined') {\n courseId = root.find(CalendarSelectors.wrapper).data('courseid');\n }\n\n if (typeof categoryId === 'undefined') {\n categoryId = root.find(CalendarSelectors.wrapper).data('categoryid');\n }\n\n return CalendarRepository.getCalendarUpcomingData(courseId, categoryId)\n .then(function(context) {\n context.viewingupcoming = true;\n return Templates.render(template, context);\n })\n .then(function(html, js) {\n return Templates.replaceNode(target, html, js);\n })\n .then(function() {\n $('body').trigger(CalendarEvents.viewUpdated);\n return;\n })\n .always(function() {\n return stopLoading(root);\n })\n .fail(Notification.exception);\n };\n\n /**\n * Get the CSS class to apply for the given event type.\n *\n * @param {String} eventType The calendar event type\n * @return {String}\n */\n var getEventTypeClassFromType = function(eventType) {\n return 'calendar_event_' + eventType;\n };\n\n /**\n * Render the event summary modal.\n *\n * @param {Number} eventId The calendar event id.\n */\n var renderEventSummaryModal = function(eventId) {\n var typeClass = '';\n\n // Calendar repository promise.\n CalendarRepository.getEventById(eventId).then(function(getEventResponse) {\n if (!getEventResponse.event) {\n throw new Error('Error encountered while trying to fetch calendar event with ID: ' + eventId);\n }\n var eventData = getEventResponse.event;\n typeClass = getEventTypeClassFromType(eventData.normalisedeventtype);\n\n return eventData;\n }).then(function(eventData) {\n // Build the modal parameters from the event data.\n var modalParams = {\n title: eventData.name,\n type: SummaryModal.TYPE,\n body: Templates.render('core_calendar/event_summary_body', eventData),\n templateContext: {\n canedit: eventData.canedit,\n candelete: eventData.candelete,\n headerclasses: typeClass,\n isactionevent: eventData.isactionevent,\n url: eventData.url\n }\n };\n\n // Create the modal.\n return ModalFactory.create(modalParams);\n\n }).done(function(modal) {\n // Handle hidden event.\n modal.getRoot().on(ModalEvents.hidden, function() {\n // Destroy when hidden.\n modal.destroy();\n });\n\n // Finally, render the modal!\n modal.show();\n\n }).fail(Notification.exception);\n };\n\n return {\n init: function(root, view) {\n registerEventListeners(root, view);\n },\n reloadCurrentMonth: reloadCurrentMonth,\n changeMonth: changeMonth,\n refreshMonthContent: refreshMonthContent,\n reloadCurrentDay: reloadCurrentDay,\n changeDay: changeDay,\n refreshDayContent: refreshDayContent,\n reloadCurrentUpcoming: reloadCurrentUpcoming\n };\n });\n"],"file":"view_manager.min.js"} \ No newline at end of file +{"version":3,"sources":["../src/view_manager.js"],"names":["define","$","Templates","Str","Notification","CalendarRepository","CalendarEvents","CalendarSelectors","ModalFactory","ModalEvents","SummaryModal","CustomEvents","registerEventListeners","root","on","links","eventLink","e","target","eventId","is","actions","viewEvent","closest","length","data","find","preventDefault","stopPropagation","renderEventSummaryModal","navLink","wrapper","view","courseId","categoryId","link","currentTarget","changeMonth","attr","changeDay","viewSelector","events","activate","option","hasClass","year","month","day","refreshMonthContent","then","window","history","pushState","fail","exception","refreshDayContent","reloadCurrentUpcoming","courseid","categoryid","template","startLoading","M","util","js_pending","get","join","includenavigation","mini","getCalendarMonthData","context","viewingmonth","render","html","js","replaceNode","trigger","viewUpdated","always","js_complete","stopLoading","url","arguments","monthChanged","getCalendarDayData","viewingday","dayChanged","loadingIconContainer","containers","loadingIcon","removeClass","addClass","getCalendarUpcomingData","viewingupcoming","getEventTypeClassFromType","eventType","typeClass","getEventById","getEventResponse","event","Error","eventData","normalisedeventtype","modalParams","title","name","type","TYPE","body","templateContext","canedit","candelete","headerclasses","isactionevent","create","done","modal","getRoot","hidden","destroy","show","init","reloadCurrentMonth","reloadCurrentDay"],"mappings":"AAuBAA,OAAM,8BAAC,CACH,QADG,CAEH,gBAFG,CAGH,UAHG,CAIH,mBAJG,CAKH,0BALG,CAMH,sBANG,CAOH,yBAPG,CAQH,oBARG,CASH,mBATG,CAUH,6BAVG,CAWH,gCAXG,CAAD,CAYH,SACCC,CADD,CAECC,CAFD,CAGCC,CAHD,CAICC,CAJD,CAKCC,CALD,CAMCC,CAND,CAOCC,CAPD,CAQCC,CARD,CASCC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,CAA0C,IAA1C,CAAgD,IAAhD,CAAsDa,CAAtD,CAC7B,CA0NM,CAKHV,WAAW,CAAEA,CALV,CAMHW,mBAAmB,CAAEA,CANlB,CAOH0E,gBAAgB,CA9KG,QAAnBA,CAAAA,gBAAmB,CAAS7G,CAAT,CAAeoB,CAAf,CAAyBC,CAAzB,CAAqC,IACpDH,CAAAA,CAAO,CAAGlB,CAAI,CAACa,IAAL,CAAUnB,CAAiB,CAACwB,OAA5B,CAD0C,CAEpDc,CAAI,CAAGd,CAAO,CAACN,IAAR,CAAa,MAAb,CAF6C,CAGpDqB,CAAK,CAAGf,CAAO,CAACN,IAAR,CAAa,OAAb,CAH4C,CAIpDsB,CAAG,CAAGhB,CAAO,CAACN,IAAR,CAAa,KAAb,CAJ8C,CAMxD,GAAI,CAACQ,CAAL,CAAe,CACXA,CAAQ,CAAGpB,CAAI,CAACa,IAAL,CAAUnB,CAAiB,CAACwB,OAA5B,EAAqCN,IAArC,CAA0C,UAA1C,CACd,CAED,GAA0B,WAAtB,QAAOS,CAAAA,CAAX,CAAuC,CACnCA,CAAU,CAAGrB,CAAI,CAACa,IAAL,CAAUnB,CAAiB,CAACwB,OAA5B,EAAqCN,IAArC,CAA0C,YAA1C,CAChB,CAED,MAAO8B,CAAAA,CAAiB,CAAC1C,CAAD,CAAOgC,CAAP,CAAaC,CAAb,CAAoBC,CAApB,CAAyBd,CAAzB,CAAmCC,CAAnC,CAC3B,CAwJM,CAQHK,SAAS,CAAEA,CARR,CASHgB,iBAAiB,CAAEA,CAThB,CAUHC,qBAAqB,CAAEA,CAVpB,CAYV,CA3bC,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 * A javascript module to handler calendar view changes.\n *\n * @module core_calendar/view_manager\n * @package core_calendar\n * @copyright 2017 Andrew Nicols \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine([\n 'jquery',\n 'core/templates',\n 'core/str',\n 'core/notification',\n 'core_calendar/repository',\n 'core_calendar/events',\n 'core_calendar/selectors',\n 'core/modal_factory',\n 'core/modal_events',\n 'core_calendar/summary_modal',\n 'core/custom_interaction_events',\n], function(\n $,\n Templates,\n Str,\n Notification,\n CalendarRepository,\n CalendarEvents,\n CalendarSelectors,\n ModalFactory,\n ModalEvents,\n SummaryModal,\n CustomEvents\n) {\n\n /**\n * Register event listeners for the module.\n *\n * @param {object} root The root element.\n */\n var registerEventListeners = function(root) {\n root = $(root);\n\n // Bind click events to event links.\n root.on('click', CalendarSelectors.links.eventLink, function(e) {\n var target = $(e.target);\n var eventId = null;\n\n var eventLink;\n if (target.is(CalendarSelectors.actions.viewEvent)) {\n eventLink = target;\n } else {\n eventLink = target.closest(CalendarSelectors.actions.viewEvent);\n }\n\n if (eventLink.length) {\n eventId = eventLink.data('eventId');\n } else {\n eventId = target.find(CalendarSelectors.actions.viewEvent).data('eventId');\n }\n\n if (eventId) {\n // A link was found. Show the modal.\n\n e.preventDefault();\n // We've handled the event so stop it from bubbling\n // and causing the day click handler to fire.\n e.stopPropagation();\n\n renderEventSummaryModal(eventId);\n }\n });\n\n\n root.on('click', CalendarSelectors.links.navLink, function(e) {\n var wrapper = root.find(CalendarSelectors.wrapper);\n var view = wrapper.data('view');\n var courseId = wrapper.data('courseid');\n var categoryId = wrapper.data('categoryid');\n var link = $(e.currentTarget);\n\n if (view === 'month') {\n changeMonth(root, link.attr('href'), link.data('year'), link.data('month'), courseId, categoryId,\n link.data('day'));\n e.preventDefault();\n } else if (view === 'day') {\n changeDay(root, link.attr('href'), link.data('year'), link.data('month'), link.data('day'),\n courseId, categoryId);\n e.preventDefault();\n }\n\n });\n\n var viewSelector = root.find(CalendarSelectors.viewSelector);\n CustomEvents.define(viewSelector, [CustomEvents.events.activate]);\n viewSelector.on(\n CustomEvents.events.activate,\n function(e) {\n e.preventDefault();\n\n var option = $(e.target);\n if (option.hasClass('active')) {\n return;\n }\n\n var view = option.data('view'),\n year = option.data('year'),\n month = option.data('month'),\n day = option.data('day'),\n courseId = option.data('courseid'),\n categoryId = option.data('categoryid');\n\n if (view == 'month') {\n refreshMonthContent(root, year, month, courseId, categoryId, root, 'core_calendar/calendar_month', day)\n .then(function() {\n return window.history.pushState({}, '', '?view=month');\n }).fail(Notification.exception);\n } else if (view == 'day') {\n refreshDayContent(root, year, month, day, courseId, categoryId, root, 'core_calendar/calendar_day')\n .then(function() {\n return window.history.pushState({}, '', '?view=day');\n }).fail(Notification.exception);\n } else if (view == 'upcoming') {\n reloadCurrentUpcoming(root, courseId, categoryId, root, 'core_calendar/calendar_upcoming')\n .then(function() {\n return window.history.pushState({}, '', '?view=upcoming');\n }).fail(Notification.exception);\n }\n }\n );\n };\n\n /**\n * Refresh the month content.\n *\n * @param {object} root The root element.\n * @param {Number} year Year\n * @param {Number} month Month\n * @param {Number} courseid The id of the course whose events are shown\n * @param {Number} categoryid The id of the category whose events are shown\n * @param {object} target The element being replaced. If not specified, the calendarwrapper is used.\n * @param {String} template The template to be rendered.\n * @param {Number} day Day (optional)\n * @return {promise}\n */\n var refreshMonthContent = function(root, year, month, courseid, categoryid, target, template, day) {\n startLoading(root);\n\n target = target || root.find(CalendarSelectors.wrapper);\n template = template || root.attr('data-template');\n day = day || 1;\n M.util.js_pending([root.get('id'), year, month, courseid].join('-'));\n var includenavigation = root.data('includenavigation');\n var mini = root.data('mini');\n return CalendarRepository.getCalendarMonthData(year, month, courseid, categoryid, includenavigation, mini, day)\n .then(function(context) {\n context.viewingmonth = true;\n return Templates.render(template, context);\n })\n .then(function(html, js) {\n return Templates.replaceNode(target, html, js);\n })\n .then(function() {\n $('body').trigger(CalendarEvents.viewUpdated);\n return;\n })\n .always(function() {\n M.util.js_complete([root.get('id'), year, month, courseid].join('-'));\n return stopLoading(root);\n })\n .fail(Notification.exception);\n };\n\n /**\n * Handle changes to the current calendar view.\n *\n * @param {object} root The container element\n * @param {String} url The calendar url to be shown\n * @param {Number} year Year\n * @param {Number} month Month\n * @param {Number} courseid The id of the course whose events are shown\n * @param {Number} categoryid The id of the category whose events are shown\n * @param {Number} day Day (optional)\n * @return {promise}\n */\n var changeMonth = function(root, url, year, month, courseid, categoryid, day) {\n day = day || 1;\n return refreshMonthContent(root, year, month, courseid, categoryid, null, null, day)\n .then(function() {\n if (url.length && url !== '#') {\n window.history.pushState({}, '', url);\n }\n return arguments;\n })\n .then(function() {\n $('body').trigger(CalendarEvents.monthChanged, [year, month, courseid, categoryid]);\n return arguments;\n });\n };\n\n /**\n * Reload the current month view data.\n *\n * @param {object} root The container element.\n * @param {Number} courseId The course id.\n * @param {Number} categoryId The id of the category whose events are shown\n * @return {promise}\n */\n var reloadCurrentMonth = function(root, courseId, categoryId) {\n var year = root.find(CalendarSelectors.wrapper).data('year');\n var month = root.find(CalendarSelectors.wrapper).data('month');\n var day = root.find(CalendarSelectors.wrapper).data('day');\n\n if (typeof courseId === 'undefined') {\n courseId = root.find(CalendarSelectors.wrapper).data('courseid');\n }\n\n if (typeof categoryId === 'undefined') {\n categoryId = root.find(CalendarSelectors.wrapper).data('categoryid');\n }\n\n return refreshMonthContent(root, year, month, courseId, categoryId, null, null, day);\n };\n\n\n /**\n * Refresh the day content.\n *\n * @param {object} root The root element.\n * @param {Number} year Year\n * @param {Number} month Month\n * @param {Number} day Day\n * @param {Number} courseid The id of the course whose events are shown\n * @param {Number} categoryId The id of the category whose events are shown\n * @param {object} target The element being replaced. If not specified, the calendarwrapper is used.\n * @param {String} template The template to be rendered.\n *\n * @return {promise}\n */\n var refreshDayContent = function(root, year, month, day, courseid, categoryId, target, template) {\n startLoading(root);\n\n target = target || root.find(CalendarSelectors.wrapper);\n template = template || root.attr('data-template');\n M.util.js_pending([root.get('id'), year, month, day, courseid, categoryId].join('-'));\n var includenavigation = root.data('includenavigation');\n return CalendarRepository.getCalendarDayData(year, month, day, courseid, categoryId, includenavigation)\n .then(function(context) {\n context.viewingday = true;\n return Templates.render(template, context);\n })\n .then(function(html, js) {\n return Templates.replaceNode(target, html, js);\n })\n .then(function() {\n $('body').trigger(CalendarEvents.viewUpdated);\n return;\n })\n .always(function() {\n M.util.js_complete([root.get('id'), year, month, day, courseid, categoryId].join('-'));\n return stopLoading(root);\n })\n .fail(Notification.exception);\n };\n\n /**\n * Reload the current day view data.\n *\n * @param {object} root The container element.\n * @param {Number} courseId The course id.\n * @param {Number} categoryId The id of the category whose events are shown\n * @return {promise}\n */\n var reloadCurrentDay = function(root, courseId, categoryId) {\n var wrapper = root.find(CalendarSelectors.wrapper);\n var year = wrapper.data('year');\n var month = wrapper.data('month');\n var day = wrapper.data('day');\n\n if (!courseId) {\n courseId = root.find(CalendarSelectors.wrapper).data('courseid');\n }\n\n if (typeof categoryId === 'undefined') {\n categoryId = root.find(CalendarSelectors.wrapper).data('categoryid');\n }\n\n return refreshDayContent(root, year, month, day, courseId, categoryId);\n };\n\n /**\n * Handle changes to the current calendar view.\n *\n * @param {object} root The root element.\n * @param {String} url The calendar url to be shown\n * @param {Number} year Year\n * @param {Number} month Month\n * @param {Number} day Day\n * @param {Number} courseId The id of the course whose events are shown\n * @param {Number} categoryId The id of the category whose events are shown\n * @return {promise}\n */\n var changeDay = function(root, url, year, month, day, courseId, categoryId) {\n return refreshDayContent(root, year, month, day, courseId, categoryId)\n .then(function() {\n if (url.length && url !== '#') {\n window.history.pushState({}, '', url);\n }\n return arguments;\n })\n .then(function() {\n $('body').trigger(CalendarEvents.dayChanged, [year, month, courseId, categoryId]);\n return arguments;\n });\n };\n\n /**\n * Set the element state to loading.\n *\n * @param {object} root The container element\n * @method startLoading\n */\n var startLoading = function(root) {\n var loadingIconContainer = root.find(CalendarSelectors.containers.loadingIcon);\n\n loadingIconContainer.removeClass('hidden');\n };\n\n /**\n * Remove the loading state from the element.\n *\n * @param {object} root The container element\n * @method stopLoading\n */\n var stopLoading = function(root) {\n var loadingIconContainer = root.find(CalendarSelectors.containers.loadingIcon);\n\n loadingIconContainer.addClass('hidden');\n };\n\n /**\n * Reload the current month view data.\n *\n * @param {object} root The container element.\n * @param {Number} courseId The course id.\n * @param {Number} categoryId The id of the category whose events are shown\n * @param {String} template The template to be rendered.\n * @param {object} target The element being replaced. If not specified, the calendarwrapper is used.\n * @return {promise}\n */\n var reloadCurrentUpcoming = function(root, courseId, categoryId, target, template) {\n startLoading(root);\n\n target = target || root.find(CalendarSelectors.wrapper);\n template = template || root.attr('data-template');\n\n if (typeof courseId === 'undefined') {\n courseId = root.find(CalendarSelectors.wrapper).data('courseid');\n }\n\n if (typeof categoryId === 'undefined') {\n categoryId = root.find(CalendarSelectors.wrapper).data('categoryid');\n }\n\n return CalendarRepository.getCalendarUpcomingData(courseId, categoryId)\n .then(function(context) {\n context.viewingupcoming = true;\n return Templates.render(template, context);\n })\n .then(function(html, js) {\n return Templates.replaceNode(target, html, js);\n })\n .then(function() {\n $('body').trigger(CalendarEvents.viewUpdated);\n return;\n })\n .always(function() {\n return stopLoading(root);\n })\n .fail(Notification.exception);\n };\n\n /**\n * Get the CSS class to apply for the given event type.\n *\n * @param {String} eventType The calendar event type\n * @return {String}\n */\n var getEventTypeClassFromType = function(eventType) {\n return 'calendar_event_' + eventType;\n };\n\n /**\n * Render the event summary modal.\n *\n * @param {Number} eventId The calendar event id.\n */\n var renderEventSummaryModal = function(eventId) {\n var typeClass = '';\n\n // Calendar repository promise.\n CalendarRepository.getEventById(eventId).then(function(getEventResponse) {\n if (!getEventResponse.event) {\n throw new Error('Error encountered while trying to fetch calendar event with ID: ' + eventId);\n }\n var eventData = getEventResponse.event;\n typeClass = getEventTypeClassFromType(eventData.normalisedeventtype);\n\n return eventData;\n }).then(function(eventData) {\n // Build the modal parameters from the event data.\n var modalParams = {\n title: eventData.name,\n type: SummaryModal.TYPE,\n body: Templates.render('core_calendar/event_summary_body', eventData),\n templateContext: {\n canedit: eventData.canedit,\n candelete: eventData.candelete,\n headerclasses: typeClass,\n isactionevent: eventData.isactionevent,\n url: eventData.url\n }\n };\n\n // Create the modal.\n return ModalFactory.create(modalParams);\n\n }).done(function(modal) {\n // Handle hidden event.\n modal.getRoot().on(ModalEvents.hidden, function() {\n // Destroy when hidden.\n modal.destroy();\n });\n\n // Finally, render the modal!\n modal.show();\n\n }).fail(Notification.exception);\n };\n\n return {\n init: function(root, view) {\n registerEventListeners(root, view);\n },\n reloadCurrentMonth: reloadCurrentMonth,\n changeMonth: changeMonth,\n refreshMonthContent: refreshMonthContent,\n reloadCurrentDay: reloadCurrentDay,\n changeDay: changeDay,\n refreshDayContent: refreshDayContent,\n reloadCurrentUpcoming: reloadCurrentUpcoming\n };\n });\n"],"file":"view_manager.min.js"} \ No newline at end of file diff --git a/calendar/amd/src/repository.js b/calendar/amd/src/repository.js index d8166fae7e4..08ddb2b8f4d 100644 --- a/calendar/amd/src/repository.js +++ b/calendar/amd/src/repository.js @@ -94,11 +94,13 @@ define(['jquery', 'core/ajax'], function($, Ajax) { * @param {Number} month Month * @param {Number} courseid The course id. * @param {Number} categoryid The category id. - * @param {Bool} includenavigation Whether to include navigation. - * @param {Bool} mini Whether the month is in mini view. + * @param {Boolean} includenavigation Whether to include navigation. + * @param {Boolean} mini Whether the month is in mini view. + * @param {Number} day Day (optional) * @return {promise} Resolved with the month view data. */ - var getCalendarMonthData = function(year, month, courseid, categoryid, includenavigation, mini) { + var getCalendarMonthData = function(year, month, courseid, categoryid, includenavigation, mini, day) { + day = day || 1; var request = { methodname: 'core_calendar_get_calendar_monthly_view', args: { @@ -107,7 +109,8 @@ define(['jquery', 'core/ajax'], function($, Ajax) { courseid: courseid, categoryid: categoryid, includenavigation: includenavigation, - mini: mini + mini: mini, + day: day } }; diff --git a/calendar/amd/src/view_manager.js b/calendar/amd/src/view_manager.js index 887645ba403..eb91fda38d1 100644 --- a/calendar/amd/src/view_manager.js +++ b/calendar/amd/src/view_manager.js @@ -94,7 +94,8 @@ define([ var link = $(e.currentTarget); if (view === 'month') { - changeMonth(root, link.attr('href'), link.data('year'), link.data('month'), courseId, categoryId); + changeMonth(root, link.attr('href'), link.data('year'), link.data('month'), courseId, categoryId, + link.data('day')); e.preventDefault(); } else if (view === 'day') { changeDay(root, link.attr('href'), link.data('year'), link.data('month'), link.data('day'), @@ -124,7 +125,7 @@ define([ categoryId = option.data('categoryid'); if (view == 'month') { - refreshMonthContent(root, year, month, courseId, categoryId, root, 'core_calendar/calendar_month') + refreshMonthContent(root, year, month, courseId, categoryId, root, 'core_calendar/calendar_month', day) .then(function() { return window.history.pushState({}, '', '?view=month'); }).fail(Notification.exception); @@ -153,17 +154,19 @@ define([ * @param {Number} categoryid The id of the category whose events are shown * @param {object} target The element being replaced. If not specified, the calendarwrapper is used. * @param {String} template The template to be rendered. + * @param {Number} day Day (optional) * @return {promise} */ - var refreshMonthContent = function(root, year, month, courseid, categoryid, target, template) { + var refreshMonthContent = function(root, year, month, courseid, categoryid, target, template, day) { startLoading(root); target = target || root.find(CalendarSelectors.wrapper); template = template || root.attr('data-template'); + day = day || 1; M.util.js_pending([root.get('id'), year, month, courseid].join('-')); var includenavigation = root.data('includenavigation'); var mini = root.data('mini'); - return CalendarRepository.getCalendarMonthData(year, month, courseid, categoryid, includenavigation, mini) + return CalendarRepository.getCalendarMonthData(year, month, courseid, categoryid, includenavigation, mini, day) .then(function(context) { context.viewingmonth = true; return Templates.render(template, context); @@ -191,10 +194,12 @@ define([ * @param {Number} month Month * @param {Number} courseid The id of the course whose events are shown * @param {Number} categoryid The id of the category whose events are shown + * @param {Number} day Day (optional) * @return {promise} */ - var changeMonth = function(root, url, year, month, courseid, categoryid) { - return refreshMonthContent(root, year, month, courseid, categoryid) + var changeMonth = function(root, url, year, month, courseid, categoryid, day) { + day = day || 1; + return refreshMonthContent(root, year, month, courseid, categoryid, null, null, day) .then(function() { if (url.length && url !== '#') { window.history.pushState({}, '', url); @@ -218,6 +223,7 @@ define([ var reloadCurrentMonth = function(root, courseId, categoryId) { var year = root.find(CalendarSelectors.wrapper).data('year'); var month = root.find(CalendarSelectors.wrapper).data('month'); + var day = root.find(CalendarSelectors.wrapper).data('day'); if (typeof courseId === 'undefined') { courseId = root.find(CalendarSelectors.wrapper).data('courseid'); @@ -227,7 +233,7 @@ define([ categoryId = root.find(CalendarSelectors.wrapper).data('categoryid'); } - return refreshMonthContent(root, year, month, courseId, categoryId); + return refreshMonthContent(root, year, month, courseId, categoryId, null, null, day); }; diff --git a/calendar/externallib.php b/calendar/externallib.php index d7f83479954..4d544456b7d 100644 --- a/calendar/externallib.php +++ b/calendar/externallib.php @@ -988,10 +988,11 @@ class core_calendar_external extends external_api { * @param int $categoryid The category to be included * @param bool $includenavigation Whether to include navigation * @param bool $mini Whether to return the mini month view or not + * @param int $day The day we want to keep as the current day * @return array */ - public static function get_calendar_monthly_view($year, $month, $courseid, $categoryid, $includenavigation, $mini) { - global $DB, $USER, $PAGE; + public static function get_calendar_monthly_view($year, $month, $courseid, $categoryid, $includenavigation, $mini, $day) { + global $USER, $PAGE; // Parameter validation. $params = self::validate_parameters(self::get_calendar_monthly_view_parameters(), [ @@ -1001,6 +1002,7 @@ class core_calendar_external extends external_api { 'categoryid' => $categoryid, 'includenavigation' => $includenavigation, 'mini' => $mini, + 'day' => $day, ]); $context = \context_user::instance($USER->id); @@ -1009,7 +1011,7 @@ class core_calendar_external extends external_api { $type = \core_calendar\type_factory::get_calendar_instance(); - $time = $type->convert_to_timestamp($params['year'], $params['month'], 1); + $time = $type->convert_to_timestamp($params['year'], $params['month'], $params['day']); $calendar = \calendar_information::create($time, $params['courseid'], $params['categoryid']); self::validate_context($calendar->context); @@ -1045,6 +1047,7 @@ class core_calendar_external extends external_api { false, NULL_ALLOWED ), + 'day' => new external_value(PARAM_INT, 'Day to be viewed', VALUE_DEFAULT, 1), ] ); } diff --git a/calendar/templates/month_mini.mustache b/calendar/templates/month_mini.mustache index cb3e22974c0..d5cef7239f7 100644 --- a/calendar/templates/month_mini.mustache +++ b/calendar/templates/month_mini.mustache @@ -38,6 +38,7 @@ }} data-categoryid="{{categoryid}}"{{! }} data-month="{{date.mon}}"{{! }} data-year="{{date.year}}"{{! + }} data-day="{{date.mday}}"{{! }} data-view="month"{{! }}> {{> core/overlay_loading}} diff --git a/calendar/tests/externallib_test.php b/calendar/tests/externallib_test.php index 810c25fdd20..acf2294b794 100644 --- a/calendar/tests/externallib_test.php +++ b/calendar/tests/externallib_test.php @@ -2372,7 +2372,7 @@ class core_calendar_externallib_testcase extends externallib_advanced_testcase { $data = external_api::clean_returnvalue( core_calendar_external::get_calendar_monthly_view_returns(), core_calendar_external::get_calendar_monthly_view($timestart->format('Y'), $timestart->format('n'), - $course->id, null, false, true) + $course->id, null, false, true, $timestart->format('d')) ); $this->assertEquals($data['courseid'], $course->id); // User enrolled in the course can load the course calendar. @@ -2380,7 +2380,7 @@ class core_calendar_externallib_testcase extends externallib_advanced_testcase { $data = external_api::clean_returnvalue( core_calendar_external::get_calendar_monthly_view_returns(), core_calendar_external::get_calendar_monthly_view($timestart->format('Y'), $timestart->format('n'), - $course->id, null, false, true) + $course->id, null, false, true, $timestart->format('d')) ); $this->assertEquals($data['courseid'], $course->id); // User not enrolled in the course cannot load the course calendar. @@ -2389,10 +2389,26 @@ class core_calendar_externallib_testcase extends externallib_advanced_testcase { $data = external_api::clean_returnvalue( core_calendar_external::get_calendar_monthly_view_returns(), core_calendar_external::get_calendar_monthly_view($timestart->format('Y'), $timestart->format('n'), - $course->id, null, false, false) + $course->id, null, false, false, $timestart->format('d')) ); } + /** + * Test get_calendar_monthly_view when a day parameter is provided. + */ + public function test_get_calendar_monthly_view_with_day_provided() { + $this->resetAfterTest(); + $this->setAdminUser(); + + $timestart = new DateTime(); + $data = external_api::clean_returnvalue( + core_calendar_external::get_calendar_monthly_view_returns(), + core_calendar_external::get_calendar_monthly_view($timestart->format('Y'), $timestart->format('n'), + SITEID, null, false, true, $timestart->format('d')) + ); + $this->assertEquals($data['date']['mday'], $timestart->format('d')); + } + /** * A user should not be able load the calendar day view for a course they cannot access. */