EventMenu

Displays a context menu for events. Items are populated by other features and/or application code.

Event menu
//<code-header>
fiddle.title = 'Event menu';
//</code-header>
targetElement.innerHTML = '<p>Right click an event bar to display a context menu:</p>';
const scheduler = new Scheduler({
    appendTo : targetElement,

    // makes scheduler as high as it needs to be to fit rows
    autoHeight : true,

    features : {
        eventMenu : {
            items : {
                duplicate : {
                    text   : 'Duplicate',
                    weight : 200,
                    icon   : 'fa fa-fw fa-copy',
                    onItem({ item, eventRecord }) {
                        scheduler.eventStore.add(eventRecord.copy());
                    }
                }
            }
        }
    },

    startDate : new Date(2018, 4, 6),
    endDate   : new Date(2018, 4, 13),

    columns : [
        { field : 'name', text : 'Name', width : 100 }
    ],

    resources : [
        { id : 1, name : 'Bernard' },
        { id : 2, name : 'Bianca' }
    ],

    events : [
        { id : 1, resourceId : 1, name : 'Interview', startDate : '2018-05-07', endDate : '2018-05-10' },
        { id : 2, resourceId : 2, name : 'Meeting', startDate : '2018-05-10', endDate : '2018-05-12' },
        { id : 3, resourceId : 2, name : 'Future task', startDate : '2018-06-10', endDate : '2018-06-12' }
    ]
});

Default event menu items

Here is the list of menu items provided by the feature and populated by the other features:

Reference Text Weight Feature Description
editEvent Edit event 100 EventEdit Edit event in the event editor. Hidden when read-only
showDetails Edit event 100 EventEdit Show event in a non-editable form. Hidden when not read-only
copyEvent Copy event 110 EventCopyPaste Copy event or assignment. Hidden when read-only
cutEvent Cut event 120 EventCopyPaste Cut event or assignment. Hidden when read-only
unassignEvent Unassign event 300 This feature Unassign event. Hidden when read-only, shown for multi-assignment
deleteEvent Delete event 500 This feature Remove event. Hidden when read-only
splitEvent Split event 650 Scheduler Pro only Split an event into two segments at the mouse position
renameSegment Rename segment 660 Scheduler Pro only Show an inline editor to rename the segment
eventColor ¹ Color 400 This feature Choose background color for the event bar

¹ Set showEventColorPickers to true to enable this item

Customizing the menu items

The menu items in the Event menu can be customized, existing items can be changed or removed, and new items can be added. This is handled using the items config of the feature.

Add extra items for all events:

const scheduler = new Scheduler({
    features : {
        eventMenu : {
            items : {
                extraItem : {
                    text : 'Extra',
                    icon : 'fa fa-fw fa-flag',
                    onItem({eventRecord}) {
                        eventRecord.flagged = true;
                    }
                }
            }
        }
    }
});

Remove existing items:

const scheduler = new Scheduler({
    features : {
        eventMenu : {
            items : {
                deleteEvent   : false,
                unassignEvent : false
            }
        }
    }
});

Customize existing item:

const scheduler = new Scheduler({
    features : {
        eventMenu : {
            items : {
                deleteEvent : {
                    text : 'Delete booking'
                }
            }
        }
    }
});

Manipulate existing items for all events or specific events:

const scheduler = new Scheduler({
    features : {
        eventMenu : {
            // Process items before menu is shown
            processItems({eventRecord, items}) {
                 // Push an extra item for conferences
                 if (eventRecord.type === 'conference') {
                     items.showSessionItem = {
                         text : 'Show sessions',
                         onItem({eventRecord}) {
                             // ...
                         }
                     };
                 }

                 // Do not show menu for secret events
                 if (eventRecord.type === 'secret') {
                     return false;
                 }
            }
        }
    }
});

The processItems implementation may be an async function which awaits a result to mutate the items object.

Note that the menuContext is applied to the Menu's item event, so your onItem handler's single event parameter also contains the following properties:

Video guides

Full information of the menu customization can be found in the "Customizing the Event menu, the Schedule menu, and the TimeAxisHeader menu" guide.

This feature is enabled by default

Configs

18

Common

disabledInstancePlugin
listenersEvents

Other

processItems: function

A function called before displaying the menu that allows manipulations of its items. Returning false from this function prevents the menu being shown.

features         : {
   eventMenu : {
        processItems({ items, eventRecord, assignmentRecord, resourceRecord }) {
            // Add or hide existing items here as needed
            items.myAction = {
                text   : 'Cool action',
                icon   : 'fa fa-fw fa-ban',
                onItem : () => console.log(`Clicked ${eventRecord.name}`),
                weight : 1000 // Move to end
            };

           if (!eventRecord.allowDelete) {
                items.deleteEvent.hidden = true;
            }
        }
    }
},
ParameterTypeDescription
contextObject

An object with information about the menu being shown.

context.featureEventMenu

A reference to this feature.

context.domEventEvent

The initiating event.

context.eventEvent

DEPRECATED: The initiating event.

context.pointNumber[]

The client X and Y position of the initiating event.

context.targetElementHTMLElement

The target to which the menu is being applied.

context.eventRecordEventModel

The record representing the current event.

context.resourceRecordResourceModel

The record representing the current resource.

context.assignmentRecordAssignmentModel

The assignment record.

context.itemsObject<String, MenuItemEntry>

An object containing the menu item configs keyed by their id.

Returns: Boolean | null -

Returning false from this function prevents the menu being shown.

clickTriggerSelectorContextMenuBase
itemsContextMenuBase
keyMapContextMenuBase
menuContextMenuBase
namedItemsContextMenuBase
preventNativeMenuContextMenuBase
triggerEventContextMenuBase
typeContextMenuBase

Misc

clientInstancePlugin
localeClassLocalizable
localizableLocalizable

Properties

20

Common

disabledInstancePlugin

Class hierarchy

isEventMenu: Boolean= truereadonly
Identifies an object as an instance of EventMenu class, or subclass thereof.
isEventMenu: Boolean= truereadonlystatic
Identifies an object as an instance of EventMenu class, or subclass thereof.
isContextMenuBaseContextMenuBase
isEventsEvents
isInstancePluginInstancePlugin
isLocalizableLocalizable
isTimeSpanMenuBaseTimeSpanMenuBase

Other

An informational object containing contextual information about the last activation of the context menu.

menuContextMenuBase
preventNativeMenuContextMenuBase

Lifecycle

configBase

Misc

clientInstancePlugin
localeHelperLocalizable
localeManagerLocalizable

Functions

30

Other

Shows context menu for the provided event. If record is not rendered (outside of time span/filtered) menu won't appear.

ParameterTypeDescription
eventRecordEventModel

Event record to show menu for.

optionsObject
options.targetElementHTMLElement

Element to align context menu to. If provided menu will be aligned according to clientX/clientY coordinates. If omitted, context menu will be centered to event element.

LstaticLocalizable
onEvents
relayAllEvents
showContextMenuContextMenuBase
triggerEvents
unEvents

Configuration

applyDefaultsstaticBase

Events

Lifecycle

destroystaticBase

Misc

doDisableInstancePlugin
initClassstaticBase
isOfTypeNamestaticBase
mixinstaticBase
optionalLstaticLocalizable

Events

10

This event fires on the owning Scheduler before the context menu is shown for an event. Allows manipulation of the items to show in the same way as in processItems. Returning false from a listener prevents the menu from being shown.

// Adding a listener using the "on" method
eventMenu.on('eventMenuBeforeShow', ({ source, items, eventRecord, resourceRecord, assignmentRecord, eventElement, event }) => {

});
ParameterTypeDescription
sourceScheduler
itemsObject<String, MenuItemEntry>

Menu item configs

eventRecordEventModel

Event record for which the menu was triggered

resourceRecordResourceModel

Resource record

assignmentRecordAssignmentModel

Assignment record, if assignments are used

eventElementHTMLElement
eventMouseEvent

Pointer event which triggered the context menu (if any)

This event fires on the owning Scheduler when an item is selected in the context menu.

// Adding a listener using the "on" method
eventMenu.on('eventMenuItem', ({ source, item, eventRecord, resourceRecord, assignmentRecord, eventElement }) => {

});
ParameterTypeDescription
sourceScheduler
itemMenuItem
eventRecordEventModel
resourceRecordResourceModel
assignmentRecordAssignmentModel

Assignment record, if assignments are used

eventElementHTMLElement

This event fires on the owning Scheduler after showing the context menu for an event

// Adding a listener using the "on" method
eventMenu.on('eventMenuShow', ({ source, menu, eventRecord, resourceRecord, assignmentRecord, eventElement }) => {

});
ParameterTypeDescription
sourceScheduler
menuMenu

The menu

eventRecordEventModel

Event record for which the menu was triggered

resourceRecordResourceModel

Resource record

assignmentRecordAssignmentModel

Assignment record, if assignments are used

eventElementHTMLElement
catchAllEvents
contextMenuItemContextMenuBase
contextMenuToggleItemContextMenuBase
destroyEvents
disableInstancePlugin
enableInstancePlugin

Event handlers

10

This event called on the owning Scheduler before the context menu is shown for an event. Allows manipulation of the items to show in the same way as in processItems. Returning false from a listener prevents the menu from being shown.

new EventMenu({
    onEventMenuBeforeShow({ source, items, eventRecord, resourceRecord, assignmentRecord, eventElement, event }) {

    }
});
ParameterTypeDescription
sourceScheduler
itemsObject<String, MenuItemEntry>

Menu item configs

eventRecordEventModel

Event record for which the menu was triggered

resourceRecordResourceModel

Resource record

assignmentRecordAssignmentModel

Assignment record, if assignments are used

eventElementHTMLElement
eventMouseEvent

Pointer event which triggered the context menu (if any)

This event called on the owning Scheduler when an item is selected in the context menu.

new EventMenu({
    onEventMenuItem({ source, item, eventRecord, resourceRecord, assignmentRecord, eventElement }) {

    }
});
ParameterTypeDescription
sourceScheduler
itemMenuItem
eventRecordEventModel
resourceRecordResourceModel
assignmentRecordAssignmentModel

Assignment record, if assignments are used

eventElementHTMLElement

This event called on the owning Scheduler after showing the context menu for an event

new EventMenu({
    onEventMenuShow({ source, menu, eventRecord, resourceRecord, assignmentRecord, eventElement }) {

    }
});
ParameterTypeDescription
sourceScheduler
menuMenu

The menu

eventRecordEventModel

Event record for which the menu was triggered

resourceRecordResourceModel

Resource record

assignmentRecordAssignmentModel

Assignment record, if assignments are used

eventElementHTMLElement
onContextMenuItemContextMenuBase
onDestroyEvents
onDisableInstancePlugin
onEnableInstancePlugin

Typedefs

4

A context object passed to any processItems method defined for a context menu feature, and the basis of events fired by context menu features.

ParameterTypeDescription
eventRecordEventModel

The event record clicked on.

resourceRecordResourceModel

The resource record clicked on.

assignmentRecordAssignmentModel

The assignment record clicked on.

MenuContextContextMenuBase
MenuItemEntryContextMenuBase