mirror of
https://github.com/moodle/moodle.git
synced 2025-04-20 16:04:25 +02:00
MDL-59890 calendar: Select current category when adding event
This commit is contained in:
parent
936235133a
commit
d097bfdda3
2
calendar/amd/build/calendar.min.js
vendored
2
calendar/amd/build/calendar.min.js
vendored
@ -1 +1 @@
|
||||
define(["jquery","core/ajax","core/str","core/templates","core/notification","core/custom_interaction_events","core/modal_events","core/modal_factory","core_calendar/modal_event_form","core_calendar/summary_modal","core_calendar/repository","core_calendar/events","core_calendar/view_manager"],function(a,b,c,d,e,f,g,h,i,j,k,l,m){var n={ROOT:"[data-region='calendar']",DAY:"[data-region='day']",EVENT_ITEM:"[data-region='event-item']",EVENT_LINK:"[data-action='view-event']",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']",CALENDAR_MONTH_WRAPPER:".calendarwrapper",COURSE_SELECTOR:'select[name="course"]',TODAY:".today"},o=function(a){var b="type"+a;return c.get_string(b,"core_calendar").then(function(a){return a})},p=function(a){k.getEventById(a).then(function(b){if(!b.event)throw new Error("Error encountered while trying to fetch calendar event with ID: "+a);var c=b.event;return o(c.eventtype).then(function(a){return c.eventtype=a,c})}).then(function(a){var b={title:a.name,type:j.TYPE,body:d.render("core_calendar/event_summary_body",a),templateContext:{canedit:a.canedit,candelete:a.candelete,isactionevent:a.isactionevent,url:a.url}};return h.create(b)}).done(function(a){a.getRoot().on(g.hidden,function(){a.destroy()}),a.show()}).fail(e.exception)},q=function(b,c,f,g){var h=null,i=g.attr("data-day-timestamp");f&&(h=f.attr("data-day-timestamp")),f&&h==i||d.render("core/loading",{}).then(function(a,b){g.find(n.DAY_CONTENT).addClass("hidden"),d.appendNodeContents(g,a,b),f&&(f.find(n.DAY_CONTENT).addClass("hidden"),d.appendNodeContents(f,a,b))}).then(function(){return k.updateEventStartDay(c,i)}).then(function(){a("body").trigger(l.eventMoved,[c,f,g])}).always(function(){var a=g.find(n.LOADING_ICON);if(g.find(n.DAY_CONTENT).removeClass("hidden"),d.replaceNode(a,"",""),f){var b=f.find(n.LOADING_ICON);f.find(n.DAY_CONTENT).removeClass("hidden"),d.replaceNode(b,"","")}}).fail(e.exception)},r=function(a){var b=a.find(n.NEW_EVENT_BUTTON),c=b.attr("data-context-id");return h.create({type:i.TYPE,large:!0,templateContext:{contextid:c}})},s=function(b,c){var d=a("body"),f=a(b).find(n.CALENDAR_MONTH_WRAPPER).data("courseid");d.on(l.created,function(){m.reloadCurrentMonth(b)}),d.on(l.deleted,function(){m.reloadCurrentMonth(b)}),d.on(l.updated,function(){m.reloadCurrentMonth(b)}),d.on(l.editActionEvent,function(a,b){window.location.assign(b)}),d.on(l.moveEvent,q),d.on(l.eventMoved,function(){m.reloadCurrentMonth(b)}),c.then(function(a){d.on(l.editEvent,function(b,c){a.setEventId(c),a.show()}),a.setCourseId(f)}).fail(e.exception)},t=function(b){b.on("click",n.EVENT_ITEM,function(b){b.preventDefault(),b.stopPropagation();var c=a(b.target),d=null;d=c.is(n.EVENT_LINK)?c.attr("data-event-id"):c.find(n.EVENT_LINK).attr("data-event-id"),p(d)}),b.on("change",n.COURSE_SELECTOR,function(){var c=a(this),d=c.val();m.reloadCurrentMonth(b,d,null).then(function(){return b.find(n.COURSE_SELECTOR).val(d)}).fail(e.exception)});var c=r(b);s(b,c),b.on("click",n.NEW_EVENT_BUTTON,function(a){c.then(function(a){var c=b.find(n.TODAY);c.length||a.setStartTime(b.find(n.DAY).attr("data-new-event-timestamp")),a.show()}).fail(e.exception),a.preventDefault()}),b.on("click",n.DAY,function(b){var d=a(b.target);if(!d.is(n.VIEW_DAY_LINK)){var f=a(this).attr("data-new-event-timestamp");c.then(function(a){a.setStartTime(f),a.show()}).fail(e.exception),b.preventDefault()}})};return{init:function(b){b=a(b),m.init(b),t(b)}}});
|
||||
define(["jquery","core/ajax","core/str","core/templates","core/notification","core/custom_interaction_events","core/modal_events","core/modal_factory","core_calendar/modal_event_form","core_calendar/summary_modal","core_calendar/repository","core_calendar/events","core_calendar/view_manager"],function(a,b,c,d,e,f,g,h,i,j,k,l,m){var n={ROOT:"[data-region='calendar']",DAY:"[data-region='day']",EVENT_ITEM:"[data-region='event-item']",EVENT_LINK:"[data-action='view-event']",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']",CALENDAR_MONTH_WRAPPER:".calendarwrapper",COURSE_SELECTOR:'select[name="course"]',TODAY:".today"},o=function(a){var b="type"+a;return c.get_string(b,"core_calendar").then(function(a){return a})},p=function(a){k.getEventById(a).then(function(b){if(!b.event)throw new Error("Error encountered while trying to fetch calendar event with ID: "+a);var c=b.event;return o(c.eventtype).then(function(a){return c.eventtype=a,c})}).then(function(a){var b={title:a.name,type:j.TYPE,body:d.render("core_calendar/event_summary_body",a),templateContext:{canedit:a.canedit,candelete:a.candelete,isactionevent:a.isactionevent,url:a.url}};return h.create(b)}).done(function(a){a.getRoot().on(g.hidden,function(){a.destroy()}),a.show()}).fail(e.exception)},q=function(b,c,f,g){var h=null,i=g.attr("data-day-timestamp");f&&(h=f.attr("data-day-timestamp")),f&&h==i||d.render("core/loading",{}).then(function(a,b){g.find(n.DAY_CONTENT).addClass("hidden"),d.appendNodeContents(g,a,b),f&&(f.find(n.DAY_CONTENT).addClass("hidden"),d.appendNodeContents(f,a,b))}).then(function(){return k.updateEventStartDay(c,i)}).then(function(){a("body").trigger(l.eventMoved,[c,f,g])}).always(function(){var a=g.find(n.LOADING_ICON);if(g.find(n.DAY_CONTENT).removeClass("hidden"),d.replaceNode(a,"",""),f){var b=f.find(n.LOADING_ICON);f.find(n.DAY_CONTENT).removeClass("hidden"),d.replaceNode(b,"","")}}).fail(e.exception)},r=function(a){var b=a.find(n.NEW_EVENT_BUTTON),c=b.attr("data-context-id");return h.create({type:i.TYPE,large:!0,templateContext:{contextid:c}})},s=function(b,c){var d=a("body");d.on(l.created,function(){m.reloadCurrentMonth(b)}),d.on(l.deleted,function(){m.reloadCurrentMonth(b)}),d.on(l.updated,function(){m.reloadCurrentMonth(b)}),d.on(l.editActionEvent,function(a,b){window.location.assign(b)}),d.on(l.moveEvent,q),d.on(l.eventMoved,function(){m.reloadCurrentMonth(b)}),c.then(function(a){d.on(l.editEvent,function(b,c){a.setEventId(c),a.show()})}).fail(e.exception)},t=function(b){b.on("click",n.EVENT_ITEM,function(b){b.preventDefault(),b.stopPropagation();var c=a(b.target),d=null;d=c.is(n.EVENT_LINK)?c.attr("data-event-id"):c.find(n.EVENT_LINK).attr("data-event-id"),p(d)}),b.on("change",n.COURSE_SELECTOR,function(){var c=a(this),d=c.val();m.reloadCurrentMonth(b,d,null).then(function(){return b.find(n.COURSE_SELECTOR).val(d)}).fail(e.exception)});var c=r(b);s(b,c),f.define(b,[f.events.activate]),b.on("click",n.NEW_EVENT_BUTTON,function(a){c.then(function(a){var c=b.find(n.CALENDAR_MONTH_WRAPPER);a.setCourseId(c.data("courseid"));var d=c.data("categoryid");"undefined"!=typeof d&&a.setCategoryId(d);var e=b.find(n.TODAY);e.length||a.setStartTime(b.find(n.DAY).attr("data-new-event-timestamp")),a.show()}).fail(e.exception),a.preventDefault()}),b.on("click",n.DAY,function(b){var d=a(b.target);if(!d.is(n.VIEW_DAY_LINK)){var f=a(this).attr("data-new-event-timestamp");c.then(function(a){var b=d.closest(n.CALENDAR_MONTH_WRAPPER);a.setCourseId(b.data("courseid"));var c=b.data("categoryid");"undefined"!=typeof c&&a.setCategoryId(c),a.setStartTime(f),a.show()}).fail(e.exception),b.preventDefault()}})};return{init:function(b){b=a(b),m.init(b),t(b)}}});
|
2
calendar/amd/build/modal_event_form.min.js
vendored
2
calendar/amd/build/modal_event_form.min.js
vendored
@ -1 +1 @@
|
||||
define(["jquery","core/event","core/str","core/notification","core/templates","core/custom_interaction_events","core/modal","core/modal_registry","core/fragment","core_calendar/events","core_calendar/repository"],function(a,b,c,d,e,f,g,h,i,j,k){var l=!1,m={SAVE_BUTTON:'[data-action="save"]',LOADING_ICON_CONTAINER:'[data-region="loading-icon-container"]'},n=function(a){g.call(this,a),this.eventId=null,this.startTime=null,this.courseId=null,this.reloadingBody=!1,this.reloadingTitle=!1,this.saveButton=this.getFooter().find(m.SAVE_BUTTON)};return n.TYPE="core_calendar-modal_event_form",n.prototype=Object.create(g.prototype),n.prototype.constructor=n,n.prototype.setCourseId=function(a){this.courseId=a},n.prototype.getCourseId=function(){return this.courseId},n.prototype.hasCourseId=function(){return null!==this.courseId},n.prototype.setEventId=function(a){this.eventId=a},n.prototype.getEventId=function(){return this.eventId},n.prototype.hasEventId=function(){return null!==this.eventId},n.prototype.setStartTime=function(a){this.startTime=a},n.prototype.getStartTime=function(){return this.startTime},n.prototype.hasStartTime=function(){return null!==this.startTime},n.prototype.getForm=function(){return this.getBody().find("form")},n.prototype.disableButtons=function(){this.saveButton.prop("disabled",!0)},n.prototype.enableButtons=function(){this.saveButton.prop("disabled",!1)},n.prototype.reloadTitleContent=function(){return this.reloadingTitle?this.titlePromise:(this.reloadingTitle=!0,this.hasEventId()?this.titlePromise=c.get_string("editevent","calendar"):this.titlePromise=c.get_string("newevent","calendar"),this.titlePromise.then(function(a){return this.setTitle(a),a}.bind(this)).always(function(){this.reloadingTitle=!1}.bind(this)),this.titlePromise)},n.prototype.reloadBodyContent=function(a){if(this.reloadingBody)return this.bodyPromise;this.reloadingBody=!0,this.disableButtons();var b=this.saveButton.attr("data-context-id"),c={};return this.hasEventId()&&(c.eventid=this.getEventId()),this.hasStartTime()&&(c.starttime=this.getStartTime()),this.hasCourseId()&&(c.courseid=this.getCourseId()),"undefined"!=typeof a&&(c.formdata=a),this.bodyPromise=i.loadFragment("calendar","event_form",b,c),this.setBody(this.bodyPromise),this.bodyPromise.then(function(){this.enableButtons()}.bind(this))["catch"](d.exception).always(function(){this.reloadingBody=!1}.bind(this)),this.bodyPromise},n.prototype.reloadAllContent=function(){return a.when(this.reloadTitleContent(),this.reloadBodyContent())},n.prototype.show=function(){this.reloadAllContent(),g.prototype.show.call(this)},n.prototype.hide=function(){g.prototype.hide.call(this),this.setEventId(null),this.setStartTime(null)},n.prototype.getFormData=function(){return this.getForm().serialize()},n.prototype.save=function(){var b=this.saveButton.find(m.LOADING_ICON_CONTAINER);b.removeClass("hidden"),this.disableButtons();var c=this.getFormData();return k.submitCreateUpdateForm(c).then(function(b){return b.validationerror?this.reloadBodyContent(c):(this.hide(),void(this.hasEventId()?a("body").trigger(j.updated,[b.event]):a("body").trigger(j.created,[b.event])))}.bind(this)).always(function(){b.addClass("hidden"),this.enableButtons()}.bind(this))["catch"](d.exception)},n.prototype.registerEventListeners=function(){g.prototype.registerEventListeners.call(this),this.getModal().on(f.events.activate,m.SAVE_BUTTON,function(a,b){this.getForm().submit(),b.originalEvent.preventDefault(),a.stopPropagation()}.bind(this)),this.getModal().on("submit",function(a){this.save(),a.preventDefault(),a.stopPropagation()}.bind(this))},l||(h.register(n.TYPE,n,"calendar/modal_event_form"),l=!0),n});
|
||||
define(["jquery","core/event","core/str","core/notification","core/templates","core/custom_interaction_events","core/modal","core/modal_registry","core/fragment","core_calendar/events","core_calendar/repository"],function(a,b,c,d,e,f,g,h,i,j,k){var l=!1,m={SAVE_BUTTON:'[data-action="save"]',LOADING_ICON_CONTAINER:'[data-region="loading-icon-container"]'},n=function(a){g.call(this,a),this.eventId=null,this.startTime=null,this.courseId=null,this.categoryId=null,this.reloadingBody=!1,this.reloadingTitle=!1,this.saveButton=this.getFooter().find(m.SAVE_BUTTON)};return n.TYPE="core_calendar-modal_event_form",n.prototype=Object.create(g.prototype),n.prototype.constructor=n,n.prototype.setCourseId=function(a){this.courseId=a},n.prototype.getCourseId=function(){return this.courseId},n.prototype.setCategoryId=function(a){this.categoryId=a},n.prototype.getCategoryId=function(){return this.categoryId},n.prototype.hasCourseId=function(){return null!==this.courseId},n.prototype.hasCategoryId=function(){return null!==this.categoryId},n.prototype.setEventId=function(a){this.eventId=a},n.prototype.getEventId=function(){return this.eventId},n.prototype.hasEventId=function(){return null!==this.eventId},n.prototype.setStartTime=function(a){this.startTime=a},n.prototype.getStartTime=function(){return this.startTime},n.prototype.hasStartTime=function(){return null!==this.startTime},n.prototype.getForm=function(){return this.getBody().find("form")},n.prototype.disableButtons=function(){this.saveButton.prop("disabled",!0)},n.prototype.enableButtons=function(){this.saveButton.prop("disabled",!1)},n.prototype.reloadTitleContent=function(){return this.reloadingTitle?this.titlePromise:(this.reloadingTitle=!0,this.hasEventId()?this.titlePromise=c.get_string("editevent","calendar"):this.titlePromise=c.get_string("newevent","calendar"),this.titlePromise.then(function(a){return this.setTitle(a),a}.bind(this)).always(function(){this.reloadingTitle=!1}.bind(this)).fail(d.exception),this.titlePromise)},n.prototype.reloadBodyContent=function(a){if(this.reloadingBody)return this.bodyPromise;this.reloadingBody=!0,this.disableButtons();var b=this.saveButton.attr("data-context-id"),c={};return this.hasEventId()&&(c.eventid=this.getEventId()),this.hasStartTime()&&(c.starttime=this.getStartTime()),this.hasCourseId()&&(c.courseid=this.getCourseId()),this.hasCategoryId()&&(c.categoryid=this.getCategoryId()),"undefined"!=typeof a&&(c.formdata=a),this.bodyPromise=i.loadFragment("calendar","event_form",b,c),this.setBody(this.bodyPromise),this.bodyPromise.then(function(){this.enableButtons()}.bind(this)).fail(d.exception).always(function(){this.reloadingBody=!1}.bind(this)).fail(d.exception),this.bodyPromise},n.prototype.reloadAllContent=function(){return a.when(this.reloadTitleContent(),this.reloadBodyContent())},n.prototype.show=function(){this.reloadAllContent(),g.prototype.show.call(this)},n.prototype.hide=function(){g.prototype.hide.call(this),this.setEventId(null),this.setStartTime(null),this.setCourseId(null),this.setCategoryId(null)},n.prototype.getFormData=function(){return this.getForm().serialize()},n.prototype.save=function(){var b=this.saveButton.find(m.LOADING_ICON_CONTAINER);b.removeClass("hidden"),this.disableButtons();var c=this.getFormData();return k.submitCreateUpdateForm(c).then(function(b){return b.validationerror?void this.reloadBodyContent(c):(this.hide(),void(this.hasEventId()?a("body").trigger(j.updated,[b.event]):a("body").trigger(j.created,[b.event])))}.bind(this)).always(function(){b.addClass("hidden"),this.enableButtons()}.bind(this)).fail(d.exception)},n.prototype.registerEventListeners=function(){g.prototype.registerEventListeners.call(this),this.getModal().on(f.events.activate,m.SAVE_BUTTON,function(a,b){this.getForm().submit(),b.originalEvent.preventDefault(),a.stopPropagation()}.bind(this)),this.getModal().on("submit",function(a){this.save(),a.preventDefault(),a.stopPropagation()}.bind(this))},l||(h.register(n.TYPE,n,"calendar/modal_event_form"),l=!0),n});
|
@ -223,8 +223,7 @@ define([
|
||||
* @param {object} eventFormModalPromise A promise reolved with the event form modal
|
||||
*/
|
||||
var registerCalendarEventListeners = function(root, eventFormModalPromise) {
|
||||
var body = $('body'),
|
||||
courseId = $(root).find(SELECTORS.CALENDAR_MONTH_WRAPPER).data('courseid');
|
||||
var body = $('body');
|
||||
|
||||
body.on(CalendarEvents.created, function() {
|
||||
CalendarViewManager.reloadCurrentMonth(root);
|
||||
@ -246,14 +245,14 @@ define([
|
||||
CalendarViewManager.reloadCurrentMonth(root);
|
||||
});
|
||||
|
||||
eventFormModalPromise.then(function(modal) {
|
||||
eventFormModalPromise
|
||||
.then(function(modal) {
|
||||
// When something within the calendar tells us the user wants
|
||||
// to edit an event then show the event form modal.
|
||||
body.on(CalendarEvents.editEvent, function(e, eventId) {
|
||||
modal.setEventId(eventId);
|
||||
modal.show();
|
||||
});
|
||||
modal.setCourseId(courseId);
|
||||
return;
|
||||
})
|
||||
.fail(Notification.exception);
|
||||
@ -299,8 +298,16 @@ define([
|
||||
registerCalendarEventListeners(root, eventFormPromise);
|
||||
|
||||
// Bind click event on the new event button.
|
||||
CustomEvents.define(root, [CustomEvents.events.activate]);
|
||||
root.on('click', SELECTORS.NEW_EVENT_BUTTON, function(e) {
|
||||
eventFormPromise.then(function(modal) {
|
||||
var wrapper = root.find(SELECTORS.CALENDAR_MONTH_WRAPPER);
|
||||
modal.setCourseId(wrapper.data('courseid'));
|
||||
var categoryId = wrapper.data('categoryid');
|
||||
if (typeof categoryId !== 'undefined') {
|
||||
modal.setCategoryId(categoryId);
|
||||
}
|
||||
|
||||
// Attempt to find the cell for today.
|
||||
// If it can't be found, then use the start time of the first day on the calendar.
|
||||
var today = root.find(SELECTORS.TODAY);
|
||||
@ -323,6 +330,15 @@ define([
|
||||
if (!target.is(SELECTORS.VIEW_DAY_LINK)) {
|
||||
var startTime = $(this).attr('data-new-event-timestamp');
|
||||
eventFormPromise.then(function(modal) {
|
||||
var wrapper = target.closest(SELECTORS.CALENDAR_MONTH_WRAPPER);
|
||||
|
||||
modal.setCourseId(wrapper.data('courseid'));
|
||||
|
||||
var categoryId = wrapper.data('categoryid');
|
||||
if (typeof categoryId !== 'undefined') {
|
||||
modal.setCategoryId(categoryId);
|
||||
}
|
||||
|
||||
modal.setStartTime(startTime);
|
||||
modal.show();
|
||||
return;
|
||||
|
@ -65,6 +65,7 @@ define([
|
||||
this.eventId = null;
|
||||
this.startTime = null;
|
||||
this.courseId = null;
|
||||
this.categoryId = null;
|
||||
this.reloadingBody = false;
|
||||
this.reloadingTitle = false;
|
||||
this.saveButton = this.getFooter().find(SELECTORS.SAVE_BUTTON);
|
||||
@ -94,6 +95,26 @@ define([
|
||||
return this.courseId;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the category id to the given value.
|
||||
*
|
||||
* @method setCategoryId
|
||||
* @param {int} id The event id
|
||||
*/
|
||||
ModalEventForm.prototype.setCategoryId = function(id) {
|
||||
this.categoryId = id;
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieve the current category id, if any.
|
||||
*
|
||||
* @method getCategoryId
|
||||
* @return {int|null} The event id
|
||||
*/
|
||||
ModalEventForm.prototype.getCategoryId = function() {
|
||||
return this.categoryId;
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if the modal has an course id.
|
||||
*
|
||||
@ -104,6 +125,16 @@ define([
|
||||
return this.courseId !== null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if the modal has an category id.
|
||||
*
|
||||
* @method hasCategoryId
|
||||
* @return {bool}
|
||||
*/
|
||||
ModalEventForm.prototype.hasCategoryId = function() {
|
||||
return this.categoryId !== null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the event id to the given value.
|
||||
*
|
||||
@ -220,7 +251,8 @@ define([
|
||||
.always(function() {
|
||||
this.reloadingTitle = false;
|
||||
return;
|
||||
}.bind(this));
|
||||
}.bind(this))
|
||||
.fail(Notification.exception);
|
||||
|
||||
return this.titlePromise;
|
||||
};
|
||||
@ -261,6 +293,10 @@ define([
|
||||
args.courseid = this.getCourseId();
|
||||
}
|
||||
|
||||
if (this.hasCategoryId()) {
|
||||
args.categoryid = this.getCategoryId();
|
||||
}
|
||||
|
||||
if (typeof formData !== 'undefined') {
|
||||
args.formdata = formData;
|
||||
}
|
||||
@ -273,11 +309,12 @@ define([
|
||||
this.enableButtons();
|
||||
return;
|
||||
}.bind(this))
|
||||
.catch(Notification.exception)
|
||||
.fail(Notification.exception)
|
||||
.always(function() {
|
||||
this.reloadingBody = false;
|
||||
return;
|
||||
}.bind(this));
|
||||
}.bind(this))
|
||||
.fail(Notification.exception);
|
||||
|
||||
return this.bodyPromise;
|
||||
};
|
||||
@ -321,6 +358,8 @@ define([
|
||||
Modal.prototype.hide.call(this);
|
||||
this.setEventId(null);
|
||||
this.setStartTime(null);
|
||||
this.setCourseId(null);
|
||||
this.setCategoryId(null);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -361,7 +400,8 @@ define([
|
||||
// If there was a server side validation error then
|
||||
// we need to re-request the rendered form from the server
|
||||
// in order to display the error for the user.
|
||||
return this.reloadBodyContent(formData);
|
||||
this.reloadBodyContent(formData);
|
||||
return;
|
||||
} else {
|
||||
// No problemo! Our work here is done.
|
||||
this.hide();
|
||||
@ -382,8 +422,10 @@ define([
|
||||
// the loading icon and re-enable the buttons.
|
||||
loadingContainer.addClass('hidden');
|
||||
this.enableButtons();
|
||||
|
||||
return;
|
||||
}.bind(this))
|
||||
.catch(Notification.exception);
|
||||
.fail(Notification.exception);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -902,6 +902,7 @@ class core_calendar_external extends external_api {
|
||||
// TODO: Copy what we do in calendar/view.php.
|
||||
$context = \context_user::instance($USER->id);
|
||||
self::validate_context($context);
|
||||
$PAGE->set_url('/calendar/');
|
||||
|
||||
if ($courseid != SITEID && !empty($courseid)) {
|
||||
// Course ID must be valid and existing.
|
||||
|
@ -1217,17 +1217,20 @@ function calendar_get_events($tstart, $tend, $users, $groups, $courses,
|
||||
}
|
||||
|
||||
if ((is_array($categories) && !empty($categories)) || is_numeric($categories)) {
|
||||
if(!empty($whereclause)) $whereclause .= ' OR';
|
||||
if (!empty($whereclause)) {
|
||||
$whereclause .= ' OR';
|
||||
}
|
||||
list($insqlcategories, $inparamscategories) = $DB->get_in_or_equal($categories, SQL_PARAMS_NAMED);
|
||||
$whereclause .= " (e.groupid = 0 AND e.courseid = 0 AND e.categoryid $insqlcategories)";
|
||||
$params = array_merge($params, $inparamscategories);
|
||||
} else if ($categories === true) {
|
||||
// Events from ALL categories.
|
||||
if(!empty($whereclause)) $whereclause .= ' OR';
|
||||
if (!empty($whereclause)) {
|
||||
$whereclause .= ' OR';
|
||||
}
|
||||
$whereclause .= ' (e.groupid = 0 AND e.courseid = 0 AND e.categoryid != 0)';
|
||||
}
|
||||
|
||||
|
||||
// Security check: if, by now, we have NOTHING in $whereclause, then it means
|
||||
// that NO event-selecting clauses were defined. Thus, we won't be returning ANY
|
||||
// events no matter what. Allowing the code to proceed might return a completely
|
||||
@ -3244,6 +3247,7 @@ function calendar_output_fragment_event_form($args) {
|
||||
$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;
|
||||
$categoryid = isset($args['categoryid']) ? clean_param($args['categoryid'], PARAM_INT) : null;
|
||||
$event = null;
|
||||
$hasformdata = isset($args['formdata']) && !empty($args['formdata']);
|
||||
$context = \context_user::instance($USER->id);
|
||||
@ -3276,6 +3280,9 @@ function calendar_output_fragment_event_form($args) {
|
||||
$data['eventtype'] = 'course';
|
||||
$data['courseid'] = $courseid;
|
||||
$data['groupcourseid'] = $courseid;
|
||||
} else if (!empty($categoryid)) {
|
||||
$data['eventtype'] = 'category';
|
||||
$data['categoryid'] = $categoryid;
|
||||
}
|
||||
$mform->set_data($data);
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user