PDA

View Full Version : [CLOSED] How to copy an event using Ext.Net CalendarPanel ?



Arohan
Apr 20, 2014, 12:34 PM
Hi,

I am using CalendarPanel for time booking application. In this I need to copy existing Event to a new date (as is) and then resize the event. Is there any event to achieve this ?

Thanks
PRASAD

Vladimir
Apr 21, 2014, 8:30 AM
You have to create new record in EventStore with required data
The code can be look like this


var rec = App.EventStore1.getAt(0).copy();
rec.set("StartDate", new Date(....));
rec.set("EndDate", new Date(....));
App.EventStore1.add(rec);

Arohan
Apr 22, 2014, 7:54 AM
Thanks for your code.

From where should I give a call to this code as I could not find relevant event in CalendarPanel Listners. Please suggest.

geoffrey.mcgill
Apr 22, 2014, 8:08 AM
Thanks for your code.

From where should I give a call to this code as I could not find relevant event in CalendarPanel Listners. Please suggest.

You can execute this code from any Listener. You mentioned you need to 'copy' the record... what will trigger the copy?

Arohan
Apr 22, 2014, 9:45 AM
Any of the following method will do


CTRL-Drag-Drop (as drag drop is already used by EventMove)
CTRL-C+CTRL-V


Or is there any ready event for EventCopy (as CalandarPanel already have EventMove, EventResize, EventAdd, EventUpdate etc)

Vladimir
Apr 22, 2014, 12:20 PM
You can use the following override to copy event during drag drop operation if ctrl key is pressed


Ext.calendar.view.AbstractCalendar.override({
onEventDrop: function (rec, dt) {
var copy = Ext.EventObject.ctrlKey,
store = this.store;


if (Ext.calendar.util.Date.compare(rec.data[Ext.calendar.data.EventMappings.StartDate.name], dt) === 0 && !copy) {
// no changes
return;
}
if (copy) {
rec = rec.copy();
}


var diff = dt.getTime() - rec.data[Ext.calendar.data.EventMappings.StartDate.name].getTime();
rec.set(Ext.calendar.data.EventMappings.StartDate. name, dt);
rec.set(Ext.calendar.data.EventMappings.EndDate.na me, Ext.calendar.util.Date.add(rec.data[Ext.calendar.data.EventMappings.EndDate.name], { millis: diff }));


if (copy) {
store.add(rec);
this.up('calendarpanel').fireEvent('eventadd', this, rec);
}
else {
this.fireEvent('eventmove', this, rec);
}
}
});

Arohan
Apr 22, 2014, 3:14 PM
Thanks a lot Vladimir. Its working perfect. Please mark this thread as Closed