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.
//<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.
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. |
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'
}
}
});
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
Configs
21Other
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'
]
}
}
});
The field to use as the name field when updating the name of copied records
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.
Misc
Properties
18
Properties
18Common
Class hierarchy
Functions
31
Functions
31Common
Edit
Copy events (when using single assignment mode) or assignments (when using multi assignment mode) to clipboard to paste later
| Parameter | Type | Description |
|---|---|---|
records | EventModel[] | AssignmentModel[] | Pass records to copy them, leave out to copying current selection |
isCut | Boolean | Copies by default, pass |
Paste events or assignments to specified date and resource
| Parameter | Type | Description |
|---|---|---|
date | Date | Date where the events or assignments will be pasted |
resourceRecord | ResourceModel | Resource to assign the pasted events or assignments to |
Configuration
Events
Misc
Other
Events
10
Events
10Fires 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 }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Scheduler | Owner scheduler |
eventRecords | EventModel[] | The event records about to be copied |
assignmentRecords | AssignmentModel[] | The assignment records about to be copied |
isCut | Boolean |
|
entityName | String | '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 }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Scheduler | Owner scheduler |
eventRecords | EventModel[] | The events about to be pasted |
assignmentRecords | AssignmentModel[] | The assignments about to be pasted |
originalEventRecords | EventModel[] | The original event records |
originalAssignmentRecords | AssignmentModel[] | The original assignment record |
date | Date | The date when the pasted events will be scheduled |
resourceRecord | ResourceModel | The target resource record, the clipboard event records will be assigned to this resource. |
isCut | Boolean |
|
entityName | String | '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 }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Scheduler | Owner scheduler |
eventRecords | EventModel[] | The event record copies |
assignmentRecords | AssignmentModel[] | The assignment record copies |
originalEventRecords | EventModel[] | The event records that were copied |
originalAssignmentRecord | AssignmentModel[] | The assignment records that were copied |
isCut | Boolean |
|
entityName | String | '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 }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Scheduler | Owner scheduler |
eventRecords | EventModel[] | The pasted event records |
assignmentRecords | AssignmentModel[] | The pasted assignment records |
pastedEventRecords | EventModel[] | (DEPRECATED) Use eventRecords instead |
originalEventRecords | EventModel[] | The original copied event records |
originalAssignmentRecords | AssignmentModel[] | The original copied assignment records |
date | Date | date Pasted to this date |
resourceRecord | ResourceModel | The target resource record |
isCut | Boolean |
|
entityName | String | '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 }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Scheduler | Owner scheduler |
eventRecords | EventModel[] | The event records about to be pasted |
assignmentRecords | AssignmentModel[] | The assignment records about to be pasted |
originalEventRecords | EventModel[] | The event records that were copied |
originalAssignmentRecords | AssignmentModel[] | The assignment records that were copied |
date | Date | The paste date |
resourceRecord | ResourceModel | The target resource record |
isCut | Boolean |
|
entityName | String | 'event' to distinguish this event from other |
reason | overlappingEvents | resourceReadOnly | A string id to use for displaying an error message to the user. |
Event handlers
10
Event handlers
10Called on the owning Scheduler before a copy action is performed, return false to prevent the action
new EventCopyPaste({
onBeforeCopy({ source, eventRecords, assignmentRecords, isCut, entityName }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Scheduler | Owner scheduler |
eventRecords | EventModel[] | The event records about to be copied |
assignmentRecords | AssignmentModel[] | The assignment records about to be copied |
isCut | Boolean |
|
entityName | String | '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 }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Scheduler | Owner scheduler |
eventRecords | EventModel[] | The events about to be pasted |
assignmentRecords | AssignmentModel[] | The assignments about to be pasted |
originalEventRecords | EventModel[] | The original event records |
originalAssignmentRecords | AssignmentModel[] | The original assignment record |
date | Date | The date when the pasted events will be scheduled |
resourceRecord | ResourceModel | The target resource record, the clipboard event records will be assigned to this resource. |
isCut | Boolean |
|
entityName | String | '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 }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Scheduler | Owner scheduler |
eventRecords | EventModel[] | The event record copies |
assignmentRecords | AssignmentModel[] | The assignment record copies |
originalEventRecords | EventModel[] | The event records that were copied |
originalAssignmentRecord | AssignmentModel[] | The assignment records that were copied |
isCut | Boolean |
|
entityName | String | '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 }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Scheduler | Owner scheduler |
eventRecords | EventModel[] | The pasted event records |
assignmentRecords | AssignmentModel[] | The pasted assignment records |
pastedEventRecords | EventModel[] | (DEPRECATED) Use eventRecords instead |
originalEventRecords | EventModel[] | The original copied event records |
originalAssignmentRecords | AssignmentModel[] | The original copied assignment records |
date | Date | date Pasted to this date |
resourceRecord | ResourceModel | The target resource record |
isCut | Boolean |
|
entityName | String | '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 }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Scheduler | Owner scheduler |
eventRecords | EventModel[] | The event records about to be pasted |
assignmentRecords | AssignmentModel[] | The assignment records about to be pasted |
originalEventRecords | EventModel[] | The event records that were copied |
originalAssignmentRecords | AssignmentModel[] | The assignment records that were copied |
date | Date | The paste date |
resourceRecord | ResourceModel | The target resource record |
isCut | Boolean |
|
entityName | String | 'event' to distinguish this event from other |
reason | overlappingEvents | resourceReadOnly | A string id to use for displaying an error message to the user. |