Skip to content

Commit

Permalink
#611 move events between calendars
Browse files Browse the repository at this point in the history
  • Loading branch information
rezk2ll committed Nov 24, 2021
1 parent 51d6635 commit 2e4528b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -402,6 +402,7 @@ function CalEventFormController(
{ graceperiod: true, notifyFullcalendar: $state.is('calendar.main') }
);
})
.then(checkCalendarChange)
.then(onEventCreateUpdateResponse)
.finally(function() {
$scope.restActive = false;
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
19 changes: 18 additions & 1 deletion src/esn.calendar.libs/app/services/calendar-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ require('./http-response-handler.js');
changeParticipation: changeParticipation,
modifyPublicRights: modifyPublicRights,
exportCalendar,
getSecretAddress
getSecretAddress,
moveEvent
};

////////////
Expand Down Expand Up @@ -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);
5 changes: 5 additions & 0 deletions src/esn.calendar.libs/app/services/event-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function calEventService(
self.getEventByUID = getEventByUID;
self.getEventFromICSUrl = getEventFromICSUrl;
self.onEventCreatedOrUpdated = onEventCreatedOrUpdated;
self.moveEvent = moveEvent;

////////////

Expand Down Expand Up @@ -575,4 +576,8 @@ function calEventService(
return new CalendarShell(ICAL.Component.fromString(response.data));
});
}

function moveEvent(source, destination) {
return calendarAPI.moveEvent(source, destination);
}
}

0 comments on commit 2e4528b

Please sign in to comment.