EventCopyPaste

Allow using Ctrl/CMD + C/X and Ctrl/CMD + V to copy/cut and paste events.

This feature also adds entries to the EventMenu for copying & cutting (see example below for how to configure) and to the ScheduleMenu for pasting.

You can configure how a newly pasted record is named using generateNewName.

Event copy paste
//<code-header>
fiddle.title = 'Event copy paste';
//</code-header>
targetElement.innerHTML = '<p>Copy/cut and paste events using keyboard shortcuts or context menu:</p>';

const scheduler = new Scheduler({
    appendTo : targetElement,

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

    startDate : new Date(2021, 1, 6),
    endDate   : new Date(2021, 1, 20),

    viewPreset : 'dayAndWeek',

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

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

    events : [
        { id : 1, resourceId : 1, name : 'Interview', startDate : '2021-02-06', endDate : '2021-02-07' },
        { id : 2, resourceId : 1, name : 'Press meeting', startDate : '2021-02-08', endDate : '2021-02-09' },
        { id : 3, resourceId : 2, name : 'Audition', startDate : '2021-02-07', endDate : '2021-02-09' },
        { id : 4, resourceId : 2, name : 'Script deadline', startDate : '2021-02-11', endDate : '2021-02-11' }
    ]
});

If you want to highlight the paste location when clicking in the schedule, consider enabling the ScheduleContext feature.

When used with Scheduler Pro, pasting will bypass any constraint set on the event to allow the copy to be assigned the targeted date.

This feature is enabled by default.

Customize menu items

See EventMenu and ScheduleMenu for more info on customizing the menu items supplied by the feature. This snippet illustrates the concept:

// Custom copy text + remove cut option from event menu:
const scheduler = new Scheduler({
    features : {
        eventMenu : {
            items : {
                copyEvent : {
                    text : 'Copy booking'
                },
                cutEvent  : false
            }
        }
    }
});

Keyboard shortcuts

The feature has the following default keyboard shortcuts:

Keys Action Action description
Ctrl+C copy Copies selected event(s) into the clipboard.
Ctrl+X cut Cuts out selected event(s) into the clipboard.
Ctrl+V paste Insert copied or cut event(s) from the clipboard.

Please note that Ctrl is the equivalent to Command and Alt is the equivalent to Option for Mac users

For more information on how to customize keyboard shortcuts, please see our guide.

Multi assigned events

In a Scheduler that uses single assignment, copying and then pasting creates a clone of the event and assigns it to the target resource. Cutting and pasting moves the original event to the target resource.

In a Scheduler using multi assignment, the behaviour is slightly more complex. Cutting and pasting reassigns the event to the target, keeping other assignments of the same event intact. The behaviour for copying and pasting is configurable using the copyPasteAction config. It accepts two values:

  • 'clone' - The default, the event is cloned and the clone is assigned to the target resource. Very similar to the behaviour with single assignment (event count goes up by 1).
  • 'assign' - The original event is assigned to the target resource (event count is unaffected).

This snippet shows how to reconfigure it:

const scheduler = new Scheduler({
    features : {
        eventCopyPaste : {
            copyPasteAction : 'assign'
        }
    }
});
Copying multiple assignments of the same event will always result in all but the first assignment being removed on paste, since paste targets a single resource and an event can only be assigned to a resource once.

Native/shared clipboard

If you have multiple Schedulers (or other Bryntum products) on the same page, they will share clipboard. This makes it possible to copy and paste between different Scheduler instances. It is also possible to use the native Clipboard API if it is available and if you set useNativeClipboard to true.

Regardless of native clipboard availability, copy-pasting "outside" of the current Scheduler instance will convert the copied events to a string. When pasting, the string will then be parsed back into events. In case of usage of the native Clipboard API, this means it is possible to copy and paste events between completely different applications.

To configure the fields that is converted and parsed from the copied string value, please see the eventToStringFields config.

Configs

21

Common

disabledInstancePlugin
listenersEvents

Other

copyPasteAction: clone | assign= clone

How to handle a copy paste operation when the host uses multi assignment. Either:

  • 'clone' - The default, clone the copied event, assigning the clone to the target resource.
  • 'assign' - Add an assignment for the existing event to the target resource.

For single assignment mode, it always uses the 'clone' behaviour.

When copying events (or assignments), data will be sent to the clipboard as a tab (\t) and new-line (\n) separated string with field values for fields present in this config (in specified order). The default included fields are (in this order):

  • name
  • startDate
  • endDate
  • duration
  • durationUnit
  • allDay To override, provide your own array of fields:
new Scheduler({
    features : {
        eventCopyPaste : {
            eventToStringFields : [
               'name',
               'startDate',
               'endDate',
               'percentDone'
            ]
        }
    }
});
Please note that this config is both used for **converting** events to a string value and is also used to **parse** a string value to events.
nameField: String= name

The field to use as the name field when updating the name of copied records

unifiedPaste: Boolean= true

By default, pasting of multiple events will spread out according to the pattern it was copied. Set to false to paste into the same resource and same date.

copyOnlyCopyPasteBase
dateFormatCopyPasteBase
emptyValueCharCopyPasteBase
generateNewNameCopyPasteBase
keyMapCopyPasteBase
toCopyStringCopyPasteBase
toPasteValueCopyPasteBase
useNativeClipboardCopyPasteBase

Misc

clientInstancePlugin
localeClassLocalizable
localizableLocalizable

Properties

18

Common

disabledInstancePlugin

Class hierarchy

isEventCopyPaste: Boolean= truereadonly
Identifies an object as an instance of EventCopyPaste class, or subclass thereof.
isEventCopyPaste: Boolean= truereadonlystatic
Identifies an object as an instance of EventCopyPaste class, or subclass thereof.
isClipboardableClipboardable
isCopyPasteBaseCopyPasteBase
isEventsEvents
isInstancePluginInstancePlugin
isLocalizableLocalizable

Lifecycle

configBase

Misc

clientInstancePlugin
localeHelperLocalizable
localeManagerLocalizable

Other

generateNewNameCopyPasteBase

Functions

31

Common

clearClipboardClipboardable

Edit

Copy events (when using single assignment mode) or assignments (when using multi assignment mode) to clipboard to paste later

ParameterTypeDescription
recordsEventModel[] | AssignmentModel[]

Pass records to copy them, leave out to copying current selection

isCutBoolean

Copies by default, pass true to cut instead

Paste events or assignments to specified date and resource

ParameterTypeDescription
dateDate

Date where the events or assignments will be pasted

resourceRecordResourceModel

Resource to assign the pasted events or assignments to

Configuration

applyDefaultsstaticBase

Events

Lifecycle

destroystaticBase

Misc

doDisableInstancePlugin
initClassstaticBase
isOfTypeNamestaticBase
mixinstaticBase
optionalLstaticLocalizable

Other

LstaticLocalizable
onEvents
relayAllEvents
triggerEvents
unEvents

Events

10

Fires on the owning Scheduler before a copy action is performed, return false to prevent the action

// Adding a listener using the "on" method
eventCopyPaste.on('beforeCopy', ({ source, eventRecords, assignmentRecords, isCut, entityName }) => {

});
ParameterTypeDescription
sourceScheduler

Owner scheduler

eventRecordsEventModel[]

The event records about to be copied

assignmentRecordsAssignmentModel[]

The assignment records about to be copied

isCutBoolean

true if this is a cut action

entityNameString

'event' to distinguish this event from other beforeCopy events

Fires on the owning Scheduler before a paste action is performed, return false to prevent the action. Depending on if the EventStore is using singleAssignment or the configuration of copyPasteAction, either the eventRecords or the assignmentRecords param will be populated with record copies.

// Adding a listener using the "on" method
eventCopyPaste.on('beforePaste', ({ source, eventRecords, assignmentRecords, originalEventRecords, originalAssignmentRecords, date, resourceRecord, isCut, entityName }) => {

});
ParameterTypeDescription
sourceScheduler

Owner scheduler

eventRecordsEventModel[]

The events about to be pasted

assignmentRecordsAssignmentModel[]

The assignments about to be pasted

originalEventRecordsEventModel[]

The original event records

originalAssignmentRecordsAssignmentModel[]

The original assignment record

dateDate

The date when the pasted events will be scheduled

resourceRecordResourceModel

The target resource record, the clipboard event records will be assigned to this resource.

isCutBoolean

true if this is a cut action

entityNameString

'event' to distinguish this event from other beforePaste events

Fires on the owning Scheduler after a copy action is performed. Depending on if the EventStore is using singleAssignment or the configuration of copyPasteAction, either the eventRecords or the assignmentRecords param will be populated with record copies.

// Adding a listener using the "on" method
eventCopyPaste.on('copy', ({ source, eventRecords, assignmentRecords, originalEventRecords, originalAssignmentRecord, isCut, entityName }) => {

});
ParameterTypeDescription
sourceScheduler

Owner scheduler

eventRecordsEventModel[]

The event record copies

assignmentRecordsAssignmentModel[]

The assignment record copies

originalEventRecordsEventModel[]

The event records that were copied

originalAssignmentRecordAssignmentModel[]

The assignment records that were copied

isCutBoolean

true if this is a cut action

entityNameString

'event' to distinguish this event from other copy events

Fires on the owning Scheduler after a paste action is performed.

// Adding a listener using the "on" method
eventCopyPaste.on('paste', ({ source, eventRecords, assignmentRecords, pastedEventRecords, originalEventRecords, originalAssignmentRecords, date, resourceRecord, isCut, entityName }) => {

});
ParameterTypeDescription
sourceScheduler

Owner scheduler

eventRecordsEventModel[]

The pasted event records

assignmentRecordsAssignmentModel[]

The pasted assignment records

pastedEventRecordsEventModel[]

(DEPRECATED) Use eventRecords instead

originalEventRecordsEventModel[]

The original copied event records

originalAssignmentRecordsAssignmentModel[]

The original copied assignment records

dateDate

date Pasted to this date

resourceRecordResourceModel

The target resource record

isCutBoolean

true if this is a cut action

entityNameString

'event' to distinguish this event from other paste events

Fires on the owning Scheduler if a paste action is not allowed. Depending on if the EventStore is using singleAssignment or the configuration of copyPasteAction, either the eventRecords or the assignmentRecords param will be populated with record copies.

// Adding a listener using the "on" method
eventCopyPaste.on('pasteNotAllowed', ({ source, eventRecords, assignmentRecords, originalEventRecords, originalAssignmentRecords, date, resourceRecord, isCut, entityName, reason }) => {

});
ParameterTypeDescription
sourceScheduler

Owner scheduler

eventRecordsEventModel[]

The event records about to be pasted

assignmentRecordsAssignmentModel[]

The assignment records about to be pasted

originalEventRecordsEventModel[]

The event records that were copied

originalAssignmentRecordsAssignmentModel[]

The assignment records that were copied

dateDate

The paste date

resourceRecordResourceModel

The target resource record

isCutBoolean

true if this is a cut action

entityNameString

'event' to distinguish this event from other pasteNotAllowed events

reasonoverlappingEvents | resourceReadOnly

A string id to use for displaying an error message to the user.

catchAllEvents
destroyEvents
disableInstancePlugin
enableInstancePlugin

Event handlers

10

Called on the owning Scheduler before a copy action is performed, return false to prevent the action

new EventCopyPaste({
    onBeforeCopy({ source, eventRecords, assignmentRecords, isCut, entityName }) {

    }
});
ParameterTypeDescription
sourceScheduler

Owner scheduler

eventRecordsEventModel[]

The event records about to be copied

assignmentRecordsAssignmentModel[]

The assignment records about to be copied

isCutBoolean

true if this is a cut action

entityNameString

'event' to distinguish this event from other beforeCopy events

Called on the owning Scheduler before a paste action is performed, return false to prevent the action. Depending on if the EventStore is using singleAssignment or the configuration of copyPasteAction, either the eventRecords or the assignmentRecords param will be populated with record copies.

new EventCopyPaste({
    onBeforePaste({ source, eventRecords, assignmentRecords, originalEventRecords, originalAssignmentRecords, date, resourceRecord, isCut, entityName }) {

    }
});
ParameterTypeDescription
sourceScheduler

Owner scheduler

eventRecordsEventModel[]

The events about to be pasted

assignmentRecordsAssignmentModel[]

The assignments about to be pasted

originalEventRecordsEventModel[]

The original event records

originalAssignmentRecordsAssignmentModel[]

The original assignment record

dateDate

The date when the pasted events will be scheduled

resourceRecordResourceModel

The target resource record, the clipboard event records will be assigned to this resource.

isCutBoolean

true if this is a cut action

entityNameString

'event' to distinguish this event from other beforePaste events

Called on the owning Scheduler after a copy action is performed. Depending on if the EventStore is using singleAssignment or the configuration of copyPasteAction, either the eventRecords or the assignmentRecords param will be populated with record copies.

new EventCopyPaste({
    onCopy({ source, eventRecords, assignmentRecords, originalEventRecords, originalAssignmentRecord, isCut, entityName }) {

    }
});
ParameterTypeDescription
sourceScheduler

Owner scheduler

eventRecordsEventModel[]

The event record copies

assignmentRecordsAssignmentModel[]

The assignment record copies

originalEventRecordsEventModel[]

The event records that were copied

originalAssignmentRecordAssignmentModel[]

The assignment records that were copied

isCutBoolean

true if this is a cut action

entityNameString

'event' to distinguish this event from other copy events

Called on the owning Scheduler after a paste action is performed.

new EventCopyPaste({
    onPaste({ source, eventRecords, assignmentRecords, pastedEventRecords, originalEventRecords, originalAssignmentRecords, date, resourceRecord, isCut, entityName }) {

    }
});
ParameterTypeDescription
sourceScheduler

Owner scheduler

eventRecordsEventModel[]

The pasted event records

assignmentRecordsAssignmentModel[]

The pasted assignment records

pastedEventRecordsEventModel[]

(DEPRECATED) Use eventRecords instead

originalEventRecordsEventModel[]

The original copied event records

originalAssignmentRecordsAssignmentModel[]

The original copied assignment records

dateDate

date Pasted to this date

resourceRecordResourceModel

The target resource record

isCutBoolean

true if this is a cut action

entityNameString

'event' to distinguish this event from other paste events

Called on the owning Scheduler if a paste action is not allowed. Depending on if the EventStore is using singleAssignment or the configuration of copyPasteAction, either the eventRecords or the assignmentRecords param will be populated with record copies.

new EventCopyPaste({
    onPasteNotAllowed({ source, eventRecords, assignmentRecords, originalEventRecords, originalAssignmentRecords, date, resourceRecord, isCut, entityName, reason }) {

    }
});
ParameterTypeDescription
sourceScheduler

Owner scheduler

eventRecordsEventModel[]

The event records about to be pasted

assignmentRecordsAssignmentModel[]

The assignment records about to be pasted

originalEventRecordsEventModel[]

The event records that were copied

originalAssignmentRecordsAssignmentModel[]

The assignment records that were copied

dateDate

The paste date

resourceRecordResourceModel

The target resource record

isCutBoolean

true if this is a cut action

entityNameString

'event' to distinguish this event from other pasteNotAllowed events

reasonoverlappingEvents | resourceReadOnly

A string id to use for displaying an error message to the user.

onDestroyEvents
onDisableInstancePlugin
onEnableInstancePlugin

Typedefs

1