Skip to content

Commit

Permalink
MDL-60558 calendar: Move edit event to CRUD
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Nov 2, 2017
1 parent fd2f1ae commit 8242027
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 17 deletions.
2 changes: 1 addition & 1 deletion calendar/amd/build/calendar.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion calendar/amd/build/calendar_view.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion calendar/amd/build/crud.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 1 addition & 13 deletions calendar/amd/src/calendar.js
Expand Up @@ -163,19 +163,7 @@ define([
CalendarViewManager.reloadCurrentMonth(root);
});

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) {
var calendarWrapper = root.find(CalendarSelectors.wrapper);
modal.setEventId(eventId);
modal.setContextId(calendarWrapper.data('contextId'));
modal.show();
});
return;
})
.fail(Notification.exception);
CalendarCrud.registerEditListeners(root, eventFormModalPromise);
};

/**
Expand Down
4 changes: 3 additions & 1 deletion calendar/amd/src/calendar_view.js
Expand Up @@ -51,7 +51,6 @@ define([
var registerEventListeners = function(root, type) {
var body = $('body');

CalendarCrud.registerEventFormModal(root);
CalendarCrud.registerRemove(root);

var reloadFunction = 'reloadCurrent' + type.charAt(0).toUpperCase() + type.slice(1);
Expand Down Expand Up @@ -85,6 +84,9 @@ define([
daysWithEvent.removeClass('hidden');
}
});

var eventFormPromise = CalendarCrud.registerEventFormModal(root);
CalendarCrud.registerEditListeners(root, eventFormPromise);
};

return {
Expand Down
30 changes: 30 additions & 0 deletions calendar/amd/src/crud.js
Expand Up @@ -198,6 +198,8 @@ function(

modal.setContextId(calendarWrapper.data('contextId'));
modal.show();

e.stopImmediatePropagation();
return;
}).fail(Notification.exception);
});
Expand All @@ -223,8 +225,36 @@ function(
});
}

/**
* Register the listeners required to edit the event.
*
* @param {jQuery} root
* @param {Promise} eventFormModalPromise
* @returns {Promise}
*/
function registerEditListeners(root, eventFormModalPromise) {
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) {
var calendarWrapper = root.find(CalendarSelectors.wrapper);
modal.setEventId(eventId);
modal.setContextId(calendarWrapper.data('contextId'));
modal.show();

e.stopImmediatePropagation();
});
return;
})
.fail(Notification.exception);

return eventFormModalPromise;
}

return {
registerRemove: registerRemove,
registerEditListeners: registerEditListeners,
registerEventFormModal: registerEventFormModal
};
});

0 comments on commit 8242027

Please sign in to comment.