Merge branch 'MDL-68728-master-2' of git://github.com/andrewnicols/moodle

This commit is contained in:
Sara Arjona 2020-05-18 20:24:17 +02:00
commit 0a3efb5689
9 changed files with 46 additions and 27 deletions

View file

@ -1,2 +1,2 @@
define ("core_calendar/crud",["jquery","core/str","core/notification","core/custom_interaction_events","core/modal","core/modal_registry","core/modal_factory","core/modal_events","core_calendar/modal_event_form","core_calendar/repository","core_calendar/events","core_calendar/modal_delete","core_calendar/selectors","core/pending"],function(a,b,c,d,e,f,g,h,i,j,k,l,m,n){function o(d,e,f){var i=new n("core_calendar/crud:confirmDeletion"),m=[{key:"deleteevent",component:"calendar"}];f=parseInt(f,10);var o,p=1<f;if(p){m.push({key:"confirmeventseriesdelete",component:"calendar",param:{name:e,count:f}});o=g.create({type:l.TYPE})}else{m.push({key:"confirmeventdelete",component:"calendar",param:e});o=g.create({type:g.types.SAVE_CANCEL})}var q=b.get_strings(m),r=a.when(q,o).then(function(b,e){e.setTitle(b[0]);e.setBody(b[1]);if(!p){e.setSaveButtonText(b[0])}e.show();e.getRoot().on(h.save,function(){var b=new n("calendar/crud:initModal:deletedevent");j.deleteEvent(d,!1).then(function(){a("body").trigger(k.deleted,[d,!1])}).then(b.resolve).catch(c.exception)});e.getRoot().on(k.deleteAll,function(){var b=new n("calendar/crud:initModal:deletedallevent");j.deleteEvent(d,!0).then(function(){a("body").trigger(k.deleted,[d,!0])}).then(b.resolve).catch(c.exception)});return e}).then(function(a){i.resolve();return a}).catch(c.exception);return r}return{registerRemove:function(b){b.on("click",m.actions.remove,function(b){var c=a(this).closest(m.eventItem),d=c.data("eventId"),e=c.data("eventTitle"),f=c.data("eventCount");o(d,e,f);b.preventDefault()})},registerEditListeners:function(b,d){d.then(function(c){a("body").on(k.editEvent,function(a,d){var e=b.find(m.wrapper);c.setEventId(d);c.setContextId(e.data("contextId"));c.show();a.stopImmediatePropagation()})}).fail(c.exception);return d},registerEventFormModal:function registerEventFormModal(b){var d=g.create({type:i.TYPE,large:!0});b.on("click",m.actions.create,function(a){d.then(function(a){var c=b.find(m.wrapper),d=c.data("categoryid");if("undefined"!=typeof d){a.setCategoryId(d)}var e=b.find(m.today),f=b.find(m.day);if(!e.length&&f.length){a.setStartTime(f.data("newEventTimestamp"))}a.setContextId(c.data("contextId"));a.setCourseId(c.data("courseid"));a.show()}).fail(c.exception);a.preventDefault()});b.on("click",m.actions.edit,function(b){b.preventDefault();var e=a(b.currentTarget),f=e.closest(m.wrapper),g=e.closest(m.eventItem);d.then(function(a){a.setEventId(g.data("eventId"));a.setContextId(f.data("contextId"));a.show();b.stopImmediatePropagation()}).fail(c.exception)});return d}}}); define ("core_calendar/crud",["jquery","core/str","core/notification","core/custom_interaction_events","core/modal","core/modal_registry","core/modal_factory","core/modal_events","core_calendar/modal_event_form","core_calendar/repository","core_calendar/events","core_calendar/modal_delete","core_calendar/selectors","core/pending"],function(a,b,c,d,e,f,g,h,i,j,k,l,m,n){function o(d,e,f){var i=new n("core_calendar/crud:confirmDeletion"),m=[{key:"deleteevent",component:"calendar"}];f=parseInt(f,10);var o,p=1<f;if(p){m.push({key:"confirmeventseriesdelete",component:"calendar",param:{name:e,count:f}});o=g.create({type:l.TYPE})}else{m.push({key:"confirmeventdelete",component:"calendar",param:e});o=g.create({type:g.types.SAVE_CANCEL})}var q=b.get_strings(m),r=a.when(q,o).then(function(b,e){e.setRemoveOnClose(!0);e.setTitle(b[0]);e.setBody(b[1]);if(!p){e.setSaveButtonText(b[0])}e.show();e.getRoot().on(h.save,function(){var b=new n("calendar/crud:initModal:deletedevent");j.deleteEvent(d,!1).then(function(){a("body").trigger(k.deleted,[d,!1])}).then(b.resolve).catch(c.exception)});e.getRoot().on(k.deleteAll,function(){var b=new n("calendar/crud:initModal:deletedallevent");j.deleteEvent(d,!0).then(function(){a("body").trigger(k.deleted,[d,!0])}).then(b.resolve).catch(c.exception)});return e}).then(function(a){i.resolve();return a}).catch(c.exception);return r}return{registerRemove:function(b){b.on("click",m.actions.remove,function(b){var c=a(this).closest(m.eventItem),d=c.data("eventId"),e=c.data("eventTitle"),f=c.data("eventCount");o(d,e,f);b.preventDefault()})},registerEditListeners:function(b,d){var e=new n("core_calendar/crud:registerEditListeners");return d.then(function(c){a("body").on(k.editEvent,function(a,d){var e=b.find(m.wrapper);c.setEventId(d);c.setContextId(e.data("contextId"));c.show();a.stopImmediatePropagation()});return c}).then(function(a){e.resolve();return a}).catch(c.exception)},registerEventFormModal:function registerEventFormModal(b){var d=g.create({type:i.TYPE,large:!0});b.on("click",m.actions.create,function(a){d.then(function(a){var c=b.find(m.wrapper),d=c.data("categoryid");if("undefined"!=typeof d){a.setCategoryId(d)}var e=b.find(m.today),f=b.find(m.day);if(!e.length&&f.length){a.setStartTime(f.data("newEventTimestamp"))}a.setContextId(c.data("contextId"));a.setCourseId(c.data("courseid"));a.show()}).fail(c.exception);a.preventDefault()});b.on("click",m.actions.edit,function(b){b.preventDefault();var e=a(b.currentTarget),f=e.closest(m.wrapper),g=e.closest(m.eventItem);d.then(function(a){a.setEventId(g.data("eventId"));a.setContextId(f.data("contextId"));a.show();b.stopImmediatePropagation()}).fail(c.exception)});return d}}});
//# sourceMappingURL=crud.min.js.map //# sourceMappingURL=crud.min.js.map

File diff suppressed because one or more lines are too long

View file

@ -1,2 +1,2 @@
define ("core_calendar/summary_modal",["jquery","core/str","core/notification","core/custom_interaction_events","core/modal","core/modal_registry","core/modal_factory","core/modal_events","core_calendar/repository","core_calendar/events","core_calendar/crud"],function(a,b,c,d,e,f,g,h,i,j,k){var l=!1,m={ROOT:"[data-region='summary-modal-container']",EDIT_BUTTON:"[data-action=\"edit\"]",DELETE_BUTTON:"[data-action=\"delete\"]"},n=function(a){e.call(this,a)};n.TYPE="core_calendar-event_summary";n.prototype=Object.create(e.prototype);n.prototype.constructor=n;n.prototype.getEditButton=function(){if("undefined"==typeof this.editButton){this.editButton=this.getFooter().find(m.EDIT_BUTTON)}return this.editButton};n.prototype.getDeleteButton=function(){if("undefined"==typeof this.deleteButton){this.deleteButton=this.getFooter().find(m.DELETE_BUTTON)}return this.deleteButton};n.prototype.getEventId=function(){return this.getBody().find(m.ROOT).attr("data-event-id")};n.prototype.getEventTitle=function(){return this.getBody().find(m.ROOT).attr("data-event-title")};n.prototype.getEventCount=function(){return this.getBody().find(m.ROOT).attr("data-event-count")};n.prototype.getEditUrl=function(){return this.getBody().find(m.ROOT).attr("data-edit-url")};n.prototype.isActionEvent=function(){return"true"==this.getBody().find(m.ROOT).attr("data-action-event")};n.prototype.registerEventListeners=function(){e.prototype.registerEventListeners.call(this);this.getRoot().on(h.bodyRendered,function(){this.getModal().data({eventTitle:this.getEventTitle(),eventId:this.getEventId(),eventCount:this.getEventCount()}).attr("data-type","event");k.registerRemove(this.getModal())}.bind(this));a("body").on(j.deleted,function(){this.hide()}.bind(this));d.define(this.getEditButton(),[d.events.activate]);this.getEditButton().on(d.events.activate,function(b,c){if(this.isActionEvent()){a("body").trigger(j.editActionEvent,[this.getEditUrl()])}else{a("body").trigger(j.editEvent,[this.getEventId()])}this.hide();b.preventDefault();b.stopPropagation();c.originalEvent.preventDefault();c.originalEvent.stopPropagation()}.bind(this))};if(!l){f.register(n.TYPE,n,"core_calendar/event_summary_modal");l=!0}return n}); define ("core_calendar/summary_modal",["jquery","core/str","core/notification","core/custom_interaction_events","core/modal","core/modal_registry","core/modal_factory","core/modal_events","core_calendar/repository","core_calendar/events","core_calendar/crud"],function(a,b,c,d,e,f,g,h,i,j,k){var l=!1,m={ROOT:"[data-region='summary-modal-container']",EDIT_BUTTON:"[data-action=\"edit\"]",DELETE_BUTTON:"[data-action=\"delete\"]"},n=function(a){e.call(this,a)};n.TYPE="core_calendar-event_summary";n.prototype=Object.create(e.prototype);n.prototype.constructor=n;n.prototype.getEditButton=function(){if("undefined"==typeof this.editButton){this.editButton=this.getFooter().find(m.EDIT_BUTTON)}return this.editButton};n.prototype.getDeleteButton=function(){if("undefined"==typeof this.deleteButton){this.deleteButton=this.getFooter().find(m.DELETE_BUTTON)}return this.deleteButton};n.prototype.getEventId=function(){return this.getBody().find(m.ROOT).attr("data-event-id")};n.prototype.getEventTitle=function(){return this.getBody().find(m.ROOT).attr("data-event-title")};n.prototype.getEventCount=function(){return this.getBody().find(m.ROOT).attr("data-event-count")};n.prototype.getEditUrl=function(){return this.getBody().find(m.ROOT).attr("data-edit-url")};n.prototype.isActionEvent=function(){return"true"==this.getBody().find(m.ROOT).attr("data-action-event")};n.prototype.registerEventListeners=function(){e.prototype.registerEventListeners.call(this);M.util.js_pending("core_calendar/summary_modal:registerEventListeners:bodyRendered");this.getRoot().on(h.bodyRendered,function(){this.getModal().data({eventTitle:this.getEventTitle(),eventId:this.getEventId(),eventCount:this.getEventCount()}).attr("data-type","event");k.registerRemove(this.getModal());M.util.js_complete("core_calendar/summary_modal:registerEventListeners:bodyRendered")}.bind(this));a("body").on(j.deleted,function(){this.hide()}.bind(this));d.define(this.getEditButton(),[d.events.activate]);this.getEditButton().on(d.events.activate,function(b,c){if(this.isActionEvent()){a("body").trigger(j.editActionEvent,[this.getEditUrl()])}else{a("body").trigger(j.editEvent,[this.getEventId()])}this.hide();b.preventDefault();b.stopPropagation();c.originalEvent.preventDefault();c.originalEvent.stopPropagation()}.bind(this))};if(!l){f.register(n.TYPE,n,"core_calendar/event_summary_modal");l=!0}return n});
//# sourceMappingURL=summary_modal.min.js.map //# sourceMappingURL=summary_modal.min.js.map

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -97,17 +97,16 @@ function(
}); });
deletePromise = ModalFactory.create( deletePromise = ModalFactory.create({
{ type: ModalFactory.types.SAVE_CANCEL,
type: ModalFactory.types.SAVE_CANCEL });
}
);
} }
var stringsPromise = Str.get_strings(deleteStrings); var stringsPromise = Str.get_strings(deleteStrings);
var finalPromise = $.when(stringsPromise, deletePromise) var finalPromise = $.when(stringsPromise, deletePromise)
.then(function(strings, deleteModal) { .then(function(strings, deleteModal) {
deleteModal.setRemoveOnClose(true);
deleteModal.setTitle(strings[0]); deleteModal.setTitle(strings[0]);
deleteModal.setBody(strings[1]); deleteModal.setBody(strings[1]);
if (!isRepeatedEvent) { if (!isRepeatedEvent) {
@ -240,7 +239,9 @@ function(
* @returns {Promise} * @returns {Promise}
*/ */
function registerEditListeners(root, eventFormModalPromise) { function registerEditListeners(root, eventFormModalPromise) {
eventFormModalPromise var pendingPromise = new Pending('core_calendar/crud:registerEditListeners');
return eventFormModalPromise
.then(function(modal) { .then(function(modal) {
// When something within the calendar tells us the user wants // When something within the calendar tells us the user wants
// to edit an event then show the event form modal. // to edit an event then show the event form modal.
@ -252,11 +253,14 @@ function(
e.stopImmediatePropagation(); e.stopImmediatePropagation();
}); });
return; return modal;
}) })
.fail(Notification.exception); .then(function(modal) {
pendingPromise.resolve();
return eventFormModalPromise; return modal;
})
.catch(Notification.exception);
} }
return { return {

View file

@ -165,6 +165,7 @@ function(
// We have to wait for the modal to finish rendering in order to ensure that // We have to wait for the modal to finish rendering in order to ensure that
// the data-event-title property is available to use as the modal title. // the data-event-title property is available to use as the modal title.
M.util.js_pending('core_calendar/summary_modal:registerEventListeners:bodyRendered');
this.getRoot().on(ModalEvents.bodyRendered, function() { this.getRoot().on(ModalEvents.bodyRendered, function() {
this.getModal().data({ this.getModal().data({
eventTitle: this.getEventTitle(), eventTitle: this.getEventTitle(),
@ -173,7 +174,7 @@ function(
}) })
.attr('data-type', 'event'); .attr('data-type', 'event');
CalendarCrud.registerRemove(this.getModal()); CalendarCrud.registerRemove(this.getModal());
M.util.js_complete('core_calendar/summary_modal:registerEventListeners:bodyRendered');
}.bind(this)); }.bind(this));
$('body').on(CalendarEvents.deleted, function() { $('body').on(CalendarEvents.deleted, function() {

View file

@ -32,6 +32,7 @@ import ModalFactory from 'core/modal_factory';
import ModalEvents from 'core/modal_events'; import ModalEvents from 'core/modal_events';
import SummaryModal from 'core_calendar/summary_modal'; import SummaryModal from 'core_calendar/summary_modal';
import CustomEvents from 'core/custom_interaction_events'; import CustomEvents from 'core/custom_interaction_events';
import Pending from 'core/pending';
/** /**
* Register event listeners for the module. * Register event listeners for the module.
@ -46,6 +47,7 @@ const registerEventListeners = (root) => {
const target = e.target; const target = e.target;
let eventLink = null; let eventLink = null;
let eventId = null; let eventId = null;
const pendingPromise = new Pending('core_calendar/view_manager:eventLink:click');
if (target.matches(CalendarSelectors.actions.viewEvent)) { if (target.matches(CalendarSelectors.actions.viewEvent)) {
eventLink = target; eventLink = target;
@ -67,7 +69,11 @@ const registerEventListeners = (root) => {
// and causing the day click handler to fire. // and causing the day click handler to fire.
e.stopPropagation(); e.stopPropagation();
renderEventSummaryModal(eventId); renderEventSummaryModal(eventId)
.then(pendingPromise.resolve)
.catch();
} else {
pendingPromise.resolve();
} }
}); });
@ -372,20 +378,21 @@ const getEventTypeClassFromType = (eventType) => {
* Render the event summary modal. * Render the event summary modal.
* *
* @param {Number} eventId The calendar event id. * @param {Number} eventId The calendar event id.
* @returns {Promise}
*/ */
const renderEventSummaryModal = (eventId) => { const renderEventSummaryModal = (eventId) => {
let typeClass = ''; const pendingPromise = new Pending('core_calendar/view_manager:renderEventSummaryModal');
// Calendar repository promise. // Calendar repository promise.
CalendarRepository.getEventById(eventId).then((getEventResponse) => { return CalendarRepository.getEventById(eventId)
.then((getEventResponse) => {
if (!getEventResponse.event) { if (!getEventResponse.event) {
throw new Error('Error encountered while trying to fetch calendar event with ID: ' + eventId); throw new Error('Error encountered while trying to fetch calendar event with ID: ' + eventId);
} }
const eventData = getEventResponse.event;
typeClass = getEventTypeClassFromType(eventData.normalisedeventtype);
return eventData; return getEventResponse.event;
}).then((eventData) => { })
.then(eventData => {
// Build the modal parameters from the event data. // Build the modal parameters from the event data.
const modalParams = { const modalParams = {
title: eventData.name, title: eventData.name,
@ -394,7 +401,7 @@ const renderEventSummaryModal = (eventId) => {
templateContext: { templateContext: {
canedit: eventData.canedit, canedit: eventData.canedit,
candelete: eventData.candelete, candelete: eventData.candelete,
headerclasses: typeClass, headerclasses: getEventTypeClassFromType(eventData.normalisedeventtype),
isactionevent: eventData.isactionevent, isactionevent: eventData.isactionevent,
url: eventData.url url: eventData.url
} }
@ -402,8 +409,8 @@ const renderEventSummaryModal = (eventId) => {
// Create the modal. // Create the modal.
return ModalFactory.create(modalParams); return ModalFactory.create(modalParams);
})
}).done(function(modal) { .then(modal => {
// Handle hidden event. // Handle hidden event.
modal.getRoot().on(ModalEvents.hidden, function() { modal.getRoot().on(ModalEvents.hidden, function() {
// Destroy when hidden. // Destroy when hidden.
@ -413,7 +420,14 @@ const renderEventSummaryModal = (eventId) => {
// Finally, render the modal! // Finally, render the modal!
modal.show(); modal.show();
}).fail(Notification.exception); return modal;
})
.then(modal => {
pendingPromise.resolve();
return modal;
})
.catch(Notification.exception);
}; };
export const init = (root, view) => { export const init = (root, view) => {