MDL-59672 core_calendar: set course event type on course context
authorSimey Lameze <simey@moodle.com>
Wed, 30 Aug 2017 02:45:05 +0000 (10:45 +0800)
committerSimey Lameze <simey@moodle.com>
Mon, 4 Sep 2017 01:12:05 +0000 (09:12 +0800)
calendar/amd/build/calendar.min.js
calendar/amd/build/modal_event_form.min.js
calendar/amd/src/calendar.js
calendar/amd/src/modal_event_form.js
calendar/lib.php

index 9d29445..accd4e6 100644 (file)
Binary files a/calendar/amd/build/calendar.min.js and b/calendar/amd/build/calendar.min.js differ
index f29703f..b27c823 100644 (file)
Binary files a/calendar/amd/build/modal_event_form.min.js and b/calendar/amd/build/modal_event_form.min.js differ
index ea10975..680c536 100644 (file)
@@ -64,7 +64,8 @@ define([
         NEW_EVENT_BUTTON: "[data-action='new-event-button']",
         DAY_CONTENT: "[data-region='day-content']",
         LOADING_ICON: '.loading-icon',
-        VIEW_DAY_LINK: "[data-action='view-day-link']"
+        VIEW_DAY_LINK: "[data-action='view-day-link']",
+        CALENDAR_MONTH_WRAPPER: ".calendarwrapper"
     };
 
     /**
@@ -254,7 +255,8 @@ define([
      * @param {object} eventFormModalPromise A promise reolved with the event form modal
      */
     var registerCalendarEventListeners = function(root, eventFormModalPromise) {
-        var body = $('body');
+        var body = $('body'),
+            courseId = $(root).find(SELECTORS.CALENDAR_MONTH_WRAPPER).data('courseid');
 
         body.on(CalendarEvents.created, function() {
             CalendarViewManager.reloadCurrentMonth(root);
@@ -283,7 +285,7 @@ define([
                 modal.setEventId(eventId);
                 modal.show();
             });
-
+            modal.setCourseId(courseId);
             return;
         });
     };
index cee039a..62ed463 100644 (file)
@@ -67,6 +67,7 @@ define([
         Modal.call(this, root);
         this.eventId = null;
         this.startTime = null;
+        this.courseId = null;
         this.reloadingBody = false;
         this.reloadingTitle = false;
         this.saveButton = this.getFooter().find(SELECTORS.SAVE_BUTTON);
@@ -76,6 +77,36 @@ define([
     ModalEventForm.TYPE = 'core_calendar-modal_event_form';
     ModalEventForm.prototype = Object.create(Modal.prototype);
     ModalEventForm.prototype.constructor = ModalEventForm;
+    
+    /**
+     * Set the course id to the given value.
+     *
+     * @method setCourseId
+     * @param {int} id The event id
+     */
+    ModalEventForm.prototype.setCourseId = function(id) {
+        this.courseId = id;
+    };
+
+    /**
+     * Retrieve the current course id, if any.
+     *
+     * @method getCourseId
+     * @return {int|null} The event id
+     */
+    ModalEventForm.prototype.getCourseId = function() {
+        return this.courseId;
+    };
+
+    /**
+     * Check if the modal has an course id.
+     *
+     * @method hasCourseId
+     * @return {bool}
+     */
+    ModalEventForm.prototype.hasCourseId = function() {
+        return this.courseId !== null;
+    };
 
     /**
      * Set the event id to the given value.
@@ -279,6 +310,10 @@ define([
             args.starttime = this.getStartTime();
         }
 
+        if(this.hasCourseId()) {
+            args.courseid = this.getCourseId();
+        }
+
         if (typeof formData !== 'undefined') {
             args.formdata = formData;
         }
index 3ad809b..f574472 100644 (file)
@@ -3537,6 +3537,7 @@ function calendar_output_fragment_event_form($args) {
     $data = null;
     $eventid = isset($args['eventid']) ? clean_param($args['eventid'], PARAM_INT) : null;
     $starttime = isset($args['starttime']) ? clean_param($args['starttime'], PARAM_INT) : null;
+    $courseid = isset($args['courseid']) ? clean_param($args['courseid'], PARAM_INT) : null;
     $event = null;
     $hasformdata = isset($args['formdata']) && !empty($args['formdata']);
     $formoptions = [];
@@ -3563,6 +3564,12 @@ function calendar_output_fragment_event_form($args) {
             true,
             $data
         );
+        if ($courseid != SITEID) {
+            $data['eventtype'] = 'course';
+            $data['courseid'] = $courseid;
+            $data['groupcourseid'] = $courseid;
+        }
+        $mform->set_data($data);
     } else {
         $event = calendar_event::load($eventid);
         $event->count_repeats();