v7.3.0
SupportExamplesFree Trial

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 subclass of Model. Please refer to documentation of that class to become familiar with the base interface of the event.

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 change, 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

Fields

Fields belong to a Model class and define the Model data structure
  • The unique identifier of a task (mandatory)

  • The name of the time span (or Event / Task)

  • Note about the event

  • Id of the resource this event is associated with (only usable for single assignments). We recommend using assignments in an AssignmentStore over this approach. Internally any Event using resourceId will have an assignment in AssignmentStore generated.

  • Ids of the resources this event is associated with (can be used for multiple assignments). Any event using resourceIds will have assignments in AssignmentStore generated automatically. It only applies if is configured with persist: true.

      class CustomEventModel extends EventModel {
          static $name = 'CustomEventModel';
    
          static get fields() {
              return [
                  { name : 'resourceIds', persist : true }
              ];
          }
      };
    
      const
          resources   = [
              { id : 'r1', name : 'Celia' },
              { id : 'r2', name : 'Lee' },
              { id : 'r3', name : 'Macy' },
              { id : 'r4', name : 'Madison' }
          ],
          events      = [
              {
                  id          : 1,
                  resourceIds : ['r1', 'r2']
                  ...
              },
              {
                  id          : 2,
                  resourceIds : ['r3', 'r4']
                  ...
              }
          ];
    
      const scheduler = new Scheduler({
          ...
          eventStore : {
              modelClass : CustomEventModel,
              data       : events
          },
          ...
      });
    
  • The array of resources which are assigned to this event.

  • Set this to true if this task should be shown in the Timeline widget

  • Specify false to prevent the event from being dragged (if EventDrag feature is used)

  • Specify false to prevent the event from being resized (if EventResize feature is used). You can also specify 'start' or 'end' to only allow resizing in one direction

  • A field marking event as all day(s) spanning event. For example, a holiday day may be represented by a startDate, and the allDay flag.

  • Field defining the constraint boundary date, if applicable.

  • constraintType : 'finishnoearlierthan'/'finishnolaterthan'/'mustfinishon'/'muststarton'/'startnoearlierthan'+ 2 more

    Field storing the event constraint alias or NULL if not constraint set. Valid values are:

    • "finishnoearlierthan"
    • "finishnolaterthan"
    • "mustfinishon"
    • "muststarton"
    • "startnoearlierthan"
    • "startnolaterthan"
  • cost : Number
    CALCULATED
    READONLY

    The total projected cost for the event.

  • The numeric part of the event effort (the number of units).

  • This boolean flag defines what part the data should be updated in the FixedDuration scheduling mode. If it is true, then effort is kept intact when new duration is provided and assignment units is updated. If it is false, then assignment units is kept intact when new duration is provided and effort is updated.

  • When set to true the event becomes inactive and stops taking part in the project scheduling (doesn't affect linked events and affect its assigned resources allocation).

  • When set to true, the startDate of the event will not be changed by any of its incoming dependencies or constraints.

  • The timespan recurrence rule. A string in RFC-5545 described format ("RRULE" expression).

  • Segments of the event that appear when the event gets splitToSegments. Can be provided as an array of segment config objects or EventSegmentModel instances.

  • Controls the primary color of the event. For available standard colors, see EventColor.

  • eventStyle : 'plain'/'border'/'colored'/'hollow'/'line'+ 7 more
    EventModelMixin

    Controls this events appearance, see Schedulers eventStyle config for available options.

  • CSS class specifying an icon to apply to the rendered time span element. Note: In case event is a milestone, using iconCls with dependency feature might slightly decrease performance because feature will refer to the DOM to get exact size of the element.

  • Width (in px) to use for this milestone when using Scheduler#milestoneLayoutMode 'data'.

  • Set this field to false to opt out of sticky event content (keeping event text in view while scrolling).

  • A CSS style string (applied to style.cssText) or object (applied to style)

    record.style = 'color: red;font-weight: 800';
    
  • Start expanded or not (only valid for tree data)

  • This is a read-only field provided in server synchronization packets to specify which position the node takes in the parent's ordered children array. This index is set on load and gets updated on reordering nodes in tree. Sorting and filtering have no effect on it.

  • parentId : String/Number/null
    READONLY
    TreeNode

    This is a read-only field provided in server synchronization packets to specify which record id is the parent of the record.

  • This is a read-only field provided in server synchronization packets to specify which position the node takes in the parent's children array. This index is set on load and gets updated automatically after row reordering, sorting, etc. To save the order, need to persist the field on the server and when data is fetched to be loaded, need to sort by this field.

  • Deprecated:

    This field has been deprecated. Please read the guide to find out if your app needs to use the new isFullyLoaded field.

    This field is added to the class at runtime when the Store is configured with lazyLoad. The number specified should reflect the total amount of children of a parent node, including nested descendants.

Configs

Configs are options you supply in a configuration object when creating an instance of this class

Properties

Properties are getters/setters or publicly accessible variables on this class
  • isEventModel : Booleantrue
    READONLY
    static
    ADVANCED
    Identifies an object as an instance of EventModel class, or subclass thereof.
  • isEventModelMixin : Booleantrue
    READONLY
    static
    ADVANCED
    EventModelMixin
    Identifies an object as an instance of EventModelMixin class, or subclass thereof.
  • isModelStm : Booleantrue
    READONLY
    static
    ADVANCED
    ModelStm
    Identifies an object as an instance of ModelStm class, or subclass thereof.
  • isPartOfProject : Booleantrue
    READONLY
    static
    ADVANCED
    PartOfProject
    Identifies an object as an instance of PartOfProject class, or subclass thereof.
  • isPercentDoneMixin : Booleantrue
    READONLY
    static
    ADVANCED
    PercentDoneMixin
    Identifies an object as an instance of PercentDoneMixin class, or subclass thereof.
  • isRecurringTimeSpan : Booleantrue
    READONLY
    static
    ADVANCED
    RecurringTimeSpan
    Identifies an object as an instance of RecurringTimeSpan class, or subclass thereof.
  • isTimeZonedDatesMixin : Booleantrue
    READONLY
    static
    ADVANCED
    TimeZonedDatesMixin
    Identifies an object as an instance of TimeZonedDatesMixin class, or subclass thereof.
  • isTreeNode : Booleantrue
    READONLY
    static
    ADVANCED
    TreeNode
    Identifies an object as an instance of TreeNode class, or subclass thereof.
  • properties : Object
    internal
    static
    TimeSpan

    A class property getter for the default values of internal properties for this class.

  • allFields : DataField[]
    READONLY
    static
    TimeSpan

    An array containing all the defined fields for this Model class. This will include all superclass's defined fields.

  • fieldMap : Object<String, DataField>
    READONLY
    static
    TimeSpan

    An object containing all the defined fields for this Model class. This will include all superclass's defined fields through its prototype chain. So be aware that Object.keys and Object.entries will only access this class's defined fields.

  • The data source for the id field which provides the ID of instances of this Model.

Functions

Functions are methods available for calling on the class
  • onClassMixedIn( )
    internal
    static
    TimeSpan

    This optional class method is called when a class is mixed in using the mixin() method.

  • initClass( )
    static
    ADVANCED
    TimeSpan

    Registers this class type with its Factory

  • exposeRelations( )
    internal
    static
    TimeSpan

    Makes getters and setters for related records. Populates a Model#relation array with the relations, to allow it to be modified later when assigning stores.

  • Iterate over all associated resources

  • Cancels current batch operation. Any changes during the batch are discarded.

  • Reverts changes in this back to their original values.

  • Called from insertChild to notify StateTrackingManager about children insertion. Provides it with all necessary context information collected in beforeInsertChild required to undo/redo the action.

  • Called from removeChild to notify StateTrackingManager about children removing. Provides it with all necessary context information collected in beforeRemoveChild required to undo/redo the action.

  • Called during creation to also turn any children into Models joined to the same stores as this model

  • Detaches an occurrence from its owning recurring event so that it can be added to the eventStore either as an exception, or as the start of a new recurring sequence.

  • The method is triggered when the timespan recurrence settings get changed. It updates the recurrenceRule field in this case.

  • Override of Model's method. If an isOccurrence is passed, it is detached from its parent recurring event. If it still has a recurrence then the recurring event is changed to stop at the occurrence date. If it has no recurrence an exception is added at the occurrence date.

  • Removes this recurring timespan's cached occurrences.

  • Removes all cached occurrences on or after the passed date from this recurring timespan's cached occurrences.

  • Initializes model relations. Called from store when adding a record.

  • clear( )
    private
    TreeNode

    Removes all records from the rootNode

Source path

SchedulerPro/model/EventModel.js

Contents