MDL-60766 block_calendar_upcoming: stop summary modal not logged in
authorRyan Wyllie <ryan@moodle.com>
Fri, 10 Nov 2017 02:20:32 +0000 (02:20 +0000)
committerRyan Wyllie <ryan@moodle.com>
Fri, 10 Nov 2017 02:20:32 +0000 (02:20 +0000)
Stopped the JS from running on the block when the user is not logged in
because it attempts to load a summary modal when an event is clicked on
which results in a failed call to a webservice.

calendar/classes/external/calendar_upcoming_exporter.php
calendar/templates/calendar_upcoming_mini.mustache

index 42fe7b9..aead6d1 100644 (file)
@@ -87,6 +87,9 @@ class calendar_upcoming_exporter extends exporter {
                 'optional' => true,
                 'default' => 0,
             ],
+            'isloggedin' => [
+                'type' => PARAM_BOOL,
+            ],
         ];
     }
 
@@ -106,6 +109,7 @@ class calendar_upcoming_exporter extends exporter {
             'course' => $this->calendar->course->id,
         ]);
         $this->url = $url;
+        $return['isloggedin'] = isloggedin();
         $return['events'] = array_map(function($event) use ($cache, $output, $url) {
             $context = $cache->get_context($event);
             $course = $cache->get_course($event);
index 8f276be..c2317bd 100644 (file)
 <div id="calendar-upcoming-block-{{uniqid}}" data-template="core_calendar/upcoming_mini">
     {{> core_calendar/upcoming_mini}}
 </div>
+{{#isloggedin}}
 {{#js}}
 require(['jquery', 'core_calendar/calendar_view'], function($, CalendarView) {
     CalendarView.init($("#calendar-upcoming-block-{{uniqid}}"), 'upcoming');
 });
 {{/js}}
+{{/isloggedin}}