From 2e4528b626812beeec3ddc9dc0c529091a07944c Mon Sep 17 00:00:00 2001 From: Khaled FERJANI Date: Wed, 24 Nov 2021 10:03:15 +0100 Subject: [PATCH] linagora/esn-frontend-calendar#611 move events between calendars --- .../event/form/event-form.controller.js | 18 +++++++++++++++++- .../app/components/event/form/event-form.pug | 4 ++-- .../app/services/calendar-api.js | 19 ++++++++++++++++++- .../app/services/event-service.js | 5 +++++ 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/esn.calendar.libs/app/components/event/form/event-form.controller.js b/src/esn.calendar.libs/app/components/event/form/event-form.controller.js index 9d9b908c..74164f02 100644 --- a/src/esn.calendar.libs/app/components/event/form/event-form.controller.js +++ b/src/esn.calendar.libs/app/components/event/form/event-form.controller.js @@ -368,7 +368,7 @@ function CalEventFormController( $scope.editedEvent.attendees = getUpdatedAttendees(); - if (!calEventUtils.hasAnyChange($scope.editedEvent, $scope.event)) { + if (!calEventUtils.hasAnyChange($scope.editedEvent, $scope.event) && !_calendarHasChanged()) { _hideModal(); return; @@ -402,6 +402,7 @@ function CalEventFormController( { graceperiod: true, notifyFullcalendar: $state.is('calendar.main') } ); }) + .then(checkCalendarChange) .then(onEventCreateUpdateResponse) .finally(function() { $scope.restActive = false; @@ -668,4 +669,19 @@ function CalEventFormController( placement: 'center' }); } + + function checkCalendarChange() { + return _calendarHasChanged() ? changeCalendar() : Promise.resolve(); + } + + function changeCalendar() { + const destinationPath = calPathBuilder.forEventId($scope.calendarHomeId, _getCalendarByUniqueId($scope.selectedCalendar.uniqueId).id, $scope.editedEvent.uid); + const sourcePath = $scope.event.path; + + return calEventService.moveEvent(sourcePath, `${destinationPath}.ics`); + } + + function _calendarHasChanged() { + return _getCalendarByUniqueId($scope.selectedCalendar.uniqueId).id !== $scope.editedEvent.calendarId; + } } diff --git a/src/esn.calendar.libs/app/components/event/form/event-form.pug b/src/esn.calendar.libs/app/components/event/form/event-form.pug index 93eb6bfd..f7970ccc 100644 --- a/src/esn.calendar.libs/app/components/event/form/event-form.pug +++ b/src/esn.calendar.libs/app/components/event/form/event-form.pug @@ -46,8 +46,8 @@ form.event-form(role="form", name="form", aria-hidden="true", ng-class="{ 'reado i.mdi.mdi-calendar-multiple .fg-line md-input-container(ng-click="changeBackdropZIndex()") - md-select(ng-disabled="!isNew(editedEvent) || !canModifyEvent", ng-model="selectedCalendar.uniqueId", md-container-class="cal-select-dropdown" aria-label="calendar") - md-option(ng-value="calendar.getUniqueId()" ng-repeat="calendar in calendars | filter: (isNew(editedEvent) || canModifyEvent) ? { readOnly: false } : {}") + md-select(ng-disabled="!canModifyEvent", ng-model="selectedCalendar.uniqueId", md-container-class="cal-select-dropdown" aria-label="calendar") + md-option(ng-value="calendar.getUniqueId()" ng-repeat="calendar in calendars | filter: { readOnly: false }") cal-select-calendar-item(calendar="calendar") cal-event-date-edition(event="editedEvent", disabled='!canModifyEvent', use-24hour-format='use24hourFormat', on-date-change='onDateChange') cal-entities-autocomplete-input.cal-user-autocomplete-input( diff --git a/src/esn.calendar.libs/app/services/calendar-api.js b/src/esn.calendar.libs/app/services/calendar-api.js index 56fe8936..817b995f 100644 --- a/src/esn.calendar.libs/app/services/calendar-api.js +++ b/src/esn.calendar.libs/app/services/calendar-api.js @@ -43,7 +43,8 @@ require('./http-response-handler.js'); changeParticipation: changeParticipation, modifyPublicRights: modifyPublicRights, exportCalendar, - getSecretAddress + getSecretAddress, + moveEvent }; //////////// @@ -331,5 +332,21 @@ require('./http-response-handler.js'); return $q.reject(error); }); } + + /** + * Move an event from one calendar to another + * + * @param {String} eventPath the path of the event. + * @param {String} destinationCalendarId the calendar id + * @returns {Object} the http response. + */ + function moveEvent(originalEventPath, destinationEventPath) { + const headers = { + Destination: destinationEventPath, + Overwrite: 'F' + }; + + return calDavRequest('move', originalEventPath, headers); + } } })(angular); diff --git a/src/esn.calendar.libs/app/services/event-service.js b/src/esn.calendar.libs/app/services/event-service.js index b21f3e11..fef02096 100644 --- a/src/esn.calendar.libs/app/services/event-service.js +++ b/src/esn.calendar.libs/app/services/event-service.js @@ -59,6 +59,7 @@ function calEventService( self.getEventByUID = getEventByUID; self.getEventFromICSUrl = getEventFromICSUrl; self.onEventCreatedOrUpdated = onEventCreatedOrUpdated; + self.moveEvent = moveEvent; //////////// @@ -575,4 +576,8 @@ function calEventService( return new CalendarShell(ICAL.Component.fromString(response.data)); }); } + + function moveEvent(source, destination) { + return calendarAPI.moveEvent(source, destination); + } }