Copy and Paste WebScheduler’s Event in Day and Week View
In scheduling scenarios, it’s quite common if user wants to copy and paste an event to a certain date. We don’t have this feature as a built-in feature yet (maybe soon ^^) in WebScheduler.NET, but you can manually implement it using our extensible API.
First of all, you need to add Copy Event and Paste Event menu items in context menu. They can be easily added in OnContextMenu client side event. The Copy Event menu item should be added in event’s context menu, while Paste Event menu item should be added in the cell area.
Next, you need to implement the copy and paste action. When you create the menu items, you can specify a function that will be invoked when the menu items are clicked. In that function, you can implement the needed code for copy and paste action. To retrieve the scheduler object in this function, you can simply use
ISGetObject([scheduler id])
or use menuItem.OwnerMenu.MenuControl.Scheduler
.
When user selects Copy Event menu item, the selected event can be stored to a global variable that can be used when user selects Paste Event menu item.Â
1 2 3 |
var evt = s.GetSelectedEvent(); if (evt != null) copiedEvent = evt; |
When user selects Paste Event menu item, you can retrieve the copied event from the stored global variable and create a new event programmatically.
1 2 3 4 5 6 7 8 9 10 11 |
var newEvent = s.CreateNewEvent(); var newOriginalObject = newEvent.GetOriginalObject(); newEvent.StartTime = newOriginalObject.StartTime = selDate; newEvent.EndTime = newOriginalObject.EndTime = endTime; //call the function that copy the original object from the copied event to the new original object CopyOriginalObject(originalObject, newOriginalObject); s.InitializeEventView(newEvent); s.InsertEvent(newOriginalObject); |
The new event will be created in the selected cell area. That means the datetime of the selected cell area will be used as the new event’s start time. To get the date time of the selected cell area, you can use s.GetDateTimeByCellElement(s.GetSelectedDateArea(), "DateTime")
method.
To calculate the end time of the new event, the start time must be added with the event’s duration. In time-based event, the event.Duration
property already stores the duration value in miliseconds. However, in all-day event, the event.Duration
property stores the duration value in days. In this case, the duration of all-day event must be converted to miliseconds.
Finally now, not only you can copy and paste event in the same view, you can also copy event during navigation.
In the following screenshot, the event is pasted in the next week. The original event that is copied starts at March 3rd 2008; and the event is pasted to March 10th 2008.
The event can also be copied to other view. For example: user can copy “Review documentation” event in Week view, navigates to Day view and paste the event.
I’ve provided a sample that can be downloaded here. In the sample, you can copy switch-event too. Switch event is actually a time-based event that occurs in multiple days and is displayed in all-day-event area. Additional code is needed to support copy and paste switch event.Â
Note that time based event can only be pasted as time-based event and so are the other event types, so if, for example, an all-day event is pasted to a time-based cell area, the new event will not be added properly.
If you wish to implement copy and paste event in other views, you need to properly convert the duration of event to miliseconds. I plan to describe more about this in the future, so stay tune ! ^^
Just passing by.Btw, your website have great content!
_________________________________
Making Money $150 An Hour
Thanks for dropping by Mike.