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.
Properties
88
Properties
88Assignments & Resources
Returns all assignments for the event. Event must be part of the store for this method to work.
Returns the first assigned resource, or assigns a resource
Returns all resources assigned to an event.
Class hierarchy
Dependencies
Returns all predecessor dependencies of this event
Returns all successor dependencies of this event
Editing
Returns true if event can be drag and dropped
Returns false if the event is not persistable. By default it always is, override this getter if you need
custom logic.
Returns true if event can be resized, but can additionally return 'start' or 'end' indicating how this event can be resized.
Milestones and parent events (that are not manuallyScheduled) cannot be resized.
Scheduling
Flag which indicates that this event is an interday event. This means that it spans an entire day or multiple days.
This is essentially used by the Calendar package to determine if an event should go into the all day zone of a DayView.
JSON
Parent & children
Recurrence
Functions
73
Functions
73Assignments & Resources
Assigns this event to the specified resource.
Note: The event must be part of an EventStore for this to work. If the EventStore uses single assignment (loaded using resourceId) existing assignments will always be removed.
| Parameter | Type | Description |
|---|---|---|
resource | ResourceModel | String | Number | ResourceModel[] | String[] | Number[] | A new resource for this event, either as a full Resource record or an id (or an array of such). |
removeExistingAssignments | Boolean |
|
Returns either the resource associated with this event (when called w/o resourceId) or resource
with specified id.
| Parameter | Type | Description |
|---|---|---|
resourceId | String | To retrieve a specific resource |
Returns true if this event is assigned to a certain resource.
| Parameter | Type | Description |
|---|---|---|
resource | ResourceModel | String | Number | The resource to query for |
Reassigns an event from an old resource to a new resource
| Parameter | Type | Description |
|---|---|---|
oldResourceId | ResourceModel | String | Number | A resource to unassign from or its id |
newResourceId | ResourceModel | String | Number | A resource to assign to or its id |
Unassigns this event from the specified resource
| Parameter | Type | Description |
|---|---|---|
resource | ResourceModel | String | Number | The resource to unassign from. |
Editing
Defines if the given event field should be manually editable in UI. You can override this method to provide your own logic.
By default, the method defines endDate, duration and fullDuration fields editable for leaf events only (in case the event is part of a tree store) and all other fields as editable.
| Parameter | Type | Description |
|---|---|---|
fieldName | String | Name of the field |
Returns true if the field is editable, false if it is not and undefined if the event has
no such field.
Set value for the specified field(s), triggering engine calculations immediately. See Model#set() for arguments.
eventRecord.set('duration', 4);
// eventRecord.endDate is not yet calculated
await eventRecord.setAsync('duration', 4);
// eventRecord.endDate is calculated
| Parameter | Type | Description |
|---|---|---|
field | String | Object | The field to set value for, or an object with multiple values to set in one call |
value | * | Value to set |
silent | Boolean | Set to |
Scheduling
Shift the dates for the date range by the passed amount and unit
| Parameter | Type | Description |
|---|---|---|
amount | Number | The amount to shift |
unit | DurationUnitShort | The unit to shift by, see DateHelper for more information on valid formats. |
A promise which is resolved when shift calculations are done
Configuration
Events
Misc
Parent & children
Recurrence
Typedefs
2
Typedefs
2Predefined named colors: