- Home
- Forum
- Angular - EJ 2
- getOccurrencesByID in actionBegin event
getOccurrencesByID in actionBegin event
Hi team,
I want to ensure that no collisions of appointments happen - also with repeated events.
If I create a new event, I use the onActionBegin event to check if there is already an appointment (or a recurring appointment with getOccurrencesByID(existingAppointment.Id). If there is one, I use args.cancel and do not allow to save the appointment.
But if the new appointment is recurring, then the getOccurrencesByID returns an empty array.
1) How can I prevent this?
Also, when I delete the first occurrence of a repeating event (its added to the RecurrenceException property) it is still returned from the getOccurrencesByID method. 2) how can I check if that particular occurrence is not deleted as exception?
If I delete the very last occurrence of an appointment, I want to delete the entire appointment. 3) Is there a built-in way for this?
Thanks,
Max
import { extend, isNullOrUndefined } from '@syncfusion/ej2-base'; export class AppComponent { public data: Record<string, any>[] = [ { Id: 1, Subject: 'Project demo meeting with Andrew', Location: 'Office', StartTime: new Date(2021, 1, 14, 12, 0), EndTime: new Date(2021, 1, 14, 13, 0), RecurrenceRule: 'FREQ=DAILY;INTERVAL=1;COUNT=5', CategoryColor: '#1aaa55' },]; @ViewChild('scheduleObj') public scheduleObj: ScheduleComponent; public onActionBegin(args: ActionEventArgs) { if (args.requestType === "eventCreate" || args.requestType === "eventChange") { let data = args.data instanceof Array ? args.data[0] : args.data; let appointementData = this.scheduleObj.eventsData; let appointementCollection = []; for (var i = 0; i < appointementData.length; i++) { if (!isNullOrUndefined(appointementData[i].RecurrenceRule)) { let occurrence = this.scheduleObj.eventBase.generateOccurrence( appointementData[i] ); appointementCollection = appointementCollection.concat(occurrence); } else { appointementCollection.push(appointementData[i]); } } if (!isNullOrUndefined(data.RecurrenceRule)) { let occurrences = this.scheduleObj.eventBase.generateOccurrence(data); for (let i = 0; i < occurrences.length; i++) { // Get the timeslot and check if there is already an event let filteredEvents = this.scheduleObj.eventBase.filterEventsByRange( appointementCollection, occurrences[i].StartTime, occurrences[i].EndTime ); if (filteredEvents.length > 0) { args.cancel = true; break; } } } else { args.cancel = !this.scheduleObj.isSlotAvailable(data); } } } } |
- 1 Reply
- 2 Participants
- Marked answer
-
MM Max Melcher
- Sep 9, 2024 01:10 PM UTC
- Sep 11, 2024 12:07 PM UTC