MDL-59671 core_calendar: action events edition needs to be on module
authorSimey Lameze <simey@moodle.com>
Mon, 7 Aug 2017 02:59:52 +0000 (10:59 +0800)
committerSimey Lameze <simey@moodle.com>
Tue, 8 Aug 2017 03:44:27 +0000 (11:44 +0800)
calendar/amd/build/calendar.min.js
calendar/amd/build/events.min.js
calendar/amd/build/summary_modal.min.js
calendar/amd/src/calendar.js
calendar/amd/src/events.js
calendar/amd/src/summary_modal.js
calendar/classes/external/event_exporter.php
calendar/templates/event_summary_body.mustache

index 5c9fb29..f21a625 100644 (file)
Binary files a/calendar/amd/build/calendar.min.js and b/calendar/amd/build/calendar.min.js differ
index 938b804..0c310d9 100644 (file)
Binary files a/calendar/amd/build/events.min.js and b/calendar/amd/build/events.min.js differ
index 8db1abb..358bad0 100644 (file)
Binary files a/calendar/amd/build/summary_modal.min.js and b/calendar/amd/build/summary_modal.min.js differ
index 653a53c..a08f1c3 100644 (file)
@@ -198,6 +198,10 @@ define([
         body.on(CalendarEvents.updated, function() {
             window.location.reload();
         });
+        body.on(CalendarEvents.editActionEvent, function(e, url) {
+            // Action events needs to be edit directly on the course module.
+            window.location.assign(url);
+        });
 
         eventFormModalPromise.then(function(modal) {
             // When something within the calendar tells us the user wants
index 80ec8ca..47aac12 100644 (file)
@@ -27,6 +27,7 @@ define([], function() {
         created: 'calendar-events:created',
         deleted: 'calendar-events:deleted',
         updated: 'calendar-events:updated',
-        editEvent: 'calendar-events:edit_event'
+        editEvent: 'calendar-events:edit_event',
+        editActionEvent: 'calendar-events:edit_action_event'
     };
 });
index d2c0d69..4a668be 100644 (file)
@@ -89,6 +89,26 @@ define(['jquery', 'core/str', 'core/notification', 'core/custom_interaction_even
         return this.getBody().find(SELECTORS.ROOT).attr('data-event-id');
     };
 
+    /**
+     * Get the url for the event being shown in this modal.
+     *
+     * @method getEventUrl
+     * @return {String}
+     */
+    ModalEventSummary.prototype.getEditUrl = function() {
+        return this.getBody().find(SELECTORS.ROOT).attr('data-edit-url');
+    };
+
+    /**
+     * Is this an action event.
+     *
+     * @method getEventUrl
+     * @return {String}
+     */
+    ModalEventSummary.prototype.isActionEvent = function() {
+        return (this.getBody().find(SELECTORS.ROOT).attr('data-action-event') == 'true');
+    };
+
     /**
      * Set up all of the event handling for the modal.
      *
@@ -132,9 +152,16 @@ define(['jquery', 'core/str', 'core/notification', 'core/custom_interaction_even
         ]);
 
         this.getEditButton().on(CustomEvents.events.activate, function(e, data) {
-            // When the edit button is clicked we fire an event for the calendar UI to handle.
-            // We don't care how the UI chooses to handle it.
-            $('body').trigger(CalendarEvents.editEvent, [this.getEventId()]);
+
+            if (this.isActionEvent()) {
+                // Action events cannot be edited on the event form and must be redirected to the module UI.
+                $('body').trigger(CalendarEvents.editActionEvent, [this.getEditUrl()]);
+            } else {
+                // When the edit button is clicked we fire an event for the calendar UI to handle.
+                // We don't care how the UI chooses to handle it.
+                $('body').trigger(CalendarEvents.editEvent, [this.getEventId()]);
+            }
+
             // There is nothing else for us to do so let's hide.
             this.hide();
 
index cefb7f8..dd189b7 100644 (file)
@@ -157,6 +157,10 @@ class event_exporter extends exporter {
     protected static function define_other_properties() {
         return [
             'url' => ['type' => PARAM_URL],
+            'editurl' => [
+                'type' => PARAM_URL,
+                'optional' => true
+            ],
             'icon' => [
                 'type' => event_icon_exporter::read_properties_definition(),
             ],
@@ -198,7 +202,13 @@ class event_exporter extends exporter {
             $modulename = $moduleproxy->get('modname');
             $moduleid = $moduleproxy->get('id');
             $url = new \moodle_url(sprintf('/mod/%s/view.php', $modulename), ['id' => $moduleid]);
+
             $values['isactionevent'] = true;
+
+            // Build edit event url for action events.
+            $params = array('update' => $moduleid, 'return' => true, 'sesskey' => sesskey());
+            $editurl = new \moodle_url('/course/mod.php', $params);
+            $values['editurl'] = $editurl->out(false);
         } else {
             // TODO MDL-58866 We do not have any way to find urls for events outside of course modules.
             global $CFG;
index d054f4f..e5301bd 100644 (file)
@@ -26,7 +26,8 @@
         "eventtype": "open"
     }
 }}
-<div data-region="summary-modal-container" data-event-id="{{id}}" data-event-title="{{name}}">
+<div data-region="summary-modal-container" data-event-id="{{id}}" data-event-title="{{name}}"
+     data-action-event="{{isactionevent}}" data-edit-url="{{editurl}}">
     <h4>{{#str}} when, core_calendar {{/str}}</h4>
     {{#userdate}} {{timestart}}, {{#str}} strftimerecentfull {{/str}} {{/userdate}}
     <br>