MDL-59671 core_calendar: check if the event can be deleted
authorSimey Lameze <simey@moodle.com>
Fri, 4 Aug 2017 06:19:38 +0000 (14:19 +0800)
committerSimey Lameze <simey@moodle.com>
Tue, 8 Aug 2017 03:44:11 +0000 (11:44 +0800)
calendar/amd/build/calendar.min.js
calendar/amd/build/summary_modal.min.js
calendar/amd/src/calendar.js
calendar/amd/src/summary_modal.js
calendar/classes/external/event_exporter.php

index fab055d..5c9fb29 100644 (file)
Binary files a/calendar/amd/build/calendar.min.js and b/calendar/amd/build/calendar.min.js differ
index 9c0bb22..8db1abb 100644 (file)
Binary files a/calendar/amd/build/summary_modal.min.js and b/calendar/amd/build/summary_modal.min.js differ
index 1843984..653a53c 100644 (file)
@@ -130,11 +130,13 @@ define([
             var modalParams = {
                 title: eventData.name,
                 type: SummaryModal.TYPE,
-                body: Templates.render('core_calendar/event_summary_body', eventData)
+                body: Templates.render('core_calendar/event_summary_body', eventData),
+                templateContext: {
+                    canedit: eventData.canedit,
+                    candelete: eventData.candelete
+                }
             };
-            if (!eventData.caneditevent) {
-                modalParams.footer = '';
-            }
+
             // Create the modal.
             return ModalFactory.create(modalParams);
 
index b758f45..d2c0d69 100644 (file)
@@ -41,14 +41,6 @@ define(['jquery', 'core/str', 'core/notification', 'core/custom_interaction_even
      */
     var ModalEventSummary = function(root) {
         Modal.call(this, root);
-
-        if (!this.getEditButton().length) {
-            Notification.exception({message: 'No edit button found'});
-        }
-
-        if (!this.getDeleteButton().length) {
-            Notification.exception({message: 'No delete button found'});
-        }
     };
 
     ModalEventSummary.TYPE = 'core_calendar-event_summary';
index 128fb8c..cefb7f8 100644 (file)
@@ -175,7 +175,9 @@ class event_exporter extends exporter {
                 'optional' => true,
                 'default' => null,
                 'null' => NULL_ALLOWED
-            ]
+            ],
+            'isactionevent' => ['type' => PARAM_BOOL],
+            'candelete' => ['type' => PARAM_BOOL]
         ];
     }
 
@@ -191,10 +193,12 @@ class event_exporter extends exporter {
         $legacyevent = container::get_event_mapper()->from_event_to_legacy_event($event);
 
         $context = $this->related['context'];
+        $values['isactionevent'] = false;
         if ($moduleproxy = $event->get_course_module()) {
             $modulename = $moduleproxy->get('modname');
             $moduleid = $moduleproxy->get('id');
             $url = new \moodle_url(sprintf('/mod/%s/view.php', $modulename), ['id' => $moduleid]);
+            $values['isactionevent'] = true;
         } else {
             // TODO MDL-58866 We do not have any way to find urls for events outside of course modules.
             global $CFG;
@@ -220,7 +224,9 @@ class event_exporter extends exporter {
             $coursesummaryexporter = new course_summary_exporter($course, ['context' => $context]);
             $values['course'] = $coursesummaryexporter->export($output);
         }
+
         $values['canedit'] = calendar_edit_event_allowed($legacyevent);
+        $values['candelete'] = (!$values['isactionevent'] && $values['canedit']);
 
         // Handle event subscription.
         $values['subscription'] = null;