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

Assignments & 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

isEventModel: Boolean= truereadonly
Identifies an object as an instance of EventModel class, or subclass thereof.
isEventModel: Boolean= truereadonlystatic
Identifies an object as an instance of EventModel class, or subclass thereof.
isEventModelMixin: Boolean= truereadonlyEventModelMixin
Identifies an object as an instance of EventModelMixin class, or subclass thereof.
isEventModelMixin: Boolean= truereadonlystaticEventModelMixin
Identifies an object as an instance of EventModelMixin class, or subclass thereof.
isModelModel
isModelLinkModelLink
isModelStmModelStm
isRecurringTimeSpanRecurringTimeSpan
isTimeSpanTimeSpan
isTimeZonedDatesMixinTimeZonedDatesMixin
isTreeNodeTreeNode

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.

isResizable: Boolean | StringreadonlyEventModelMixin

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.

copyOfModel
isValidModel

Scheduling

isInterDay: BooleanreadonlyEventModelMixin

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.

datesTimeSpan
durationMSTimeSpan
isMilestoneTimeSpan
isScheduledTimeSpan

Fields

allFieldsstaticModel
autoExposeFieldsstaticModel
childrenFieldstaticModel
defaultsstaticModel
fieldMapstaticModel
fieldsstaticModel
idFieldstaticModel

Grouping

Identification

keyModel

JSON

jsonModel

Lifecycle

configBase

Linked records

hasLinksModelLink
isLinkedModelLink
recordLinksModelLink

Misc

eventStoreTimeSpan
stmModelStm

Other

$namestaticModel
relationsstaticModel

Parent & children

allChildrenTreeNode
childLevelTreeNode
firstChildTreeNode
isLeafTreeNode
isLoadedTreeNode
isParentTreeNode
isRootTreeNode
lastChildTreeNode
nextSiblingTreeNode
parentTreeNode
parentIdTreeNode
wbsCodeTimeSpan

Recurrence

isOccurrenceRecurringTimeSpan
isRecurringRecurringTimeSpan
occurrenceIndexRecurringTimeSpan
recurrenceRecurringTimeSpan
recurrenceModelRecurringTimeSpan
supportsRecurringRecurringTimeSpan

Functions

73

Assignments & 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.

ParameterTypeDescription
resourceResourceModel | 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).

removeExistingAssignmentsBoolean

true to first remove existing assignments

Returns either the resource associated with this event (when called w/o resourceId) or resource with specified id.

ParameterTypeDescription
resourceIdString

To retrieve a specific resource

Returns: ResourceModel

Returns true if this event is assigned to a certain resource.

ParameterTypeDescription
resourceResourceModel | String | Number

The resource to query for

Returns: Boolean

Reassigns an event from an old resource to a new resource

ParameterTypeDescription
oldResourceIdResourceModel | String | Number

A resource to unassign from or its id

newResourceIdResourceModel | String | Number

A resource to assign to or its id

Unassigns this event from the specified resource

ParameterTypeDescription
resourceResourceModel | 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.

ParameterTypeDescription
fieldNameString

Name of the field

Returns: Boolean -

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
ParameterTypeDescription
fieldString | Object

The field to set value for, or an object with multiple values to set in one call

value*

Value to set

silentBoolean

Set to true to not trigger events. If event is recurring, occurrences won't be updated automatically.

copyModel
getDataModel
removeModel
setModel

Scheduling

Shift the dates for the date range by the passed amount and unit

ParameterTypeDescription
amountNumber

The amount to shift

unitDurationUnitShort

The unit to shift by, see DateHelper for more information on valid formats.

Returns: Promise -

A promise which is resolved when shift calculations are done

forEachDateTimeSpan
setDurationTimeSpan
setEndDateTimeSpan
setStartDateTimeSpan
splitTimeSpan

Configuration

applyDefaultsstaticBase

Events

Fields

addFieldstaticModel
getModel
isTimeZoneDateFieldstaticTimeZonedDatesMixin
processFieldstaticModel
removeFieldstaticModel

Identification

asIdstaticModel
generateIdstaticModel

JSON

toJSONModel

Lifecycle

destroystaticBase

Misc

equalsModel
exportToICSTimeSpan
initClassstaticBase
isOfTypeNamestaticBase
linkModelLink
mixinstaticBase

Parent & children

appendChildTreeNode
bubbleTreeNode
bubbleWhileTreeNode
containsTreeNode
insertChildTreeNode
isExpandedTreeNode
removeChildTreeNode
traverseTreeNode

Recurrence

addExceptionDateRecurringTimeSpan
hasExceptionRecurringTimeSpan
setRecurrenceRecurringTimeSpan

Typedefs

2
EventColor: red | pink | magenta | purple | violet | deep-purple | indigo | blue | light-blue | cyan | teal | green | light-green | lime | yellow | orange | amber | deep-orange | light-gray | gray | black | String | nullEventModelMixin

Predefined named colors:

red
pink
magenta
purple
violet
deep-purple
indigo
blue
light-blue
cyan
teal
green
light-green
lime
yellow
orange
amber
deep-orange
light-gray
gray
black