v7.3.0

EventModel

This class represent a single event in your schedule, usually added to a EventStore.

It is a subclass of the TimeSpan, which is in turn a subclass of Model. Please refer to the documentation of that class to become familiar with the base interface of the event.

Recurrence

This class mixes RecurringTimeSpan which provides recurrence support. Using the recurrenceRule and exceptionDates you can express just about any recurrence pattern. Below is the data for a repeating event happening every weekday at 10am.

{
  "id"             : 1,
  "name"           : "Daily standup",
  "startDate"      : "2024-01-03 10:00",
  "duration"       : 1,
  "durationUnit"   : "hour",
  "recurrenceRule" : "FREQ=WEEKLY;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR"
}

Async date calculations

A record created from an EventModel is normally part of an EventStore, which in turn is part of a project. When dates or the duration of an event is changed, the project performs async calculations to normalize the other fields. For example if duration is changed, it will calculate endDate.

As a result of this being an async operation, the values of other fields are not guaranteed to be up to date immediately after a change. To ensure data is up to date, await the calculations to finish.

For example, endDate is not up to date after this operation:

eventRecord.duration = 5;
// endDate not yet calculated

But if calculations are awaited it is up to date:

eventRecord.duration = 5;
await eventRecord.project.commitAsync();
// endDate is calculated

As an alternative, you can also use setAsync() to trigger calculations directly after the change:

await eventRecord.setAsync({ duration : 5});
// endDate is calculated

Subclassing the Event model class

The Event model has a few predefined fields as seen below. If you want to add new fields or change the options for the existing fields, you can do that by subclassing this class (see example below).

class MyEvent extends EventModel {

static get fields() { return [ // Add new field { name: 'myField', type : 'number', defaultValue : 0 } ]; },

myCheckMethod() { return this.myField > 0 },

... });

If you in your data want to use other names for the startDate, endDate, resourceId and name fields you can configure them as seen below:

class MyEvent extends EventModel {

static get fields() { return [ { name: 'startDate', dataSource : 'taskStart' }, { name: 'endDate', dataSource : 'taskEnd', format: 'YYYY-MM-DD' }, { name: 'resourceId', dataSource : 'userId' }, { name: 'name', dataSource : 'taskTitle' }, ]; }, ... });

Please refer to Model for additional details.

Changing default field values

Default values for fields can be changed without subclassing or redefining fields using applyDefaults. This should be called before data is loaded into stores:

// Change the default duration unit for all new events
EventModel.applyDefaults({ durationUnit : 'week' });

See also

No results

Properties

Properties are getters/setters or publicly accessible variables on this class

Source path

Scheduler/model/EventModel.js

Contents