EventCopyPaste
Feature
Allow using Ctrl/Cmd+C, Ctrl/Cmd+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.
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.
Useful configs and functions
| Member | Description |
|---|---|
| beforeCopy | Fires before copy, return false to prevent |
| copy | Fires when events are copied |
| beforePaste | Fires before paste, return false to prevent |
| paste | Fires when events are pasted |
See also
- EventModel - Event data model
- EventEdit - Event editor
Configs
Configs are options you supply in a configuration object when creating an instance of this class-
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
falseto paste into the same resource and same date. -
Configure which sources $name this class allows pasting model data from. Accepts string or array. Unspecified accepts all. If source is not accepted, it will try to use the string value instead.
-
Set this to
trueto use native Clipboard API if it is available -
If
truethis prevents cutting and pasting. Will default totrueif CellEdit feature is disabled. Set tofalseto prevent this behaviour. -
The format a copied date value should have when converted to a string. To learn more about available formats, check out DateHelper docs.
-
Default keyMap configuration: Ctrl/Cmd+c to copy, Ctrl/Cmd+x to cut and Ctrl/Cmd+v to paste. These keyboard shortcuts require a selection to be made.
-
Internal listeners, that cannot be removed by the user.
-
The widget which this plugin is to attach to.
Has a corresponding runtime client property.
-
Set to
falseto disable localization of this object.
Properties
Properties are getters/setters or publicly accessible variables on this class-
Identifies an object as an instance of Clipboardable class, or subclass thereof.
-
Identifies an object as an instance of EventCopyPaste class, or subclass thereof.
-
Identifies an object as an instance of Events class, or subclass thereof.
-
Identifies an object as an instance of Localizable class, or subclass thereof.
-
A class property getter for the default values of internal properties for this class.
-
An empty array that can be used as a default value.
-
An empty object that can be used as a default value.
-
Identifies an object as an instance of CopyPasteBase class, or subclass thereof.
-
Identifies an object as an instance of EventCopyPaste class, or subclass thereof.
-
Identifies an object as an instance of InstancePlugin class, or subclass thereof.
-
Gets the current shared Clipboard instance
-
A method used to generate the name for a copy-pasted record. By defaults appends "- 2", "- 3" as a suffix. Override it to provide your own naming of pasted records.
Has a corresponding generateNewName config.
-
Returns a copy of the full configuration which was used to configure this object.
-
This property is set to
truebefore theconstructorreturns. -
This property is set to
trueon entry to the destroy method. It remains on the objects after returning fromdestroy(). If isDestroyed istrue, this property will also betrue, so there is no need to test for both (for example,comp.isDestroying || comp.isDestroyed). -
The Widget which was passed into the constructor, which is the Widget we are providing extra services for.
Has a corresponding client config.
-
Get the global LocaleHelper
-
Get the global LocaleManager
Functions
Functions are methods available for calling on the class-
This optional class method is called when a class is mixed in using the mixin() method.
-
Registers this class type with its Factory
-
Clears the clipboard data
-
Internal function used to hook destroy() calls when using thisObj
-
Internal function used restore hooked destroy() calls when using thisObj
-
Auto detaches listeners registered from start, if set as detachable
-
Internal function used to run a callback function after an event is triggered
-
Removes all listeners registered to this object by the application.
-
This will merge a feature's (subclass of InstancePlugin) keyMap with it's client's keyMap.