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.

Copy Event menu item

Copy Event menu item

Paste Event menu item

Paste Event menu item

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.

When user selects Paste Event menu item, you can retrieve the copied event from the stored global variable and create a new event programmatically.

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.

After Paste Event

Event Copied

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.

Copied event during navigation

Copied event during navigation

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.

Copied event in Day view

Copied event in Day view

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 ! ^^

Comments

Leave a Reply