MDL-59677 core_calendar: delete event without reload whole page
authorSimey Lameze <simey@moodle.com>
Mon, 21 Aug 2017 04:49:04 +0000 (12:49 +0800)
committerSimey Lameze <simey@moodle.com>
Mon, 21 Aug 2017 07:20:14 +0000 (15:20 +0800)
calendar/amd/build/calendar.min.js
calendar/amd/build/view_manager.min.js
calendar/amd/src/calendar.js
calendar/amd/src/view_manager.js
calendar/classes/external/month_exporter.php
calendar/templates/month_detailed.mustache

index 24a5810..59256a9 100644 (file)
Binary files a/calendar/amd/build/calendar.min.js and b/calendar/amd/build/calendar.min.js differ
index 384490f..7866676 100644 (file)
Binary files a/calendar/amd/build/view_manager.min.js and b/calendar/amd/build/view_manager.min.js differ
index 570c8c6..b1f37e7 100644 (file)
@@ -195,7 +195,7 @@ define([
             window.location.reload();
         });
         body.on(CalendarEvents.deleted, function() {
-            window.location.reload();
+            CalendarViewManager.reloadCurrentMonth();
         });
         body.on(CalendarEvents.updated, function() {
             window.location.reload();
index 6eb6269..da1e454 100644 (file)
@@ -47,31 +47,61 @@ define(['jquery', 'core/templates', 'core/notification', 'core_calendar/reposito
             });
         };
 
+        /**
+         * Refresh the month content.
+         *
+         * @param {Number} time The calendar time to be shown
+         * @param {Number} courseid The id of the course whose events are shown
+         * @return {promise}
+         */
+        var refreshMonthContent = function(time, courseid) {
+            return CalendarRepository.getCalendarMonthData(time, courseid)
+                .then(function(context) {
+                    return Templates.render('core_calendar/month_detailed', context);
+                })
+                .then(function(html, js) {
+                    return Templates.replaceNodeContents(SELECTORS.CALENDAR_MONTH_WRAPPER, html, js);
+                })
+                .fail(Notification.exception);
+        };
+
         /**
          * Handle changes to the current calendar view.
          *
          * @param {String} url The calendar url to be shown
          * @param {Number} time The calendar time to be shown
          * @param {Number} courseid The id of the course whose events are shown
+         * @return {promise}
          */
         var changeMonth = function(url, time, courseid) {
-            CalendarRepository.getCalendarMonthData(time, courseid)
-            .then(function(context) {
-                window.history.pushState({}, '', url);
-                return Templates.render('core_calendar/month_detailed', context);
-            })
-            .then(function(html, js) {
-                return Templates.replaceNodeContents(SELECTORS.CALENDAR_MONTH_WRAPPER, html, js);
-            })
-            .done(function() {
-                $('body').trigger(CalendarEvents.monthChanged, [time, courseid]);
-            })
-            .fail(Notification.exception);
+            return refreshMonthContent(time, courseid)
+                .then(function() {
+                    window.history.pushState({}, '', url);
+                })
+                .then(function() {
+                    $('body').trigger(CalendarEvents.monthChanged, [time, courseid]);
+                });
+        };
+
+        /**
+         * Reload the current month view data.
+         *
+         * @return {promise}
+         */
+        var reloadCurrentMonth = function() {
+            var root = $(SELECTORS.ROOT),
+                courseid = root.find(SELECTORS.CALENDAR_MONTH_WRAPPER).data('courseid'),
+                time = root.find(SELECTORS.CALENDAR_MONTH_WRAPPER).data('current-time');
+
+            return refreshMonthContent(time, courseid);
         };
 
         return {
             init: function() {
                 registerEventListeners(SELECTORS.ROOT);
-            }
+            },
+            reloadCurrentMonth: reloadCurrentMonth,
+            changeMonth: changeMonth,
+            refreshMonthContent: refreshMonthContent
         };
     });
index cf1d1bd..9b99498 100644 (file)
@@ -112,6 +112,9 @@ class month_exporter extends exporter {
             'nextperiod' => [
                 'type' => PARAM_INT,
             ],
+            'time' => [
+                'type' => PARAM_INT,
+            ]
         ];
     }
 
@@ -131,6 +134,7 @@ class month_exporter extends exporter {
             'navigation' => $this->get_navigation($output),
             'weeks' => $this->get_weeks($output),
             'daynames' => $this->get_day_names($output),
+            'time' => $this->calendar->time
         ];
     }
 
index 106d81b..9809309 100644 (file)
@@ -31,7 +31,7 @@
     {
     }
 }}
-<span class="calendarwrapper" data-courseid="{{courseid}}">
+<span class="calendarwrapper" data-courseid="{{courseid}}" data-current-time="{{time}}">
     {{> core_calendar/month_header }}
     {{> core_calendar/month_navigation }}
     <table class="calendarmonth calendartable card-deck m-b-0">